Mon, 10 Feb 2025 20:59:02 +0100
add support for building windows DLLs - resolves #582
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
29 | * @file printf.h |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
30 | * @brief Wrapper for write functions with a printf-like interface. |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
31 | * @author Mike Becker |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
32 | * @author Olaf Wintermann |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
33 | * @copyright 2-Clause BSD License |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | */ |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | #ifndef UCX_PRINTF_H |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | #define UCX_PRINTF_H |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | #include "common.h" |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | #include "string.h" |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
41 | #include <stdarg.h> |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
43 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
44 | * Attribute for printf-like functions. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
45 | * @param fmt_idx index of the format string parameter |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
46 | * @param arg_idx index of the first formatting argument |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
47 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
48 | #define cx_attr_printf(fmt_idx, arg_idx) \ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
49 | __attribute__((__format__(printf, fmt_idx, arg_idx))) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
50 | |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | #ifdef __cplusplus |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | extern "C" { |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | #endif |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | |
805
26500fc24058
add constant for reading out printf sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
55 | |
26500fc24058
add constant for reading out printf sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
56 | /** |
26500fc24058
add constant for reading out printf sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
57 | * The maximum string length that fits into stack memory. |
26500fc24058
add constant for reading out printf sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
58 | */ |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1112
diff
changeset
|
59 | cx_attr_export |
926
8fdd8d78c14b
fix several survivors of east-const and some missing consts
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
60 | extern const unsigned cx_printf_sbo_size; |
805
26500fc24058
add constant for reading out printf sbo size - relates to #343
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
61 | |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
63 | * A @c fprintf like function which writes the output to a stream by |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | * using a write_func. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
65 | * |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | * @param stream the stream the data is written to |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | * @param wfc the write function |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | * @param fmt format string |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | * @param ... additional arguments |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
70 | * @return the total number of bytes written or an error code from stdlib printf implementation |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
72 | cx_attr_nonnull_arg(1, 2, 3) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
73 | cx_attr_printf(3, 4) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
74 | cx_attr_cstr_arg(3) |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1112
diff
changeset
|
75 | cx_attr_export |
635
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
76 | int cx_fprintf( |
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
77 | void *stream, |
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
78 | cx_write_func wfc, |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
849
diff
changeset
|
79 | const char *fmt, |
635
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
80 | ... |
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
81 | ); |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
84 | * A @c vfprintf like function which writes the output to a stream by |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | * using a write_func. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | * |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | * @param stream the stream the data is written to |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | * @param wfc the write function |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | * @param fmt format string |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | * @param ap argument list |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
91 | * @return the total number of bytes written or an error code from stdlib printf implementation |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | * @see cx_fprintf() |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
93 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
94 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
95 | cx_attr_cstr_arg(3) |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1112
diff
changeset
|
96 | cx_attr_export |
635
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
97 | int cx_vfprintf( |
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
98 | void *stream, |
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
99 | cx_write_func wfc, |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
849
diff
changeset
|
100 | const char *fmt, |
635
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
101 | va_list ap |
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
102 | ); |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
105 | * A @c asprintf like function which allocates space for a string |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | * the result is written to. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
108 | * @note The resulting string is guaranteed to be zero-terminated, |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
109 | * unless there was an error, in which case the string's pointer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
110 | * will be @c NULL. |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | * |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | * @param allocator the CxAllocator used for allocating the string |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
113 | * @param fmt format string |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | * @param ... additional arguments |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | * @return the formatted string |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | * @see cx_strfree_a() |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
118 | cx_attr_nonnull_arg(1, 2) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
119 | cx_attr_printf(2, 3) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
120 | cx_attr_cstr_arg(2) |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1112
diff
changeset
|
121 | cx_attr_export |
635
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
122 | cxmutstr cx_asprintf_a( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
849
diff
changeset
|
123 | const CxAllocator *allocator, |
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
849
diff
changeset
|
124 | const char *fmt, |
635
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
125 | ... |
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
126 | ); |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
129 | * A @c asprintf like function which allocates space for a string |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
130 | * the result is written to. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
132 | * @note The resulting string is guaranteed to be zero-terminated, |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
133 | * unless there was an error, in which case the string's pointer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
134 | * will be @c NULL. |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
136 | * @param fmt (@c char*) format string |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
137 | * @param ... additional arguments |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
138 | * @return (@c cxmutstr) the formatted string |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
139 | * @see cx_strfree() |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | */ |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | #define cx_asprintf(fmt, ...) \ |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | cx_asprintf_a(cxDefaultAllocator, fmt, __VA_ARGS__) |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
143 | |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
145 | * A @c vasprintf like function which allocates space for a string |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | * the result is written to. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
147 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
148 | * @note The resulting string is guaranteed to be zero-terminated, |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
149 | * unless there was an error, in which case the string's pointer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
150 | * will be @c NULL. |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | * |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | * @param allocator the CxAllocator used for allocating the string |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | * @param fmt format string |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | * @param ap argument list |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
155 | * @return the formatted string |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | * @see cx_asprintf_a() |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
158 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
159 | cx_attr_cstr_arg(2) |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1112
diff
changeset
|
160 | cx_attr_export |
635
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
161 | cxmutstr cx_vasprintf_a( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
849
diff
changeset
|
162 | const CxAllocator *allocator, |
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
849
diff
changeset
|
163 | const char *fmt, |
635
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
164 | va_list ap |
d4845058239a
add attributes to printf functions
Mike Becker <universe@uap-core.de>
parents:
599
diff
changeset
|
165 | ); |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
166 | |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
168 | * A @c vasprintf like function which allocates space for a string |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | * the result is written to. |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
170 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
171 | * @note The resulting string is guaranteed to be zero-terminated, |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
172 | * unless there was in error, in which case the string's pointer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
173 | * will be @c NULL. |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
174 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
175 | * @param fmt (@c char*) format string |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
176 | * @param ap (@c va_list) argument list |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
177 | * @return (@c cxmutstr) the formatted string |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | * @see cx_asprintf() |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
179 | */ |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
180 | #define cx_vasprintf(fmt, ap) cx_vasprintf_a(cxDefaultAllocator, fmt, ap) |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
181 | |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
182 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
183 | * A @c printf like function which writes the output to a CxBuffer. |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
184 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
185 | * @param buffer (@c CxBuffer*) a pointer to the buffer the data is written to |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
186 | * @param fmt (@c char*) the format string |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
187 | * @param ... additional arguments |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
188 | * @return (@c int) the total number of bytes written or an error code from stdlib printf implementation |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
189 | * @see cx_fprintf() |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
190 | * @see cxBufferWrite() |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
191 | */ |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
192 | #define cx_bprintf(buffer, fmt, ...) cx_fprintf((void*)buffer, \ |
1112
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1105
diff
changeset
|
193 | cxBufferWriteFunc, fmt, __VA_ARGS__) |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
194 | |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
195 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
196 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
197 | * An @c sprintf like function which reallocates the string when the buffer is not large enough. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
198 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
199 | * The size of the buffer will be updated in @p len when necessary. |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
200 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
201 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
202 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
203 | * @param str (@c char**) a pointer to the string buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
204 | * @param len (@c size_t*) a pointer to the length of the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
205 | * @param fmt (@c char*) the format string |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
206 | * @param ... additional arguments |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
207 | * @return (@c int) the length of produced string or an error code from stdlib printf implementation |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
208 | */ |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
209 | #define cx_sprintf(str, len, fmt, ...) cx_sprintf_a(cxDefaultAllocator, str, len, fmt, __VA_ARGS__) |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
210 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
211 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
212 | * An @c sprintf like function which reallocates the string when the buffer is not large enough. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
213 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
214 | * The size of the buffer will be updated in @p len when necessary. |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
215 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
216 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
217 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
218 | * @attention The original buffer MUST have been allocated with the same allocator! |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
219 | * |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
220 | * @param alloc the allocator to use |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
221 | * @param str a pointer to the string buffer |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
222 | * @param len a pointer to the length of the buffer |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
223 | * @param fmt the format string |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
224 | * @param ... additional arguments |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
225 | * @return the length of produced string or an error code from stdlib printf implementation |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
226 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
227 | cx_attr_nonnull_arg(1, 2, 3, 4) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
228 | cx_attr_printf(4, 5) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
229 | cx_attr_cstr_arg(4) |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1112
diff
changeset
|
230 | cx_attr_export |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
231 | int cx_sprintf_a( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
232 | CxAllocator *alloc, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
233 | char **str, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
234 | size_t *len, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
235 | const char *fmt, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
236 | ... |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
237 | ); |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
238 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
239 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
240 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
241 | * An @c sprintf like function which reallocates the string when the buffer is not large enough. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
242 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
243 | * The size of the buffer will be updated in @p len when necessary. |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
244 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
245 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
246 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
247 | * @param str (@c char**) a pointer to the string buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
248 | * @param len (@c size_t*) a pointer to the length of the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
249 | * @param fmt (@c char*) the format string |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
250 | * @param ap (@c va_list) argument list |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
251 | * @return (@c int) the length of produced string or an error code from stdlib printf implementation |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
252 | */ |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
253 | #define cx_vsprintf(str, len, fmt, ap) cx_vsprintf_a(cxDefaultAllocator, str, len, fmt, ap) |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
254 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
255 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
256 | * An @c sprintf like function which reallocates the string when the buffer is not large enough. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
257 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
258 | * The size of the buffer will be updated in @p len when necessary. |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
259 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
260 | * @note The resulting string is guaranteed to be zero-terminated. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
261 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
262 | * @attention The original buffer MUST have been allocated with the same allocator! |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
263 | * |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
264 | * @param alloc the allocator to use |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
265 | * @param str a pointer to the string buffer |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
266 | * @param len a pointer to the length of the buffer |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
267 | * @param fmt the format string |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
268 | * @param ap argument list |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
269 | * @return the length of produced string or an error code from stdlib printf implementation |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
270 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
271 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
272 | cx_attr_cstr_arg(4) |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
273 | cx_attr_access_rw(2) |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
274 | cx_attr_access_rw(3) |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1112
diff
changeset
|
275 | cx_attr_export |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
276 | int cx_vsprintf_a( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
277 | CxAllocator *alloc, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
278 | char **str, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
279 | size_t *len, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
280 | const char *fmt, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
281 | va_list ap |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
282 | ); |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
283 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
284 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
285 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
286 | * An @c sprintf like function which allocates a new string when the buffer is not large enough. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
287 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
288 | * The size of the buffer will be updated in @p len when necessary. |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
289 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
290 | * The location of the resulting string will @em always be stored to @p str. When the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
291 | * was sufficiently large, @p buf itself will be stored to the location of @p str. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
292 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
293 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
294 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
295 | * @remark When a new string needed to be allocated, the contents of @p buf will be |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
296 | * poisoned after the call, because this function tries to produce the string in @p buf, first. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
297 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
298 | * @param buf (@c char*) a pointer to the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
299 | * @param len (@c size_t*) a pointer to the length of the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
300 | * @param str (@c char**) a pointer where the location of the result shall be stored |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
301 | * @param fmt (@c char*) the format string |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
302 | * @param ... additional arguments |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
303 | * @return (@c int) the length of produced string or an error code from stdlib printf implementation |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
304 | */ |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
305 | #define cx_sprintf_s(buf, len, str, fmt, ...) cx_sprintf_sa(cxDefaultAllocator, buf, len, str, fmt, __VA_ARGS__) |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
306 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
307 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
308 | * An @c sprintf like function which allocates a new string when the buffer is not large enough. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
309 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
310 | * The size of the buffer will be updated in @p len when necessary. |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
311 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
312 | * The location of the resulting string will @em always be stored to @p str. When the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
313 | * was sufficiently large, @p buf itself will be stored to the location of @p str. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
314 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
315 | * @note The resulting string, if successful, is guaranteed to be zero-terminated. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
316 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
317 | * @remark When a new string needed to be allocated, the contents of @p buf will be |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
318 | * poisoned after the call, because this function tries to produce the string in @p buf, first. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
319 | * |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
320 | * @param alloc the allocator to use |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
321 | * @param buf a pointer to the buffer |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
322 | * @param len a pointer to the length of the buffer |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
323 | * @param str a pointer where the location of the result shall be stored |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
324 | * @param fmt the format string |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
325 | * @param ... additional arguments |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
326 | * @return the length of produced string or an error code from stdlib printf implementation |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
327 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
328 | cx_attr_nonnull_arg(1, 2, 4, 5) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
329 | cx_attr_printf(5, 6) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
330 | cx_attr_cstr_arg(5) |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
331 | cx_attr_access_rw(2) |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
332 | cx_attr_access_rw(3) |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
333 | cx_attr_access_rw(4) |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1112
diff
changeset
|
334 | cx_attr_export |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
335 | int cx_sprintf_sa( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
336 | CxAllocator *alloc, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
337 | char *buf, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
338 | size_t *len, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
339 | char **str, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
340 | const char *fmt, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
341 | ... |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
342 | ); |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
343 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
344 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
345 | * An @c sprintf like function which allocates a new string when the buffer is not large enough. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
346 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
347 | * The size of the buffer will be updated in @p len when necessary. |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
348 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
349 | * The location of the resulting string will @em always be stored to @p str. When the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
350 | * was sufficiently large, @p buf itself will be stored to the location of @p str. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
351 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
352 | * @note The resulting string is guaranteed to be zero-terminated. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
353 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
354 | * @remark When a new string needed to be allocated, the contents of @p buf will be |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
355 | * poisoned after the call, because this function tries to produce the string in @p buf, first. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
356 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
357 | * @param buf (@c char*) a pointer to the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
358 | * @param len (@c size_t*) a pointer to the length of the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
359 | * @param str (@c char**) a pointer where the location of the result shall be stored |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
360 | * @param fmt (@c char*) the format string |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
361 | * @param ap (@c va_list) argument list |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
362 | * @return (@c int) the length of produced string or an error code from stdlib printf implementation |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
363 | */ |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
364 | #define cx_vsprintf_s(buf, len, str, fmt, ap) cx_vsprintf_sa(cxDefaultAllocator, buf, len, str, fmt, ap) |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
365 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
366 | /** |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
367 | * An @c sprintf like function which allocates a new string when the buffer is not large enough. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
368 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
369 | * The size of the buffer will be updated in @p len when necessary. |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
370 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
371 | * The location of the resulting string will @em always be stored to @p str. When the buffer |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
372 | * was sufficiently large, @p buf itself will be stored to the location of @p str. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
373 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
374 | * @note The resulting string is guaranteed to be zero-terminated. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
375 | * |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
376 | * @remark When a new string needed to be allocated, the contents of @p buf will be |
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
377 | * poisoned after the call, because this function tries to produce the string in @p buf, first. |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
378 | * |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
379 | * @param alloc the allocator to use |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
380 | * @param buf a pointer to the buffer |
849
edb9f875b7f9
improves interface of cx_sprintf() variants
Mike Becker <universe@uap-core.de>
parents:
810
diff
changeset
|
381 | * @param len a pointer to the length of the buffer |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
382 | * @param str a pointer where the location of the result shall be stored |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
383 | * @param fmt the format string |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
384 | * @param ap argument list |
1105
5c16dc362684
refine docs for printf.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
385 | * @return the length of produced string or an error code from stdlib printf implementation |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
386 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
387 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
388 | cx_attr_cstr_arg(5) |
1180
4c3a69b9723a
add support for building windows DLLs - resolves #582
Mike Becker <universe@uap-core.de>
parents:
1112
diff
changeset
|
389 | cx_attr_export |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
390 | int cx_vsprintf_sa( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
391 | CxAllocator *alloc, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
392 | char *buf, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
393 | size_t *len, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
394 | char **str, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
395 | const char *fmt, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
396 | va_list ap |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
926
diff
changeset
|
397 | ); |
810
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
398 | |
85859399a0cc
add cx_sprintf() variants - fixes #353
Mike Becker <universe@uap-core.de>
parents:
805
diff
changeset
|
399 | |
599
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
400 | #ifdef __cplusplus |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
401 | } // extern "C" |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
402 | #endif |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
403 | |
6536a9a75b71
#222 add printf-like functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
404 | #endif //UCX_PRINTF_H |