SmolRTSP  0.1.3
A small, portable, extensible RTSP 1.0 implementation in C99
writer.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <stdarg.h>
9 #include <stddef.h>
10 #include <stdio.h>
11 
12 #include <unistd.h>
13 
14 #include <interface99.h>
15 #include <slice99.h>
16 
17 #include <smolrtsp/priv/compiler_attrs.h>
18 
22 #define SmolRTSP_Writer_IFACE \
23  \
24  /* \
25  * Writes @p data into itself. \
26  * \
27  * @param[in] data The slice of character data to write. \
28  * \
29  * @return The number of bytes written or a negative value on error. \
30  */ \
31  vfunc99(ssize_t, write, VSelf99, CharSlice99 data) \
32  \
33  /* \
34  * Lock writer to prevent race conditions on TCP interleaved channels \
35  */ \
36  vfunc99(void, lock, VSelf99) \
37  \
38  /* \
39  * Unlock writer locked by `lock` \
40  */ \
41  vfunc99(void, unlock, VSelf99) \
42  \
43  /* \
44  * Get current size of output buffer \
45  */ \
46  vfunc99(size_t, filled, VSelf99) \
47  \
48  /* \
49  * Writes a formatted string into itself. \
50  * \
51  * @param[in] fmt The `printf`-like format string. \
52  * \
53  * @return The number of bytes written or a negative value on error. \
54  */ \
55  vfunc99(int, writef, VSelf99, const char *restrict fmt, ...) \
56  \
57  /* \
58  * The same as `printf` but accepts `va_list`. \
59  */ \
60  vfunc99(int, vwritef, VSelf99, const char *restrict fmt, va_list ap)
61 
68 interface99(SmolRTSP_Writer);
69 
74 #define SMOLRTSP_WRITE_SLICES(w, ...) \
75  smolrtsp_write_slices( \
76  w, SLICE99_ARRAY_LEN((const CharSlice99[])__VA_ARGS__), \
77  (const CharSlice99[])__VA_ARGS__)
78 
90 ssize_t smolrtsp_write_slices(
91  SmolRTSP_Writer w, size_t len,
92  const CharSlice99 data[restrict static len]) SMOLRTSP_PRIV_MUST_USE;
93 
99 SmolRTSP_Writer smolrtsp_fd_writer(int *fd) SMOLRTSP_PRIV_MUST_USE;
100 
106 SmolRTSP_Writer smolrtsp_file_writer(FILE *stream) SMOLRTSP_PRIV_MUST_USE;
107 
114 SmolRTSP_Writer smolrtsp_string_writer(char *buffer) SMOLRTSP_PRIV_MUST_USE;
SmolRTSP_Writer smolrtsp_string_writer(char *buffer) SMOLRTSP_PRIV_MUST_USE
A writer that invokes strncat on a provided buffer.
SmolRTSP_Writer smolrtsp_fd_writer(int *fd) SMOLRTSP_PRIV_MUST_USE
A writer that invokes write on a provided file descriptor.
SmolRTSP_Writer smolrtsp_file_writer(FILE *stream) SMOLRTSP_PRIV_MUST_USE
A writer that invokes fwrite on a provided file pointer.
interface99(SmolRTSP_Writer)
Defines the SmolRTSP_Writer interface.
ssize_t smolrtsp_write_slices(SmolRTSP_Writer w, size_t len, const CharSlice99 data[restrict static len]) SMOLRTSP_PRIV_MUST_USE
Sequentially writes all items in data to w.