Coverage Report

Created: 2026-04-12 07:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/include/vlc_memstream.h
Line
Count
Source
1
/*****************************************************************************
2
 * vlc_memstream.h:
3
 *****************************************************************************
4
 * Copyright (C) 2016 Rémi Denis-Courmont
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program 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
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19
 *****************************************************************************/
20
21
#ifndef VLC_MEMSTREAM_H
22
# define VLC_MEMSTREAM_H 1
23
24
# include <stdarg.h>
25
# include <stdio.h>
26
27
/**
28
 * \defgroup memstream In-memory byte streams
29
 * \ingroup cext
30
 *
31
 * In-memory byte stream are a portable wrapper for in-memory formatted output
32
 * byte streams. Compare with POSIX @c open_memstream().
33
 *
34
 * @{
35
 */
36
37
/**
38
 * In-memory stream object.
39
 */
40
struct vlc_memstream
41
{
42
    FILE *stream;
43
    char *ptr; /**< Buffer start address */
44
    size_t length; /**< Buffer length in bytes */
45
};
46
47
/**
48
 * Initializes a byte stream object.
49
 *
50
 * @note Even when this function fails, the stream object is initialized and
51
 * can be used safely. It is sufficient to check for errors from
52
 * vlc_memstream_flush() and vlc_memstream_close().
53
 *
54
 * Compare with POSIX @c open_memstream().
55
 *
56
 * @param ms byte stream object
57
 *
58
 * @retval 0 on success
59
 * @retval EOF on error
60
 */
61
VLC_API
62
int vlc_memstream_open(struct vlc_memstream *ms);
63
64
/**
65
 * Flushes a byte stream object.
66
 *
67
 * This function ensures that any previous write to the byte stream is flushed
68
 * and the in-memory buffer is synchronized. It can be used observe the content
69
 * of the buffer before the final vlc_memstream_close().
70
 *
71
 * Compare with @c fflush().
72
 *
73
 * @note vlc_memstream_close() implicitly flushes the object.
74
 * Calling vlc_memstream_flush() before closing is thus superfluous.
75
 *
76
 * @warning @c ms->ptr must <b>not</b> be freed. It can only be freed after
77
 * a successful call to vlc_memstream_close().
78
 *
79
 * @retval 0 success, i.e., @c ms->ptr and @c ms->length are valid
80
 * @retval EOF failure (@c ms->ptr and @c ms->length are unspecified)
81
 */
82
VLC_API
83
int vlc_memstream_flush(struct vlc_memstream *ms) VLC_USED;
84
85
/**
86
 * Closes a byte stream object.
87
 *
88
 * This function flushes the stream object, releases any underlying
89
 * resource, except for the heap-allocated formatted buffer @c ms->ptr,
90
 * and deinitializes the object.
91
 *
92
 * On success, the caller is responsible for freeing the buffer with @c free().
93
 *
94
 * Compare with @c fclose().
95
 *
96
 * \retval 0 success
97
 * \retval EOF failure (@c ms->ptr and @c ms->length are unspecified)
98
 */
99
VLC_API
100
int vlc_memstream_close(struct vlc_memstream *ms) VLC_USED;
101
102
/**
103
 * Appends a binary blob to a byte stream.
104
 *
105
 * Compare with @c fwrite().
106
 *
107
 * @param ms the VLC memstream to write to
108
 * @param ptr start address of the blob
109
 * @param len byte length of the blob
110
 */
111
VLC_API
112
size_t vlc_memstream_write(struct vlc_memstream *ms,
113
                           const void *ptr, size_t len);
114
115
/**
116
 * Appends a single byte to a byte stream.
117
 *
118
 * Compare with @c putc() or @c fputc().
119
 *
120
 * @param ms the VLC memstream to write to
121
 * @param c Unsigned byte value converted to int.
122
 */
123
VLC_API
124
int vlc_memstream_putc(struct vlc_memstream *ms, int c);
125
126
/**
127
 * Appends a nul-terminated string to a byte stream.
128
 *
129
 * Compare with @c fputs().
130
 */
131
VLC_API
132
int vlc_memstream_puts(struct vlc_memstream *ms, const char *str);
133
134
/**
135
 * Appends a formatted string to a byte stream.
136
 *
137
 * Compare with @c vfprintf().
138
 */
139
VLC_API
140
int vlc_memstream_vprintf(struct vlc_memstream *ms, const char *fmt,
141
                          va_list args);
142
143
/**
144
 * Appends a formatted string to a byte stream.
145
 *
146
 * Compare with @c fprintf().
147
 */
148
VLC_API
149
int vlc_memstream_printf(struct vlc_memstream *s, const char *fmt,
150
                         ...) VLC_FORMAT(2,3);
151
152
# ifdef __GNUC__
153
static inline int vlc_memstream_puts_len(struct vlc_memstream *ms,
154
                                         const char *str, size_t len)
155
977k
{
156
977k
    return (vlc_memstream_write(ms, str, len) == len) ? (int)len : EOF;
157
977k
}
Unexecuted instantiation: ttml.c:vlc_memstream_puts_len
Unexecuted instantiation: encttml.c:vlc_memstream_puts_len
Unexecuted instantiation: substtml.c:vlc_memstream_puts_len
genttml.c:vlc_memstream_puts_len
Line
Count
Source
155
564k
{
156
564k
    return (vlc_memstream_write(ms, str, len) == len) ? (int)len : EOF;
157
564k
}
webvtt.c:vlc_memstream_puts_len
Line
Count
Source
155
4.54k
{
156
4.54k
    return (vlc_memstream_write(ms, str, len) == len) ? (int)len : EOF;
157
4.54k
}
Unexecuted instantiation: subsvtt.c:vlc_memstream_puts_len
Unexecuted instantiation: external.c:vlc_memstream_puts_len
Unexecuted instantiation: access.c:vlc_memstream_puts_len
Unexecuted instantiation: demux.c:vlc_memstream_puts_len
Unexecuted instantiation: input.c:vlc_memstream_puts_len
Unexecuted instantiation: player.c:vlc_memstream_puts_len
Unexecuted instantiation: osd.c:vlc_memstream_puts_len
Unexecuted instantiation: stream.c:vlc_memstream_puts_len
Unexecuted instantiation: stream_extractor.c:vlc_memstream_puts_len
Unexecuted instantiation: stream_filter.c:vlc_memstream_puts_len
Unexecuted instantiation: stream_memory.c:vlc_memstream_puts_len
Unexecuted instantiation: memstream.c:vlc_memstream_puts_len
strings.c:vlc_memstream_puts_len
Line
Count
Source
155
408k
{
156
408k
    return (vlc_memstream_write(ms, str, len) == len) ? (int)len : EOF;
157
408k
}
Unexecuted instantiation: url.c:vlc_memstream_puts_len
cpu.c:vlc_memstream_puts_len
Line
Count
Source
155
290
{
156
290
    return (vlc_memstream_write(ms, str, len) == len) ? (int)len : EOF;
157
290
}
Unexecuted instantiation: vlmshell.c:vlc_memstream_puts_len
Unexecuted instantiation: ipc.c:vlc_memstream_puts_len
Unexecuted instantiation: es_out.c:vlc_memstream_puts_len
Unexecuted instantiation: chroma_probe.c:vlc_memstream_puts_len
Unexecuted instantiation: fetcher.c:vlc_memstream_puts_len
158
#  define vlc_memstream_puts(ms,s) \
159
2.78M
    (__builtin_constant_p(__builtin_strlen(s)) ? \
160
2.78M
        vlc_memstream_puts_len(ms,s,__builtin_strlen(s)) : \
161
2.78M
        vlc_memstream_puts(ms,s))
162
# endif
163
164
/** @} */
165
166
#endif /* VLC_MEMSTREAM_H */