1 mike 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 mike 1.1 **==============================================================================
23 */
24
25 #ifndef _base_strings_h
26 #define _base_strings_h
27
28 #include <common.h>
29 #include <wchar.h>
30 #include <string.h>
31
32 /* Maximum path length */
33 #define MAX_PATH_SIZE 1024
34
35 BEGIN_EXTERNC
36
37 MI_INLINE int Wcscmp(const wchar_t* s1, const wchar_t* s2)
38 {
39 return wcscmp(s1, s2);
40 }
41
42 MI_INLINE int Strcmp(const char* s1, const char* s2)
43 mike 1.1 {
44 return strcmp(s1, s2);
45 }
46
47 MI_INLINE int Zcmp(const MI_Char* s1, const MI_Char* s2)
48 {
49 #if (MI_CHAR_TYPE == 1)
50 return Strcmp(s1, s2);
51 #else
52 return Wcscmp(s1, s2);
53 #endif
54 }
55
56 MI_INLINE size_t Strlen(const char* str)
57 {
58 return strlen(str);
59 }
60
61 MI_INLINE size_t Wcslen(const wchar_t* str)
62 {
63 return wcslen(str);
64 mike 1.1 }
65
66 MI_INLINE size_t Zlen(const MI_Char* str)
67 {
68 #if (MI_CHAR_TYPE == 1)
69 return Strlen(str);
70 #else
71 return Wcslen(str);
72 #endif
73 }
74
75 MI_INLINE char* Strdup(const char* s)
76 {
77 #if defined(_MSC_VER)
78 return _strdup(s);
79 #else
80 return strdup(s);
81 #endif
82 }
83
84 #if (MI_CHAR_TYPE != 1)
85 mike 1.1 MI_INLINE wchar_t* Wcsdup(const wchar_t* s)
86 {
87 #if defined(_MSC_VER)
88 return _wcsdup(s);
89 #else
90 extern wchar_t* wcsdup(const wchar_t*);
91 return wcsdup(s);
92 #endif
93 }
94 #endif
95
96 MI_INLINE MI_Char* Zdup(const MI_Char* s)
97 {
98 #if (MI_CHAR_TYPE == 1)
99 return Strdup(s);
100 #else
101 return Wcsdup(s);
102 #endif
103 }
104
105 MI_INLINE int Strcasecmp(const char* s1, const char* s2)
106 mike 1.1 {
107 #if defined(_MSC_VER)
108 return _stricmp(s1, s2);
109 #else
110 return strcasecmp(s1, s2);
111 #endif
112 }
113
114 #if (MI_CHAR_TYPE != 1)
115 MI_INLINE int Wcscasecmp(const wchar_t* s1, const wchar_t* s2)
116 {
117 #if defined(_MSC_VER)
118 return _wcsicmp(s1, s2);
119 #else
120 # if defined(__GNUC__)
121 extern int wcscasecmp(const wchar_t*, const wchar_t*);
122 # endif
123 return wcscasecmp(s1, s2);
124 #endif
125 }
126 #endif
127 mike 1.1
128 MI_INLINE int Zcasecmp(const MI_Char* s1, const MI_Char* s2)
129 {
130 #if (MI_CHAR_TYPE == 1)
131 return Strcasecmp(s1, s2);
132 #else
133 return Wcscasecmp(s1, s2);
134 #endif
135 }
136
137 MI_INLINE int Strncasecmp(const char* s1, const char* s2, size_t n)
138 {
139 #if defined(_MSC_VER)
140 return _strnicmp(s1, s2, n);
141 #else
142 return strncasecmp(s1, s2, n);
143 #endif
144 }
145
146 #if (MI_CHAR_TYPE != 1)
147 MI_INLINE int Wcsncasecmp(const wchar_t* s1, const wchar_t* s2, size_t n)
148 mike 1.1 {
149 #if defined(_MSC_VER)
150 return _wcsnicmp(s1, s2, n);
151 #else
152 # if defined(__GNUC__)
153 extern int wcsncasecmp(const wchar_t*, const wchar_t*, size_t n);
154 # endif
155 return wcsncasecmp(s1, s2, n);
156 #endif
157 }
158 #endif
159
160 MI_INLINE int Zncasecmp(const MI_Char* s1, const MI_Char* s2, size_t n)
161 {
162 #if (MI_CHAR_TYPE == 1)
163 return Strncasecmp(s1, s2, n);
164 #else
165 return Wcsncasecmp(s1, s2, n);
166 #endif
167 }
168
169 mike 1.1 MI_INLINE unsigned long Strtoul(const char* str, char** end, int base)
170 {
171 return strtoul(str, end, base);
172 }
173
174 #if (MI_CHAR_TYPE != 1)
175 MI_INLINE unsigned long Wcstoul(const wchar_t* str, wchar_t** end, int base)
176 {
177 return wcstoul(str, end, base);
178 }
179 #endif
180
181 MI_INLINE unsigned long Ztoul(const MI_Char* str, MI_Char** end, int base)
182 {
183 #if (MI_CHAR_TYPE == 1)
184 return Strtoul(str, end, base);
185 #else
186 return Wcstoul(str, end, base);
187 #endif
188 }
189
190 mike 1.1 MI_INLINE long Strtol(const char* str, char** end, int base)
191 {
192 return strtol(str, end, base);
193 }
194
195 #if (MI_CHAR_TYPE != 1)
196 MI_INLINE long Wcstol(const wchar_t* str, wchar_t** end, int base)
197 {
198 return wcstol(str, end, base);
199 }
200 #endif
201
202 MI_INLINE long Ztol(const MI_Char* str, MI_Char** end, int base)
203 {
204 #if (MI_CHAR_TYPE == 1)
205 return Strtol(str, end, base);
206 #else
207 return Wcstol(str, end, base);
208 #endif
209 }
210
211 mike 1.1 MI_INLINE MI_Uint64 Strtoull(const char* str, char** end, int base)
212 {
213 #if defined(_MSC_VER)
214 return _strtoui64(str, end, base);
215 #else
216 return strtoull(str, end, base);
217 #endif
218 }
219
220 #if (MI_CHAR_TYPE != 1)
221 MI_INLINE MI_Uint64 Wcstoull(const wchar_t* str, wchar_t** end, int base)
222 {
223 #if defined(_MSC_VER)
224 return _wcstoui64(str, end, base);
225 #else
226 extern unsigned long long wcstoull(const wchar_t* s, wchar_t** e, int b);
227 return wcstoull(str, end, base);
228 #endif
229 }
230 #endif
231
232 mike 1.1 MI_INLINE MI_Uint64 Ztoull(const MI_Char* str, MI_Char** end, int base)
233 {
234 #if (MI_CHAR_TYPE == 1)
235 return Strtoull(str, end, base);
236 #else
237 return Wcstoull(str, end, base);
238 #endif
239 }
240
241 /*BOOKMARK*/
242 MI_INLINE MI_Sint64 Strtoll(const char* str, char** end, int base)
243 {
244 #if defined(_MSC_VER)
245 return _strtoi64(str, end, base);
246 #else
247 return strtoll(str, end, base);
248 #endif
249 }
250
251 #if (MI_CHAR_TYPE != 1)
252 MI_INLINE MI_Sint64 Wcstoll(const wchar_t* str, wchar_t** end, int base)
253 mike 1.1 {
254 #if defined(_MSC_VER)
255 return _wcstoi64(str, end, base);
256 #else
257 extern long long wcstoll(const wchar_t* s, wchar_t** e, int b);
258 return wcstoll(str, end, base);
259 #endif
260 }
261 #endif
262
263 MI_INLINE MI_Sint64 Ztoll(const MI_Char* str, MI_Char** end, int base)
264 {
265 #if (MI_CHAR_TYPE == 1)
266 return Strtoll(str, end, base);
267 #else
268 return Wcstoll(str, end, base);
269 #endif
270 }
271
272 MI_INLINE double Strtod(const char* str, char** end)
273 {
274 mike 1.1 return strtod(str, end);
275 }
276
277 MI_INLINE double Wcstod(const wchar_t* str, wchar_t** end)
278 {
279 return wcstod(str, end);
280 }
281
282 MI_INLINE double Ztod(const MI_Char* str, MI_Char** end)
283 {
284 #if (MI_CHAR_TYPE == 1)
285 return Strtod(str, end);
286 #else
287 return Wcstod(str, end);
288 #endif
289 }
290
291 MI_INLINE char* Strcat(char* dest, size_t count, const char* src)
292 {
293 #if defined(_MSC_VER)
294 strcat_s(dest, count, src);
295 mike 1.1 return dest;
296 #else
297 return strcat(dest, src);
298 #endif
299 }
300
301 MI_INLINE char* Strtok(char* str, const char* delim, char** context)
302 {
303 #if defined(_MSC_VER)
304 return strtok_s(str, delim, context);
305 #else
306 return strtok_r(str, delim, context);
307 #endif
308 }
309
310 size_t Strlcat(char* dest, const char* src, size_t size);
311
312 size_t Strlcpy(char* dest, const char* src, size_t size);
313
314 size_t ZStrlcat(MI_Char* dest, const char* src, size_t size);
315
316 mike 1.1 size_t ZStrlcpy(MI_Char* dest, const char* src, size_t size);
317
318 size_t Zlcat(MI_Char* dest, const MI_Char* src, size_t size);
319
320 size_t Zlcpy(MI_Char* dest, const MI_Char* src, size_t size);
321
322 const char* Uint32ToStr(char buf[12], MI_Uint32 x, size_t* size);
323
324 const char* Uint64ToStr(char buf[12], MI_Uint64 x, size_t* size);
325
326 #if (MI_CHAR_TYPE == 1)
327 INLINE const MI_Char* Uint32ToZStr(MI_Char buf[11], MI_Uint32 x, size_t* size)
328 {
329 return Uint32ToStr(buf, x, size);
330 }
331 INLINE const MI_Char* Uint64ToZStr(MI_Char buf[21], MI_Uint64 x, size_t* size)
332 {
333 return Uint64ToStr(buf, x, size);
334 }
335 #else
336 const MI_Char* Uint32ToZStr(MI_Char buf[12], MI_Uint32 x, size_t* size);
337 mike 1.1 const MI_Char* Uint64ToZStr(MI_Char buf[12], MI_Uint64 x, size_t* size);
338 #endif
339
340 END_EXTERNC
341
342 #endif /* _base_strings_h */
|