src/printf.c

changeset 644
fcaa0891ef28
parent 643
5700ba9154ab
child 693
494d9b20b99e
equal deleted inserted replaced
643:5700ba9154ab 644:fcaa0891ef28
47 ret = cx_vfprintf(stream, wfc, fmt, ap); 47 ret = cx_vfprintf(stream, wfc, fmt, ap);
48 va_end(ap); 48 va_end(ap);
49 return ret; 49 return ret;
50 } 50 }
51 51
52 int cx_vfprintf(void *stream, cx_write_func wfc, char const *fmt, va_list ap) { 52 int cx_vfprintf(
53 void *stream,
54 cx_write_func wfc,
55 char const *fmt,
56 va_list ap
57 ) {
53 char buf[CX_PRINTF_SBO_SIZE]; 58 char buf[CX_PRINTF_SBO_SIZE];
54 va_list ap2; 59 va_list ap2;
55 va_copy(ap2, ap); 60 va_copy(ap2, ap);
56 int ret = vsnprintf(buf, CX_PRINTF_SBO_SIZE, fmt, ap); 61 int ret = vsnprintf(buf, CX_PRINTF_SBO_SIZE, fmt, ap);
57 if (ret < 0) { 62 if (ret < 0) {
72 free(newbuf); 77 free(newbuf);
73 } 78 }
74 return ret; 79 return ret;
75 } 80 }
76 81
77 cxmutstr cx_asprintf_a(CxAllocator *allocator, char const *fmt, ...) { 82 cxmutstr cx_asprintf_a(
83 CxAllocator *allocator,
84 char const *fmt,
85 ...
86 ) {
78 va_list ap; 87 va_list ap;
79 cxmutstr ret; 88 cxmutstr ret;
80 va_start(ap, fmt); 89 va_start(ap, fmt);
81 ret = cx_vasprintf_a(allocator, fmt, ap); 90 ret = cx_vasprintf_a(allocator, fmt, ap);
82 va_end(ap); 91 va_end(ap);
83 return ret; 92 return ret;
84 } 93 }
85 94
86 cxmutstr cx_vasprintf_a(CxAllocator *a, char const *fmt, va_list ap) { 95 cxmutstr cx_vasprintf_a(
96 CxAllocator *a,
97 char const *fmt,
98 va_list ap
99 ) {
87 cxmutstr s; 100 cxmutstr s;
88 s.ptr = NULL; 101 s.ptr = NULL;
89 s.length = 0; 102 s.length = 0;
90 char buf[CX_PRINTF_SBO_SIZE]; 103 char buf[CX_PRINTF_SBO_SIZE];
91 va_list ap2; 104 va_list ap2;

mercurial