59 char buf[CX_PRINTF_SBO_SIZE]; |
59 char buf[CX_PRINTF_SBO_SIZE]; |
60 va_list ap2; |
60 va_list ap2; |
61 va_copy(ap2, ap); |
61 va_copy(ap2, ap); |
62 int ret = vsnprintf(buf, CX_PRINTF_SBO_SIZE, fmt, ap); |
62 int ret = vsnprintf(buf, CX_PRINTF_SBO_SIZE, fmt, ap); |
63 if (ret < 0) { |
63 if (ret < 0) { |
|
64 va_end(ap2); |
64 return ret; |
65 return ret; |
65 } else if (ret < CX_PRINTF_SBO_SIZE) { |
66 } else if (ret < CX_PRINTF_SBO_SIZE) { |
|
67 va_end(ap2); |
66 return (int) wfc(buf, 1, ret, stream); |
68 return (int) wfc(buf, 1, ret, stream); |
67 } else { |
69 } else { |
68 int len = ret + 1; |
70 int len = ret + 1; |
69 char *newbuf = malloc(len); |
71 char *newbuf = malloc(len); |
70 if (!newbuf) { |
72 if (!newbuf) { |
|
73 va_end(ap2); |
71 return -1; |
74 return -1; |
72 } |
75 } |
73 |
76 |
74 ret = vsnprintf(newbuf, len, fmt, ap2); |
77 ret = vsnprintf(newbuf, len, fmt, ap2); |
|
78 va_end(ap2); |
75 if (ret > 0) { |
79 if (ret > 0) { |
76 ret = (int) wfc(newbuf, 1, ret, stream); |
80 ret = (int) wfc(newbuf, 1, ret, stream); |
77 } |
81 } |
78 free(newbuf); |
82 free(newbuf); |
79 } |
83 } |