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