Thu, 28 Dec 2023 19:17:45 +0100
fix accidental generation of cxListIterator() symbol
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28 /**
29 * \file printf.h
30 * \brief Wrapper for write functions with a printf-like interface.
31 * \author Mike Becker
32 * \author Olaf Wintermann
33 * \copyright 2-Clause BSD License
34 */
36 #ifndef UCX_PRINTF_H
37 #define UCX_PRINTF_H
39 #include "common.h"
40 #include "string.h"
41 #include <stdarg.h>
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
47 /**
48 * A \c fprintf like function which writes the output to a stream by
49 * using a write_func.
50 *
51 * @param stream the stream the data is written to
52 * @param wfc the write function
53 * @param fmt format string
54 * @param ... additional arguments
55 * @return the total number of bytes written
56 */
57 __attribute__((__nonnull__(1, 2, 3), __format__(printf, 3, 4)))
58 int cx_fprintf(
59 void *stream,
60 cx_write_func wfc,
61 char const *fmt,
62 ...
63 );
65 /**
66 * A \c vfprintf like function which writes the output to a stream by
67 * using a write_func.
68 *
69 * @param stream the stream the data is written to
70 * @param wfc the write function
71 * @param fmt format string
72 * @param ap argument list
73 * @return the total number of bytes written
74 * @see cx_fprintf()
75 */
76 __attribute__((__nonnull__))
77 int cx_vfprintf(
78 void *stream,
79 cx_write_func wfc,
80 char const *fmt,
81 va_list ap
82 );
84 /**
85 * A \c asprintf like function which allocates space for a string
86 * the result is written to.
87 *
88 * \note The resulting string is guaranteed to be zero-terminated.
89 *
90 * @param allocator the CxAllocator used for allocating the string
91 * @param fmt format string
92 * @param ... additional arguments
93 * @return the formatted string
94 * @see cx_strfree_a()
95 */
96 __attribute__((__nonnull__(1, 2), __format__(printf, 2, 3)))
97 cxmutstr cx_asprintf_a(
98 CxAllocator const *allocator,
99 char const *fmt,
100 ...
101 );
103 /**
104 * A \c asprintf like function which allocates space for a string
105 * the result is written to.
106 *
107 * \note The resulting string is guaranteed to be zero-terminated.
108 *
109 * @param fmt format string
110 * @param ... additional arguments
111 * @return the formatted string
112 * @see cx_strfree()
113 */
114 #define cx_asprintf(fmt, ...) \
115 cx_asprintf_a(cxDefaultAllocator, fmt, __VA_ARGS__)
117 /**
118 * A \c vasprintf like function which allocates space for a string
119 * the result is written to.
120 *
121 * \note The resulting string is guaranteed to be zero-terminated.
122 *
123 * @param allocator the CxAllocator used for allocating the string
124 * @param fmt format string
125 * @param ap argument list
126 * @return the formatted string
127 * @see cx_asprintf_a()
128 */
129 __attribute__((__nonnull__))
130 cxmutstr cx_vasprintf_a(
131 CxAllocator const *allocator,
132 char const *fmt,
133 va_list ap
134 );
136 /**
137 * A \c vasprintf like function which allocates space for a string
138 * the result is written to.
139 *
140 * \note The resulting string is guaranteed to be zero-terminated.
141 *
142 * @param fmt format string
143 * @param ap argument list
144 * @return the formatted string
145 * @see cx_asprintf()
146 */
147 #define cx_vasprintf(fmt, ap) cx_vasprintf_a(cxDefaultAllocator, fmt, ap)
149 /**
150 * A \c printf like function which writes the output to a CxBuffer.
151 *
152 * @param buffer a pointer to the buffer the data is written to
153 * @param fmt the format string
154 * @param ... additional arguments
155 * @return the total number of bytes written
156 * @see ucx_fprintf()
157 */
158 #define cx_bprintf(buffer, fmt, ...) cx_fprintf((CxBuffer*)buffer, \
159 (cx_write_func) cxBufferWrite, fmt, __VA_ARGS__)
161 #ifdef __cplusplus
162 } // extern "C"
163 #endif
165 #endif //UCX_PRINTF_H