Lines Matching refs:xstr
22 IWXSTR *xstr = malloc(sizeof(*xstr)); in iwxstr_new2() local
23 if (!xstr) return 0; in iwxstr_new2()
24 xstr->ptr = malloc(siz); in iwxstr_new2()
25 if (!xstr->ptr) { in iwxstr_new2()
26 free(xstr); in iwxstr_new2()
29 xstr->size = 0; in iwxstr_new2()
30 xstr->asize = siz; in iwxstr_new2()
31 xstr->ptr[0] = '\0'; in iwxstr_new2()
32 return xstr; in iwxstr_new2()
39 void iwxstr_destroy(IWXSTR *xstr) { in iwxstr_destroy() argument
40 if (!xstr) return; in iwxstr_destroy()
41 free(xstr->ptr); in iwxstr_destroy()
42 free(xstr); in iwxstr_destroy()
45 void iwxstr_clear(IWXSTR *xstr) { in iwxstr_clear() argument
46 assert(xstr); in iwxstr_clear()
47 xstr->size = 0; in iwxstr_clear()
50 iwrc iwxstr_cat(IWXSTR *xstr, const void *buf, size_t size) { in iwxstr_cat() argument
51 size_t nsize = xstr->size + size + 1; in iwxstr_cat()
52 if (xstr->asize < nsize) { in iwxstr_cat()
53 while (xstr->asize < nsize) { in iwxstr_cat()
54 xstr->asize <<= 1; in iwxstr_cat()
55 if (xstr->asize < nsize) { in iwxstr_cat()
56 xstr->asize = nsize; in iwxstr_cat()
59 char *ptr = realloc(xstr->ptr, xstr->asize); in iwxstr_cat()
63 xstr->ptr = ptr; in iwxstr_cat()
65 memcpy(xstr->ptr + xstr->size, buf, size); in iwxstr_cat()
66 xstr->size += size; in iwxstr_cat()
67 xstr->ptr[xstr->size] = '\0'; in iwxstr_cat()
71 iwrc iwxstr_cat2(IWXSTR *xstr, const char *buf) { in iwxstr_cat2() argument
72 return buf ? iwxstr_cat(xstr, buf, strlen(buf)) : 0; in iwxstr_cat2()
75 iwrc iwxstr_unshift(IWXSTR *xstr, const void *buf, size_t size) { in iwxstr_unshift() argument
76 size_t nsize = xstr->size + size + 1; in iwxstr_unshift()
77 if (xstr->asize < nsize) { in iwxstr_unshift()
78 while (xstr->asize < nsize) { in iwxstr_unshift()
79 xstr->asize <<= 1; in iwxstr_unshift()
80 if (xstr->asize < nsize) { in iwxstr_unshift()
81 xstr->asize = nsize; in iwxstr_unshift()
84 char *ptr = realloc(xstr->ptr, xstr->asize); in iwxstr_unshift()
88 xstr->ptr = ptr; in iwxstr_unshift()
90 if (xstr->size) { in iwxstr_unshift()
92 memmove(xstr->ptr + size, xstr->ptr, xstr->size); in iwxstr_unshift()
94 memcpy(xstr->ptr, buf, size); in iwxstr_unshift()
95 xstr->size += size; in iwxstr_unshift()
96 xstr->ptr[xstr->size] = '\0'; in iwxstr_unshift()
100 void iwxstr_shift(IWXSTR *xstr, size_t shift_size) { in iwxstr_shift() argument
104 if (shift_size > xstr->size) { in iwxstr_shift()
105 shift_size = xstr->size; in iwxstr_shift()
107 if (xstr->size > shift_size) { in iwxstr_shift()
108 memmove(xstr->ptr, xstr->ptr + shift_size, xstr->size - shift_size); in iwxstr_shift()
110 xstr->size -= shift_size; in iwxstr_shift()
111 xstr->ptr[xstr->size] = '\0'; in iwxstr_shift()
114 static iwrc iwxstr_vaprintf(IWXSTR *xstr, const char *format, va_list ap) { in iwxstr_vaprintf() argument
137 rc = iwxstr_cat(xstr, tmp, strlen(tmp)); in iwxstr_vaprintf()
147 rc = iwxstr_cat(xstr, tbuf, (size_t) tlen); in iwxstr_vaprintf()
161 rc = iwxstr_cat(xstr, tbuf, (size_t) tlen); in iwxstr_vaprintf()
177 rc = iwxstr_cat(xstr, tbuf, (size_t) tlen); in iwxstr_vaprintf()
180 rc = iwxstr_cat(xstr, "%", 1); in iwxstr_vaprintf()
185 rc = iwxstr_cat(xstr, format, 1); in iwxstr_vaprintf()
193 iwrc iwxstr_printf(IWXSTR *xstr, const char *format, ...) { in iwxstr_printf() argument
196 iwrc rc = iwxstr_vaprintf(xstr, format, ap); in iwxstr_printf()
201 char *iwxstr_ptr(IWXSTR *xstr) { in iwxstr_ptr() argument
202 return xstr->ptr; in iwxstr_ptr()
205 size_t iwxstr_size(IWXSTR *xstr) { in iwxstr_size() argument
206 return xstr->size; in iwxstr_size()