FFmpeg  3.2.18
bprint.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Nicolas George
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVUTIL_BPRINT_H
22 #define AVUTIL_BPRINT_H
23 
24 #include <stdarg.h>
25 
26 #include "attributes.h"
27 #include "avstring.h"
28 
29 /**
30  * Define a structure with extra padding to a fixed size
31  * This helps ensuring binary compatibility with future versions.
32  */
33 
34 #define FF_PAD_STRUCTURE(name, size, ...) \
35 struct ff_pad_helper_##name { __VA_ARGS__ }; \
36 typedef struct name { \
37  __VA_ARGS__ \
38  char reserved_padding[size - sizeof(struct ff_pad_helper_##name)]; \
39 } name;
40 
41 /**
42  * Buffer to print data progressively
43  *
44  * The string buffer grows as necessary and is always 0-terminated.
45  * The content of the string is never accessed, and thus is
46  * encoding-agnostic and can even hold binary data.
47  *
48  * Small buffers are kept in the structure itself, and thus require no
49  * memory allocation at all (unless the contents of the buffer is needed
50  * after the structure goes out of scope). This is almost as lightweight as
51  * declaring a local "char buf[512]".
52  *
53  * The length of the string can go beyond the allocated size: the buffer is
54  * then truncated, but the functions still keep account of the actual total
55  * length.
56  *
57  * In other words, buf->len can be greater than buf->size and records the
58  * total length of what would have been to the buffer if there had been
59  * enough memory.
60  *
61  * Append operations do not need to be tested for failure: if a memory
62  * allocation fails, data stop being appended to the buffer, but the length
63  * is still updated. This situation can be tested with
64  * av_bprint_is_complete().
65  *
66  * The size_max field determines several possible behaviours:
67  *
68  * size_max = -1 (= UINT_MAX) or any large value will let the buffer be
69  * reallocated as necessary, with an amortized linear cost.
70  *
71  * size_max = 0 prevents writing anything to the buffer: only the total