OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 //----------------------debug_helper:end---------------------// | |
6 #include <memory.h> | |
7 #include <signal.h> | |
8 #include <sys/types.h> | |
9 #include <unistd.h> | |
10 namespace debug_helper { | |
11 const int kOutputDebugStringSignal = SIGUSR1; | |
12 const int kOutputDebugStringSize = 4 * 1024; | |
13 void OutputDebugString_sigaction(int signo, siginfo_t* sig_inf, void* data) {} | |
14 bool OutputDebugString_Init() { | |
15 struct sigaction act; | |
16 memset(&act, 0, sizeof(act)); | |
17 act.sa_flags = SA_SIGINFO; | |
18 act.sa_sigaction = OutputDebugString_sigaction; | |
19 int res = sigaction(kOutputDebugStringSignal, &act, NULL); | |
20 return (0 == res); | |
21 } | |
22 bool OutputDebugString(const char* str) { | |
23 static char static_buff[kOutputDebugStringSize + 1]; | |
24 size_t num = strlen(str) + 1; | |
25 if (num > sizeof(static_buff)) | |
26 num = sizeof(static_buff); | |
27 memcpy(static_buff, str, num); | |
28 static_buff[num] = 0; | |
29 sigval val; | |
30 val.sival_ptr = static_buff; | |
31 return (0 == sigqueue(getpid(), kOutputDebugStringSignal, val)); | |
32 } | |
33 } // namesdpace debug_helper | |
34 //----------------------debug_helper:end---------------------// | |
35 | |
OLD | NEW |