Lines Matching refs:buf
33 #define av_bprint_room(buf) ((buf)->size - FFMIN((buf)->len, (buf)->size)) argument
34 #define av_bprint_is_allocated(buf) ((buf)->str != (buf)->reserved_internal_buffer) argument
36 static int av_bprint_alloc(AVBPrint *buf, unsigned room) in av_bprint_alloc() argument
41 if (buf->size == buf->size_max) in av_bprint_alloc()
43 if (!av_bprint_is_complete(buf)) in av_bprint_alloc()
45 min_size = buf->len + 1 + FFMIN(UINT_MAX - buf->len - 1, room); in av_bprint_alloc()
46 new_size = buf->size > buf->size_max / 2 ? buf->size_max : buf->size * 2; in av_bprint_alloc()
48 new_size = FFMIN(buf->size_max, min_size); in av_bprint_alloc()
49 old_str = av_bprint_is_allocated(buf) ? buf->str : NULL; in av_bprint_alloc()
54 memcpy(new_str, buf->str, buf->len + 1); in av_bprint_alloc()
55 buf->str = new_str; in av_bprint_alloc()
56 buf->size = new_size; in av_bprint_alloc()
60 static void av_bprint_grow(AVBPrint *buf, unsigned extra_len) in av_bprint_grow() argument
63 extra_len = FFMIN(extra_len, UINT_MAX - 5 - buf->len); in av_bprint_grow()
64 buf->len += extra_len; in av_bprint_grow()
65 if (buf->size) in av_bprint_grow()
66 buf->str[FFMIN(buf->len, buf->size - 1)] = 0; in av_bprint_grow()
69 void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max) in av_bprint_init() argument
71 unsigned size_auto = (char *)buf + sizeof(*buf) - in av_bprint_init()
72 buf->reserved_internal_buffer; in av_bprint_init()
76 buf->str = buf->reserved_internal_buffer; in av_bprint_init()
77 buf->len = 0; in av_bprint_init()
78 buf->size = FFMIN(size_auto, size_max); in av_bprint_init()
79 buf->size_max = size_max; in av_bprint_init()
80 *buf->str = 0; in av_bprint_init()
81 if (size_init > buf->size) in av_bprint_init()
82 av_bprint_alloc(buf, size_init - 1); in av_bprint_init()
85 void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size) in av_bprint_init_for_buffer() argument
87 buf->str = buffer; in av_bprint_init_for_buffer()
88 buf->len = 0; in av_bprint_init_for_buffer()
89 buf->size = size; in av_bprint_init_for_buffer()
90 buf->size_max = size; in av_bprint_init_for_buffer()
91 *buf->str = 0; in av_bprint_init_for_buffer()
94 void av_bprintf(AVBPrint *buf, const char *fmt, ...) in av_bprintf() argument
102 room = av_bprint_room(buf); in av_bprintf()
103 dst = room ? buf->str + buf->len : NULL; in av_bprintf()
111 if (av_bprint_alloc(buf, extra_len)) in av_bprintf()
114 av_bprint_grow(buf, extra_len); in av_bprintf()
117 void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg) in av_vbprintf() argument
125 room = av_bprint_room(buf); in av_vbprintf()
126 dst = room ? buf->str + buf->len : NULL; in av_vbprintf()
134 if (av_bprint_alloc(buf, extra_len)) in av_vbprintf()
137 av_bprint_grow(buf, extra_len); in av_vbprintf()
140 void av_bprint_chars(AVBPrint *buf, char c, unsigned n) in av_bprint_chars() argument
145 room = av_bprint_room(buf); in av_bprint_chars()
148 if (av_bprint_alloc(buf, n)) in av_bprint_chars()
153 memset(buf->str + buf->len, c, real_n); in av_bprint_chars()
155 av_bprint_grow(buf, n); in av_bprint_chars()
158 void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size) in av_bprint_append_data() argument
163 room = av_bprint_room(buf); in av_bprint_append_data()
166 if (av_bprint_alloc(buf, size)) in av_bprint_append_data()
171 memcpy(buf->str + buf->len, data, real_n); in av_bprint_append_data()
173 av_bprint_grow(buf, size); in av_bprint_append_data()
176 void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm) in av_bprint_strftime() argument
184 room = av_bprint_room(buf); in av_bprint_strftime()
185 if (room && (l = strftime(buf->str + buf->len, room, fmt, tm))) in av_bprint_strftime()
191 if (av_bprint_alloc(buf, room)) { in av_bprint_strftime()
193 room = av_bprint_room(buf); in av_bprint_strftime()
200 av_bprintf(buf, "%s", buf2); in av_bprint_strftime()
208 memset(buf->str + buf->len, '!', room); in av_bprint_strftime()
209 memcpy(buf->str + buf->len, txt, FFMIN(sizeof(txt) - 1, room)); in av_bprint_strftime()
210 av_bprint_grow(buf, room); /* force truncation */ in av_bprint_strftime()
215 av_bprint_grow(buf, l); in av_bprint_strftime()
218 void av_bprint_get_buffer(AVBPrint *buf, unsigned size, in av_bprint_get_buffer() argument
221 if (size > av_bprint_room(buf)) in av_bprint_get_buffer()
222 av_bprint_alloc(buf, size); in av_bprint_get_buffer()
223 *actual_size = av_bprint_room(buf); in av_bprint_get_buffer()
224 *mem = *actual_size ? buf->str + buf->len : NULL; in av_bprint_get_buffer()
227 void av_bprint_clear(AVBPrint *buf) in av_bprint_clear() argument
229 if (buf->len) { in av_bprint_clear()
230 *buf->str = 0; in av_bprint_clear()
231 buf->len = 0; in av_bprint_clear()
235 int av_bprint_finalize(AVBPrint *buf, char **ret_str) in av_bprint_finalize() argument
237 unsigned real_size = FFMIN(buf->len + 1, buf->size); in av_bprint_finalize()
242 if (av_bprint_is_allocated(buf)) { in av_bprint_finalize()
243 str = av_realloc(buf->str, real_size); in av_bprint_finalize()
245 str = buf->str; in av_bprint_finalize()
246 buf->str = NULL; in av_bprint_finalize()
250 memcpy(str, buf->str, real_size); in av_bprint_finalize()
256 if (av_bprint_is_allocated(buf)) in av_bprint_finalize()
257 av_freep(&buf->str); in av_bprint_finalize()
259 buf->size = real_size; in av_bprint_finalize()