1 krisbash 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 krisbash 1.1 **==============================================================================
23 */
24
25 #ifndef _base_format_h
26 #define _base_format_h
27
28 #ifndef _MSC_VER
29 #include "config.h"
30 #if defined(CONFIG_OS_LINUX)
31 #ifndef _GNU_SOURCE
32 #define _GNU_SOURCE
33 #endif
34 #endif
35 #endif
36
37 #include <pal/palcommon.h>
38 #include <pal/format.placeholders.h>
39 #include <stdio.h>
40 #include <stdarg.h>
41
42
43 krisbash 1.1 #ifdef _PREFAST_
44 #pragma prefast(push)
45 #pragma prefast(disable:28252)
46 #pragma prefast(disable:28253)
47 #endif
48 #include <wchar.h>
49 #ifdef _PREFAST_
50 #pragma prefast(pop)
51 #endif
52
53 #if defined(CONFIG_ENABLE_WCHAR)
54 # define Tprintf Wprintf
55 # define Ftprintf Fwprintf
56 # define Stprintf Swprintf
57 # define Stprintf_CultureInvariant Swprintf_CultureInvariant
58 # define Stscanf_CultureInvariant Swscanf_CultureInvariant
59 # define Vtprintf Vwprintf
60 # define Vftprintf Vfwprintf
61 # define Vstprintf Vswprintf
62 # define Vstprintf_CultureInvariant Vswprintf_CultureInvariant
63 # define Vstscanf_CultureInvariant Vswscanf_CultureInvariant
64 krisbash 1.1 # define Tputc fwputc
65 #else
66 # define Tprintf Printf
67 # define Ftprintf Fprintf
68 # define Stprintf Snprintf
69 # define Stprintf_CultureInvariant Snprintf_CultureInvariant
70 # define Stscanf_CultureInvariant Sscanf_CultureInvariant
71 # define Vtprintf Vprintf
72 # define Vftprintf Vfprintf
73 # define Vstprintf Vsnprintf
74 # define Vstprintf_CultureInvariant Vsnprintf_CultureInvariant
75 # define Vstscanf_CultureInvariant Vsscanf_CultureInvariant
76 # define Tputc fputc
77 #endif
78
79 PAL_BEGIN_EXTERNC
80
81 /*
82 **==============================================================================
83 **
84 ** Wide-character versions:
85 krisbash 1.1 **
86 **==============================================================================
87 */
88
89 int Wprintf(
90 const wchar_t* format,
91 ...);
92
93 int Fwprintf(
94 FILE* os,
95 const wchar_t* format,
96 ...);
97
98 int Swprintf(
99 _Out_writes_z_(size) wchar_t* buffer,
100 _In_ size_t size,
101 _In_z_ const wchar_t* format,
102 ...);
103
104 int Swprintf_CultureInvariant(
105 _Out_writes_z_(size) wchar_t* buffer,
106 krisbash 1.1 _In_ size_t size,
107 _In_z_ const wchar_t* format,
108 ...);
109
110 int Vwprintf(
111 const wchar_t* format,
112 va_list ap);
113
114 int Vfwprintf(
115 FILE* os,
116 const wchar_t* format,
117 va_list ap);
118
119 int Vswprintf(
120 _Out_writes_z_(size) wchar_t* buffer,
121 _In_ size_t size,
122 _In_z_ const wchar_t* format,
123 va_list ap);
124
125 int Vswprintf_CultureInvariant(
126 _Out_writes_z_(size) wchar_t* buffer,
127 krisbash 1.1 _In_ size_t size,
128 _In_z_ const wchar_t* format,
129 va_list ap);
130
131 int Swscanf_CultureInvariant(
132 _In_z_ const wchar_t* buffer,
133 _In_z_ const wchar_t* format,
134 ...);
135
136 int Vswscanf_CultureInvariant(
137 _In_z_ const wchar_t* buffer,
138 _In_z_ const wchar_t* format,
139 va_list ap);
140
141 /*
142 **==============================================================================
143 **
144 ** single-character versions:
145 **
146 **==============================================================================
147 */
148 krisbash 1.1
149 int Printf(
150 const char* format,
151 ...);
152
153 int Fprintf(
154 FILE* os,
155 const char* format,
156 ...);
157
158 int Snprintf(
159 _Out_writes_z_(size) char* buffer,
160 _In_ size_t size,
161 _In_z_ const char* format,
162 ...);
163
164 int Snprintf_CultureInvariant(
165 _Out_writes_z_(size) char* buffer,
166 _In_ size_t size,
167 _In_z_ const char* format,
168 ...);
169 krisbash 1.1
170 int Vprintf(
171 const char* format,
172 va_list ap);
173
174 int Vfprintf(
175 FILE* os,
176 const char* format,
177 va_list ap);
178
179 int Vsnprintf(
180 _Out_writes_z_(size) char* buffer,
181 _In_ size_t size,
182 _In_z_ const char* format,
183 va_list ap);
184
185 int Vsnprintf_CultureInvariant(
186 _Out_writes_z_(size) char* buffer,
187 _In_ size_t size,
188 _In_z_ const char* format,
189 va_list ap);
190 krisbash 1.1
191 int Sscanf_CultureInvariant(
192 _In_z_ const char* buffer,
193 _In_z_ const char* format,
194 ...);
195
196 int Vsscanf_CultureInvariant(
197 _In_z_ const char* buffer,
198 _In_z_ const char* format,
199 va_list ap);
200
201 /*
202 **==============================================================================
203 **
204 ** These macros are used to type-check printf parameters. There are 3 functions:
205 **
206 ** scs - single-character string (use with %s)
207 ** wcs - wide-character string (use with %S)
208 ** tcs - z-character string (TChar) (use with %T)
209 **
210 ** Always use these to test the assumption about argument-format agreement.
211 krisbash 1.1 ** For example:
212 **
213 ** Tprintf(PAL_T("%T %S %s"), tcs(s1), wcs(s2), scs(s3));
214 **
215 **==============================================================================
216 */
217
218 PAL_INLINE const char* scs(const char* str) { return (NULL == str) ? "null" : str; }
219
220 PAL_INLINE const wchar_t* wcs(const wchar_t* str) { return (NULL == str) ? L"null" : str; }
221
222 PAL_INLINE const TChar* tcs(const TChar* str) { return (NULL == str) ?PAL_T("null") : str; }
223
224 /*
225 **==============================================================================
226 **
227 ** Helper function built-on top of the other formatting functions/macros above
228 **
229 **==============================================================================
230 */
231
232 krisbash 1.1 PAL_Char* Stprintf_StrDup(_In_z_ const PAL_Char* templateString, ...);
233 PAL_Char* Vstprintf_StrDup(_In_z_ const PAL_Char* templateString, va_list ap);
234
235 char* FixupFormat(
236 _Out_writes_z_(size) _Null_terminated_ char* buf,
237 _In_ size_t size,
238 _In_z_ const char* fmt);
239
240 wchar_t* WFixupFormat(
241 _Out_writes_z_(size) _Null_terminated_ wchar_t* buf,
242 _In_ size_t size,
243 _In_z_ const wchar_t* fmt);
244
245 PAL_END_EXTERNC
246
247 #endif /* _base_format_h */
|