| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 #ifndef PACKAGES_LIBRARIES_NACL_MOUNTS_UTIL_DEBUGPRINT_H_ | 6 #ifndef PACKAGES_LIBRARIES_NACL_MOUNTS_UTIL_DEBUGPRINT_H_ |
| 7 #define PACKAGES_LIBRARIES_NACL_MOUNTS_UTIL_DEBUGPRINT_H_ | 7 #define PACKAGES_LIBRARIES_NACL_MOUNTS_UTIL_DEBUGPRINT_H_ |
| 8 | 8 |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <stdarg.h> | 10 #include <stdarg.h> |
| 11 #include <sys/types.h> | 11 #include <sys/types.h> |
| 12 | 12 |
| 13 #ifdef __cplusplus |
| 13 extern "C" { | 14 extern "C" { |
| 15 #endif |
| 14 ssize_t __real_write(int fd, const void *buf, size_t count); | 16 ssize_t __real_write(int fd, const void *buf, size_t count); |
| 17 #ifdef __cplusplus |
| 15 } | 18 } |
| 19 #endif |
| 16 | 20 |
| 17 static int dbgprintf(const char* format, ...) { | 21 static int dbgprintf(const char* format, ...) { |
| 18 const int buf_size = 1000; | 22 const int buf_size = 1000; |
| 19 char buf[buf_size]; | 23 char buf[buf_size]; |
| 20 va_list args; | 24 va_list args; |
| 21 va_start(args, format); | 25 va_start(args, format); |
| 22 ssize_t r = vsnprintf(buf, buf_size, format, args); | 26 ssize_t r = vsnprintf(buf, buf_size, format, args); |
| 23 if (r > 0) | 27 if (r > 0) |
| 24 __real_write(2, buf, r); | 28 __real_write(2, buf, r); |
| 25 va_end(args); | 29 va_end(args); |
| 26 return r; | 30 return r; |
| 27 } | 31 } |
| 28 | 32 |
| 29 #endif // PACKAGES_LIBRARIES_NACL_MOUNTS_UTIL_DEBUGPRINT_H_ | 33 #endif // PACKAGES_LIBRARIES_NACL_MOUNTS_UTIL_DEBUGPRINT_H_ |
| OLD | NEW |