a958d4bc0b7dbfe772479404ba19a613d72ac3de
[lttv.git] / ltt-usertrace / ltt / ltt-facility-custom-user_generic.h
1 #ifndef _LTT_FACILITY_CUSTOM_USER_GENERIC_H_
2 #define _LTT_FACILITY_CUSTOM_USER_GENERIC_H_
3
4 #include <sys/types.h>
5 #include <ltt/ltt-facility-id-user_generic.h>
6 #include <ltt/ltt-usertrace.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <stdarg.h>
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 static int trace_user_generic_slow_printf(
16 const char *fmt, ...)
17 #ifndef LTT_TRACE
18 {
19 }
20 #else
21 {
22 /* Guess we need no more than 100 bytes. */
23 int n, size = 100;
24 char *p, *np;
25 va_list ap;
26 int ret;
27
28 if ((p = malloc (size)) == NULL)
29 return -1;
30
31 while (1) {
32 /* Try to print in the allocated space. */
33 va_start(ap, fmt);
34 n = vsnprintf (p, size, fmt, ap);
35 va_end(ap);
36 /* If that worked, trace the string. */
37 if (n > -1 && n < size) {
38 ret = trace_user_generic_slow_printf_param_buffer(p, n+1);
39 free(p);
40 return ret;
41 }
42 /* Else try again with more space. */
43 if (n > -1) /* glibc 2.1 */
44 size = n+1; /* precisely what is needed */
45 else /* glibc 2.0 */
46 size *= 2; /* twice the old size */
47 if ((np = realloc (p, size)) == NULL) {
48 free(p);
49 return -1;
50 } else {
51 p = np;
52 }
53 }
54 }
55 #endif //LTT_TRACE
56
57 #ifdef __cplusplus
58 } /* end of extern "C" */
59 #endif
60
61 #endif //_LTT_FACILITY_CUSTOM_USER_GENERIC_H_
This page took 0.036096 seconds and 3 git commands to generate.