Lines Matching refs:sb
47 static inline void strbuf_set_error(struct vrend_strbuf *sb) in strbuf_set_error() argument
49 sb->error_state = true; in strbuf_set_error()
52 static inline bool strbuf_get_error(struct vrend_strbuf *sb) in strbuf_get_error() argument
54 return sb->error_state; in strbuf_get_error()
57 static inline size_t strbuf_get_len(struct vrend_strbuf *sb) in strbuf_get_len() argument
59 return sb->size; in strbuf_get_len()
62 static inline void strbuf_free(struct vrend_strbuf *sb) in strbuf_free() argument
64 free(sb->buf); in strbuf_free()
67 static inline bool strbuf_alloc(struct vrend_strbuf *sb, int initial_size) in strbuf_alloc() argument
69 sb->buf = malloc(initial_size); in strbuf_alloc()
70 if (!sb->buf) in strbuf_alloc()
72 sb->alloc_size = initial_size; in strbuf_alloc()
73 sb->buf[0] = 0; in strbuf_alloc()
74 sb->error_state = false; in strbuf_alloc()
75 sb->size = 0; in strbuf_alloc()
82 static inline bool strbuf_grow(struct vrend_strbuf *sb, int len) in strbuf_grow() argument
84 if (sb->size + len + 1 > sb->alloc_size) { in strbuf_grow()
88 size_t new_size = MAX2(sb->size + len + 1, sb->alloc_size + STRBUF_MIN_MALLOC); in strbuf_grow()
89 char *new = realloc(sb->buf, new_size); in strbuf_grow()
91 strbuf_set_error(sb); in strbuf_grow()
94 sb->buf = new; in strbuf_grow()
95 sb->alloc_size = new_size; in strbuf_grow()
100 static inline void strbuf_append_buffer(struct vrend_strbuf *sb, const char *data, size_t len) in strbuf_append_buffer() argument
103 if (strbuf_get_error(sb) || in strbuf_append_buffer()
104 !strbuf_grow(sb, len)) in strbuf_append_buffer()
106 memcpy(sb->buf + sb->size, data, len); in strbuf_append_buffer()
107 sb->size += len; in strbuf_append_buffer()
108 sb->buf[sb->size] = '\0'; in strbuf_append_buffer()
111 static inline void strbuf_append(struct vrend_strbuf *sb, const char *addstr) in strbuf_append() argument
113 strbuf_append_buffer(sb, addstr, strlen(addstr)); in strbuf_append()
116 static inline void strbuf_vappendf(struct vrend_strbuf *sb, const char *fmt, va_list ap) in strbuf_vappendf() argument
121 int len = vsnprintf(sb->buf + sb->size, sb->alloc_size - sb->size, fmt, ap); in strbuf_vappendf()
122 if (len >= (int)(sb->alloc_size - sb->size)) { in strbuf_vappendf()
123 if (!strbuf_grow(sb, len)) in strbuf_vappendf()
125 vsnprintf(sb->buf + sb->size, sb->alloc_size - sb->size, fmt, cp); in strbuf_vappendf()
127 sb->size += len; in strbuf_vappendf()
131 static inline void strbuf_appendf(struct vrend_strbuf *sb, const char *fmt, ...) in strbuf_appendf() argument
135 strbuf_vappendf(sb, fmt, va); in strbuf_appendf()
139 static inline void strbuf_vfmt(struct vrend_strbuf *sb, const char *fmt, va_list ap) in strbuf_vfmt() argument
144 int len = vsnprintf(sb->buf, sb->alloc_size, fmt, ap); in strbuf_vfmt()
145 if (len >= (int)(sb->alloc_size)) { in strbuf_vfmt()
146 if (!strbuf_grow(sb, len)) in strbuf_vfmt()
148 vsnprintf(sb->buf, sb->alloc_size, fmt, cp); in strbuf_vfmt()
150 sb->size = len; in strbuf_vfmt()
154 static inline void strbuf_fmt(struct vrend_strbuf *sb, const char *fmt, ...) in strbuf_fmt() argument
158 strbuf_vfmt(sb, fmt, va); in strbuf_fmt()
178 static inline bool strarray_addstrbuf(struct vrend_strarray *sa, const struct vrend_strbuf *sb) in strarray_addstrbuf() argument
183 sa->strings[sa->num_strings] = *sb; in strarray_addstrbuf()