Lines Matching refs:b

19 	buffer * const b = calloc(1, sizeof(*b));  in buffer_init()  local
20 force_assert(b); in buffer_init()
21 return b; in buffer_init()
25 void buffer_free(buffer *b) { in buffer_free() argument
26 if (NULL == b) return; in buffer_free()
27 free(b->ptr); in buffer_free()
28 free(b); in buffer_free()
31 void buffer_free_ptr(buffer *b) { in buffer_free_ptr() argument
32 free(b->ptr); in buffer_free_ptr()
33 b->ptr = NULL; in buffer_free_ptr()
34 b->used = 0; in buffer_free_ptr()
35 b->size = 0; in buffer_free_ptr()
38 void buffer_move(buffer * restrict b, buffer * restrict src) { in buffer_move() argument
40 buffer_clear(b); in buffer_move()
41 tmp = *src; *src = *b; *b = tmp; in buffer_move()
49 static char* buffer_realloc(buffer * const restrict b, const size_t len) { in __attribute_nonnull__()
60 b->size = sz; in __attribute_nonnull__()
61 b->ptr = realloc(b->ptr, sz); in __attribute_nonnull__()
63 force_assert(NULL != b->ptr); in __attribute_nonnull__()
64 return b->ptr; in __attribute_nonnull__()
71 static char* buffer_alloc_replace(buffer * const restrict b, const size_t size) { in __attribute_nonnull__()
73 if (NULL != b->ptr) { in __attribute_nonnull__()
74 free(b->ptr); in __attribute_nonnull__()
75 b->ptr = NULL; in __attribute_nonnull__()
78 const size_t bsize2x = (b->size & ~1uL) << 1; in __attribute_nonnull__()
79 return buffer_realloc(b, bsize2x > size ? bsize2x-1 : size); in __attribute_nonnull__()
82 char* buffer_string_prepare_copy(buffer * const b, const size_t size) { in buffer_string_prepare_copy() argument
83 b->used = 0; in buffer_string_prepare_copy()
85 force_assert(size >= b->size || b->ptr); in buffer_string_prepare_copy()
87 return (size < b->size) in buffer_string_prepare_copy()
88 ? b->ptr in buffer_string_prepare_copy()
89 : buffer_alloc_replace(b, size); in buffer_string_prepare_copy()
96 static char* buffer_string_prepare_append_resize(buffer * const restrict b, const size_t size) { in __attribute_nonnull__()
97 if (b->used < 2) { /* buffer_is_blank(b) */ in __attribute_nonnull__()
98 char * const s = buffer_string_prepare_copy(b, size); in __attribute_nonnull__()
105 const size_t bsize2x = (b->size & ~1uL) << 1; in __attribute_nonnull__()
106 const size_t req_size = (bsize2x - b->used > size) in __attribute_nonnull__()
108 : b->used + size; in __attribute_nonnull__()
111 force_assert(req_size >= b->used); in __attribute_nonnull__()
113 return buffer_realloc(b, req_size) + b->used - 1; in __attribute_nonnull__()
116 char* buffer_string_prepare_append(buffer * const b, const size_t size) { in buffer_string_prepare_append() argument
117 const uint32_t len = b->used ? b->used-1 : 0; in buffer_string_prepare_append()
118 return (b->size - len >= size + 1) in buffer_string_prepare_append()
119 ? b->ptr + len in buffer_string_prepare_append()
120 : buffer_string_prepare_append_resize(b, size); in buffer_string_prepare_append()
126 buffer_extend (buffer * const b, const size_t x) in buffer_extend() argument
133 char * const s = buffer_string_prepare_append(b, x); in buffer_extend()
134 b->used += x + (0 == b->used); in buffer_extend()
136 const uint32_t len = b->used ? b->used-1 : 0; in buffer_extend()
137 char * const s = (b->size - len >= x + 1) in buffer_extend()
138 ? b->ptr + len in buffer_extend()
139 : buffer_string_prepare_append_resize(b, x); in buffer_extend()
140 b->used = len+x+1; in buffer_extend()
146 void buffer_commit(buffer *b, size_t size) in buffer_commit() argument
148 size_t sz = b->used; in buffer_commit()
157 b->used = sz; in buffer_commit()
158 b->ptr[sz - 1] = '\0'; in buffer_commit()
162 void buffer_copy_string(buffer * restrict b, const char * restrict s) { in buffer_copy_string() argument
164 buffer_copy_string_len(b, s, strlen(s)); in buffer_copy_string()
167 void buffer_copy_string_len(buffer * const restrict b, const char * const restrict s, const size_t … in buffer_copy_string_len() argument
168 b->used = len + 1; in buffer_copy_string_len()
169 char * const restrict d = (len < b->size) in buffer_copy_string_len()
170 ? b->ptr in buffer_copy_string_len()
171 : buffer_alloc_replace(b, len); in buffer_copy_string_len()
177 void buffer_append_string(buffer * restrict b, const char * restrict s) { in buffer_append_string() argument
179 buffer_append_string_len(b, s, strlen(s)); in buffer_append_string()
193 void buffer_append_string_len(buffer * const restrict b, const char * const restrict s, const size_… in buffer_append_string_len() argument
194 memcpy(buffer_extend(b, len), s, len); in buffer_append_string_len()
197 void buffer_append_str2(buffer * const restrict b, const char * const s1, const size_t len1, const … in buffer_append_str2() argument
198 char * const restrict s = buffer_extend(b, len1+len2); in buffer_append_str2()
207 void buffer_append_str3(buffer * const restrict b, const char * const s1, const size_t len1, const … in buffer_append_str3() argument
208 char * restrict s = buffer_extend(b, len1+len2+len3); in buffer_append_str3()
218 void buffer_append_iovec(buffer * const restrict b, const struct const_iovec * const iov, const siz… in buffer_append_iovec() argument
222 char *s = buffer_extend(b, len); in buffer_append_iovec()
234 void buffer_append_path_len(buffer * restrict b, const char * restrict a, size_t alen) { in buffer_append_path_len() argument
235 char * restrict s = buffer_string_prepare_append(b, alen+1); in buffer_append_path_len()
237 if (b->used > 1 && s[-1] == '/') { in buffer_append_path_len()
244 if (0 == b->used) b->used = 1; in buffer_append_path_len()
247 ++b->used; in buffer_append_path_len()
250 b->used += alen; in buffer_append_path_len()
256 buffer_copy_path_len2 (buffer * const restrict b, const char * const restrict s1, size_t len1, cons… in buffer_copy_path_len2() argument
259 memcpy(buffer_string_prepare_copy(b, len1+len2+1), s1, len1); in buffer_copy_path_len2()
260 b->used = len1 + 1; /*('\0' byte will be written below)*/ in buffer_copy_path_len2()
262 buffer_append_path_len(b, s2, len2);/*(choice: not inlined, special-cased)*/ in buffer_copy_path_len2()
266 buffer_copy_string_len_lc (buffer * const restrict b, const char * const restrict s, const size_t l… in buffer_copy_string_len_lc() argument
268 char * const restrict d = buffer_string_prepare_copy(b, len); in buffer_copy_string_len_lc()
269 b->used = len+1; in buffer_copy_string_len_lc()
275 void buffer_append_uint_hex_lc(buffer *b, uintmax_t value) { in buffer_append_uint_hex_lc() argument
287 buf = buffer_extend(b, shift >> 2); /*nibbles (4 bits)*/ in buffer_append_uint_hex_lc()
320 void buffer_append_int(buffer *b, intmax_t val) { in buffer_append_int() argument
323 buffer_append_string_len(b, str, buf+sizeof(buf) - str); in buffer_append_int()
326 void buffer_append_strftime(buffer * const restrict b, const char * const restrict format, const st… in buffer_append_strftime() argument
332 size_t rv = strftime(buffer_string_prepare_append(b, 63), 64, format, tm); in buffer_append_strftime()
338 rv = strftime(buffer_string_prepare_append(b, 4095), 4096, format, tm); in buffer_append_strftime()
344 b->used += (uint32_t)rv + (0 == b->used); in buffer_append_strftime()
401 int buffer_eq_icase_ssn(const char * const a, const char * const b, const size_t len) { in buffer_eq_icase_ssn() argument
404 unsigned int cb = ((unsigned char *)b)[i]; in buffer_eq_icase_ssn()
410 int buffer_eq_icase_ss(const char * const a, const size_t alen, const char * const b, const size_t … in buffer_eq_icase_ss() argument
412 return (alen == blen) ? buffer_eq_icase_ssn(a, b, blen) : 0; in buffer_eq_icase_ss()
415 int buffer_eq_icase_slen(const buffer * const b, const char * const s, const size_t slen) { in buffer_eq_icase_slen() argument
418 return (b->used == slen + 1) ? buffer_eq_icase_ssn(b->ptr, s, slen) : 0; in buffer_eq_icase_slen()
421 int buffer_eq_slen(const buffer * const b, const char * const s, const size_t slen) { in buffer_eq_slen() argument
424 return (b->used == slen + 1 && 0 == memcmp(b->ptr, s, slen)); in buffer_eq_slen()
432 int buffer_is_equal(const buffer *a, const buffer *b) { in buffer_is_equal() argument
434 return (a->used == b->used && 0 == memcmp(a->ptr, b->ptr, a->used)); in buffer_is_equal()
461 void buffer_substr_replace (buffer * const restrict b, const size_t offset, in buffer_substr_replace() argument
464 const size_t blen = buffer_clen(b); in buffer_substr_replace()
468 buffer_extend(b, rlen-len); in buffer_substr_replace()
469 memmove(b->ptr+offset+rlen, b->ptr+offset+len, blen-offset-len); in buffer_substr_replace()
472 memcpy(b->ptr+offset, replace->ptr, rlen); in buffer_substr_replace()
475 memmove(b->ptr+offset+rlen, b->ptr+offset+len, blen-offset-len); in buffer_substr_replace()
476 buffer_truncate(b, blen-len+rlen); in buffer_substr_replace()
481 void buffer_append_string_encoded_hex_lc(buffer * const restrict b, const char * const restrict s, … in buffer_append_string_encoded_hex_lc() argument
482 unsigned char * const p = (unsigned char *)buffer_extend(b, len*2); in buffer_append_string_encoded_hex_lc()
489 void buffer_append_string_encoded_hex_uc(buffer * const restrict b, const char * const restrict s, … in buffer_append_string_encoded_hex_uc() argument
490 unsigned char * const p = (unsigned char *)buffer_extend(b, len*2); in buffer_append_string_encoded_hex_uc()
590 void buffer_append_string_encoded(buffer * const restrict b, const char * const restrict s, size_t … in buffer_append_string_encoded() argument
628 d = (unsigned char*) buffer_extend(b, d_len); in buffer_append_string_encoded()
660 void buffer_append_string_c_escaped(buffer * const restrict b, const char * const restrict s, size_… in buffer_append_string_c_escaped() argument
682 d = (unsigned char*) buffer_extend(b, d_len); in buffer_append_string_c_escaped()
716 buffer_append_bs_escaped (buffer * const restrict b, in buffer_append_bs_escaped() argument
727 buffer_string_prepare_append(b, len); in buffer_append_bs_escaped()
734 if (s - ptr) buffer_append_string_len(b, ptr, s - ptr); in buffer_append_bs_escaped()
750 d = buffer_extend(b, 2); in buffer_append_bs_escaped()
756 d = buffer_extend(b, 4); in buffer_append_bs_escaped()
768 buffer_append_bs_escaped_json (buffer * const restrict b, in buffer_append_bs_escaped_json() argument
775 buffer_string_prepare_append(b, len); in buffer_append_bs_escaped_json()
782 if (s - ptr) buffer_append_string_len(b, ptr, s - ptr); in buffer_append_bs_escaped_json()
798 d = buffer_extend(b, 2); in buffer_append_bs_escaped_json()
803 d = buffer_extend(b, 6); in buffer_append_bs_escaped_json()
822 void buffer_urldecode_path(buffer * const b) { in buffer_urldecode_path() argument
823 const size_t len = buffer_clen(b); in buffer_urldecode_path()
824 char *src = len ? memchr(b->ptr, '%', len) : NULL; in buffer_urldecode_path()
840 b->used = (dst - b->ptr) + 1; in buffer_urldecode_path()
843 int buffer_is_valid_UTF8(const buffer *b) { in buffer_is_valid_UTF8() argument
846 const unsigned char *c = (unsigned char *)b->ptr; in buffer_is_valid_UTF8()
893 void buffer_path_simplify(buffer *b) in buffer_path_simplify() argument
895 char *out = b->ptr; in buffer_path_simplify()
896 char * const end = b->ptr + b->used - 1; in buffer_path_simplify()
898 if (__builtin_expect( (buffer_is_blank(b)), 0)) { in buffer_path_simplify()
899 buffer_blank(b); in buffer_path_simplify()
905 for (char *p = b->ptr; *p; p++) { in buffer_path_simplify()
955 while (out > b->ptr && *--out != '/') ; in buffer_path_simplify()
982 b->used = (out - b->ptr) + 1; in buffer_path_simplify()
986 void buffer_to_lower(buffer * const b) { in buffer_to_lower() argument
987 unsigned char * const restrict s = (unsigned char *)b->ptr; in buffer_to_lower()
988 const uint_fast32_t used = b->used; in buffer_to_lower()
995 void buffer_to_upper(buffer * const b) { in buffer_to_upper() argument
996 unsigned char * const restrict s = (unsigned char *)b->ptr; in buffer_to_upper()
997 const uint_fast32_t used = b->used; in buffer_to_upper()