xref: /reactos/sdk/include/ucrt/string.h (revision fe11f7a2)
1 //
2 // string.h
3 //
4 //      Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // The C Standard Library <string.h> header.
7 //
8 #pragma once
9 #ifndef _INC_STRING // include guard for 3rd party interop
10 #define _INC_STRING
11 
12 #include <corecrt.h>
13 #include <corecrt_memory.h>
14 #include <corecrt_wstring.h>
15 #include <vcruntime_string.h>
16 
17 #ifndef __midl
18 
19 #pragma warning(push)
20 #pragma warning(disable: _UCRT_DISABLED_WARNINGS)
21 _UCRT_DISABLE_CLANG_WARNINGS
22 
23 _CRT_BEGIN_C_HEADER
24 
25 
26 
27 #define _NLSCMPERROR _CRT_INT_MAX // currently == INT_MAX
28 
29 #if __STDC_WANT_SECURE_LIB__
30 
31     _Check_return_wat_
32     _ACRTIMP errno_t __cdecl strcpy_s(
33         _Out_writes_z_(_SizeInBytes) char*       _Destination,
34         _In_                         rsize_t     _SizeInBytes,
35         _In_z_                       char const* _Source
36         );
37 
38     _Check_return_wat_
39     _ACRTIMP errno_t __cdecl strcat_s(
40         _Inout_updates_z_(_SizeInBytes) char*       _Destination,
41         _In_                            rsize_t     _SizeInBytes,
42         _In_z_                          char const* _Source
43         );
44 
45     _Check_return_wat_
46     _ACRTIMP errno_t __cdecl strerror_s(
47         _Out_writes_z_(_SizeInBytes) char*  _Buffer,
48         _In_                         size_t _SizeInBytes,
49         _In_                         int    _ErrorNumber);
50 
51     _Check_return_wat_
52     _ACRTIMP errno_t __cdecl strncat_s(
53         _Inout_updates_z_(_SizeInBytes) char*       _Destination,
54         _In_                            rsize_t     _SizeInBytes,
55         _In_reads_or_z_(_MaxCount)      char const* _Source,
56         _In_                            rsize_t     _MaxCount
57         );
58 
59     _Check_return_wat_
60     _ACRTIMP errno_t __cdecl strncpy_s(
61         _Out_writes_z_(_SizeInBytes) char*       _Destination,
62         _In_                         rsize_t     _SizeInBytes,
63         _In_reads_or_z_(_MaxCount)   char const* _Source,
64         _In_                         rsize_t     _MaxCount
65         );
66 
67     _Check_return_
68     _ACRTIMP char*  __cdecl strtok_s(
69         _Inout_opt_z_                 char*       _String,
70         _In_z_                        char const* _Delimiter,
71         _Inout_ _Deref_prepost_opt_z_ char**      _Context
72         );
73 
74 #endif // __STDC_WANT_SECURE_LIB__
75 
76 _ACRTIMP void* __cdecl _memccpy(
77     _Out_writes_bytes_opt_(_MaxCount) void*       _Dst,
78     _In_                              void const* _Src,
79     _In_                              int         _Val,
80     _In_                              size_t      _MaxCount
81     );
82 
83 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(
84     errno_t, strcat_s,
85            char,        _Destination,
86     _In_z_ char const*, _Source
87     )
88 
89 #ifndef RC_INVOKED
90 
91     __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(
92         char*, __RETURN_POLICY_DST, __EMPTY_DECLSPEC, strcat,
93         _Inout_updates_z_(_String_length_(_Destination) + _String_length_(_Source) + 1), char,        _Destination,
94         _In_z_                                                                           char const*, _Source
95         )
96 
97 #endif // RC_INVOKED
98 
99 _Check_return_
100 int __cdecl strcmp(
101     _In_z_ char const* _Str1,
102     _In_z_ char const* _Str2
103     );
104 
105 _Check_return_
106 _ACRTIMP int __cdecl _strcmpi(
107     _In_z_ char const* _String1,
108     _In_z_ char const* _String2
109     );
110 
111 _Check_return_
112 _ACRTIMP int __cdecl strcoll(
113     _In_z_ char const* _String1,
114     _In_z_ char const* _String2
115     );
116 
117 _Check_return_
118 _ACRTIMP int __cdecl _strcoll_l(
119     _In_z_   char const* _String1,
120     _In_z_   char const* _String2,
121     _In_opt_ _locale_t   _Locale
122     );
123 
124 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(
125     errno_t, strcpy_s,
126     _Post_z_ char,        _Destination,
127     _In_z_   char const*, _Source
128     )
129 
130 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(
131     char*, __RETURN_POLICY_DST, __EMPTY_DECLSPEC, strcpy,
132     _Out_writes_z_(_String_length_(_Source) + 1), char,        _Destination,
133     _In_z_                                        char const*, _Source
134     )
135 
136 _Check_return_
137 _ACRTIMP size_t __cdecl strcspn(
138     _In_z_ char const* _Str,
139     _In_z_ char const* _Control
140     );
141 
142 #if defined _DEBUG && defined _CRTDBG_MAP_ALLOC
143     #pragma push_macro("_strdup")
144     #undef _strdup
145 #endif
146 
147 _Check_return_
148 _ACRTIMP _CRTALLOCATOR char* __cdecl _strdup(
149     _In_opt_z_ char const* _Source
150     );
151 
152 #if defined _DEBUG && defined _CRTDBG_MAP_ALLOC
153     #pragma pop_macro("_strdup")
154 #endif
155 
156 _Ret_z_
157 _Success_(return != 0)
158 _Check_return_ _CRT_INSECURE_DEPRECATE(_strerror_s)
159 _ACRTIMP char*  __cdecl _strerror(
160     _In_opt_z_ char const* _ErrorMessage
161     );
162 
163 _Check_return_wat_
164 _ACRTIMP errno_t __cdecl _strerror_s(
165     _Out_writes_z_(_SizeInBytes) char*       _Buffer,
166     _In_                         size_t      _SizeInBytes,
167     _In_opt_z_                   char const* _ErrorMessage
168     );
169 
170 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(
171     errno_t, _strerror_s,
172                char,        _Buffer,
173     _In_opt_z_ char const*, _ErrorMessage
174     )
175 
176 _Ret_z_
177 _Check_return_ _CRT_INSECURE_DEPRECATE(strerror_s)
178 _ACRTIMP char* __cdecl strerror(
179     _In_ int _ErrorMessage
180     );
181 
182 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(
183     errno_t, strerror_s,
184         char, _Buffer,
185     _In_ int, _ErrorMessage
186     )
187 
188 _Check_return_
189 _ACRTIMP int __cdecl _stricmp(
190     _In_z_ char const* _String1,
191     _In_z_ char const* _String2
192     );
193 
194 _Check_return_
195 _ACRTIMP int __cdecl _stricoll(
196     _In_z_ char const* _String1,
197     _In_z_ char const* _String2
198     );
199 
200 _Check_return_
201 _ACRTIMP int __cdecl _stricoll_l(
202     _In_z_   char const* _String1,
203     _In_z_   char const* _String2,
204     _In_opt_ _locale_t   _Locale
205     );
206 
207 _Check_return_
208 _ACRTIMP int __cdecl _stricmp_l(
209     _In_z_   char const* _String1,
210     _In_z_   char const* _String2,
211     _In_opt_ _locale_t   _Locale
212     );
213 
214 _Check_return_
215 size_t __cdecl strlen(
216     _In_z_ char const* _Str
217     );
218 
219 _Check_return_wat_
220 _ACRTIMP errno_t __cdecl _strlwr_s(
221     _Inout_updates_z_(_Size) char*  _String,
222     _In_                     size_t _Size
223     );
224 
225 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(
226     errno_t, _strlwr_s,
227     _Prepost_z_ char, _String
228     )
229 
230 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(
231     char*, __RETURN_POLICY_DST, _ACRTIMP, _strlwr,
232     _Inout_z_, char, _String
233     )
234 
235 _Check_return_wat_
236 _ACRTIMP errno_t __cdecl _strlwr_s_l(
237     _Inout_updates_z_(_Size) char*     _String,
238     _In_                     size_t    _Size,
239     _In_opt_                 _locale_t _Locale
240     );
241 
242 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(
243     errno_t, _strlwr_s_l,
244     _Prepost_z_ char,      _String,
245     _In_opt_    _locale_t, _Locale
246     )
247 
248 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(
249     char*, __RETURN_POLICY_DST, _ACRTIMP, _strlwr_l, _strlwr_s_l,
250     _Inout_updates_z_(_Size) char,
251     _Inout_z_,               char,      _String,
252     _In_opt_                 _locale_t, _Locale
253     )
254 
255 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(
256     errno_t, strncat_s,
257     _Prepost_z_             char,        _Destination,
258     _In_reads_or_z_(_Count) char const*, _Source,
259     _In_                    size_t,      _Count
260     )
261 
262 __DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(
263     char*, __RETURN_POLICY_DST, _ACRTIMP, strncat, strncat_s,
264     _Inout_updates_z_(_Size)   char,
265     _Inout_updates_z_(_Count), char,        _Destination,
266     _In_reads_or_z_(_Count)    char const*, _Source,
267     _In_                       size_t,      _Count
268     )
269 
270 _Check_return_
271 _ACRTIMP int __cdecl strncmp(
272     _In_reads_or_z_(_MaxCount) char const* _Str1,
273     _In_reads_or_z_(_MaxCount) char const* _Str2,
274     _In_                       size_t      _MaxCount
275     );
276 
277 _Check_return_
278 _ACRTIMP int __cdecl _strnicmp(
279     _In_reads_or_z_(_MaxCount) char const* _String1,
280     _In_reads_or_z_(_MaxCount) char const* _String2,
281     _In_                       size_t      _MaxCount
282     );
283 
284 _Check_return_
285 _ACRTIMP int __cdecl _strnicmp_l(
286     _In_reads_or_z_(_MaxCount) char const* _String1,
287     _In_reads_or_z_(_MaxCount) char const* _String2,
288     _In_                       size_t      _MaxCount,
289     _In_opt_                   _locale_t   _Locale
290     );
291 
292 _Check_return_
293 _ACRTIMP int __cdecl _strnicoll(
294     _In_reads_or_z_(_MaxCount) char const* _String1,
295     _In_reads_or_z_(_MaxCount) char const* _String2,
296     _In_                       size_t      _MaxCount
297     );
298 
299 _Check_return_
300 _ACRTIMP int __cdecl _strnicoll_l(
301     _In_reads_or_z_(_MaxCount) char const* _String1,
302     _In_reads_or_z_(_MaxCount) char const* _String2,
303     _In_                       size_t      _MaxCount,
304     _In_opt_                   _locale_t   _Locale
305     );
306 
307 _Check_return_
308 _ACRTIMP int __cdecl _strncoll(
309     _In_reads_or_z_(_MaxCount) char const* _String1,
310     _In_reads_or_z_(_MaxCount) char const* _String2,
311     _In_                       size_t      _MaxCount
312     );
313 
314 _Check_return_
315 _ACRTIMP int __cdecl _strncoll_l(
316     _In_reads_or_z_(_MaxCount) char const* _String1,
317     _In_reads_or_z_(_MaxCount) char const* _String2,
318     _In_                       size_t      _MaxCount,
319     _In_opt_                   _locale_t   _Locale
320     );
321 
322 _ACRTIMP size_t __cdecl __strncnt(
323     _In_reads_or_z_(_Count) char const* _String,
324     _In_                    size_t      _Count
325     );
326 
327 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(
328     errno_t, strncpy_s,
329                             char,        _Destination,
330     _In_reads_or_z_(_Count) char const*, _Source,
331     _In_                    size_t,      _Count
332     )
333 
334 __DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(
335     char*, __RETURN_POLICY_DST, _ACRTIMP, strncpy, strncpy_s,
336     _Out_writes_z_(_Size)               char,
337     _Out_writes_(_Count) _Post_maybez_, char,        _Destination,
338     _In_reads_or_z_(_Count)             char const*, _Source,
339     _In_                                size_t,      _Count
340     )
341 
342 _Check_return_
343 _When_(
344     _MaxCount > _String_length_(_String),
345     _Post_satisfies_(return == _String_length_(_String))
346 )
347 _When_(
348     _MaxCount <= _String_length_(_String),
349     _Post_satisfies_(return == _MaxCount)
350 )
351 _ACRTIMP size_t __cdecl strnlen(
352     _In_reads_or_z_(_MaxCount) char const* _String,
353     _In_                       size_t      _MaxCount
354     );
355 
356 #if __STDC_WANT_SECURE_LIB__ && !defined __midl
357 
358     _Check_return_
359     _When_(
360         _MaxCount > _String_length_(_String),
361         _Post_satisfies_(return == _String_length_(_String))
362     )
363     _When_(
364         _MaxCount <= _String_length_(_String),
365         _Post_satisfies_(return == _MaxCount)
366     )
367     static __inline size_t __CRTDECL strnlen_s(
368         _In_reads_or_z_(_MaxCount) char const* _String,
369         _In_                       size_t      _MaxCount
370         )
371     {
372         return _String == 0 ? 0 : strnlen(_String, _MaxCount);
373     }
374 
375 #endif
376 
377 _Check_return_wat_
378 _ACRTIMP errno_t __cdecl _strnset_s(
379     _Inout_updates_z_(_SizeInBytes) char*  _String,
380     _In_                            size_t _SizeInBytes,
381     _In_                            int    _Value,
382     _In_                            size_t _MaxCount
383     );
384 
385 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(
386     errno_t, _strnset_s,
387     _Prepost_z_ char,   _Destination,
388     _In_        int,    _Value,
389     _In_        size_t, _Count
390     )
391 
392 __DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(
393     char*, __RETURN_POLICY_DST, _ACRTIMP, _strnset, _strnset_s,
394     _Inout_updates_z_(_Size)   char,
395     _Inout_updates_z_(_Count), char,   _Destination,
396     _In_                       int,    _Value,
397     _In_                       size_t, _Count
398     )
399 
400 _Check_return_
401 _ACRTIMP char _CONST_RETURN* __cdecl strpbrk(
402     _In_z_ char const* _Str,
403     _In_z_ char const* _Control
404     );
405 
406 _ACRTIMP char* __cdecl _strrev(
407     _Inout_z_ char* _Str
408     );
409 
410 _Check_return_wat_
411 _ACRTIMP errno_t __cdecl _strset_s(
412     _Inout_updates_z_(_DestinationSize) char*  _Destination,
413     _In_                                size_t _DestinationSize,
414     _In_                                int    _Value
415     );
416 
417 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(
418     errno_t, _strset_s,
419     _Prepost_z_ char, _Destination,
420     _In_        int,  _Value
421     )
422 
423 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(
424     char*, __RETURN_POLICY_DST, __EMPTY_DECLSPEC, _strset,
425     _Inout_z_, char, _Destination,
426     _In_       int,  _Value
427     )
428 
429 _Check_return_
430 _ACRTIMP size_t __cdecl strspn(
431     _In_z_ char const* _Str,
432     _In_z_ char const* _Control
433     );
434 
435 _Check_return_ _CRT_INSECURE_DEPRECATE(strtok_s)
436 _ACRTIMP char* __cdecl strtok(
437     _Inout_opt_z_ char*       _String,
438     _In_z_        char const* _Delimiter
439     );
440 
441 _Check_return_wat_
442 _ACRTIMP errno_t __cdecl _strupr_s(
443     _Inout_updates_z_(_Size) char*  _String,
444     _In_                     size_t _Size
445     );
446 
447 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(
448     errno_t, _strupr_s,
449     _Prepost_z_ char, _String
450     )
451 
452 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(
453     char*, __RETURN_POLICY_DST, _ACRTIMP, _strupr,
454     _Inout_z_, char, _String
455     )
456 
457 _Check_return_wat_
458 _ACRTIMP errno_t __cdecl _strupr_s_l(
459     _Inout_updates_z_(_Size) char*     _String,
460     _In_                     size_t    _Size,
461     _In_opt_                 _locale_t _Locale
462     );
463 
464 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(
465     errno_t, _strupr_s_l,
466     _Prepost_z_ char,      _String,
467     _In_opt_    _locale_t, _Locale
468     )
469 
470 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(
471     char*, __RETURN_POLICY_DST, _ACRTIMP, _strupr_l, _strupr_s_l,
472     _Inout_updates_z_(_Size) char,
473     _Inout_z_,               char,      _String,
474     _In_opt_                 _locale_t, _Locale
475     )
476 
477 _Success_(return < _MaxCount)
478 _Check_return_opt_
479 _ACRTIMP size_t __cdecl strxfrm(
480     _Out_writes_opt_(_MaxCount) _Post_maybez_ char*       _Destination,
481     _In_z_                                    char const* _Source,
482     _In_ _In_range_(<=,_CRT_INT_MAX)          size_t      _MaxCount
483     );
484 
485 _Success_(return < _MaxCount)
486 _Check_return_opt_
487 _ACRTIMP size_t __cdecl _strxfrm_l(
488     _Out_writes_opt_(_MaxCount) _Post_maybez_ char*       _Destination,
489     _In_z_                                    char const* _Source,
490     _In_ _In_range_(<=,_CRT_INT_MAX)          size_t      _MaxCount,
491     _In_opt_                                  _locale_t   _Locale
492     );
493 
494 
495 
496 #ifdef __cplusplus
497 extern "C++"
498 {
499     _Check_return_
500     inline char* __CRTDECL strchr(_In_z_ char* const _String, _In_ int const _Ch)
501     {
502         return const_cast<char*>(strchr(static_cast<char const*>(_String), _Ch));
503     }
504 
505     _Check_return_
506     inline char* __CRTDECL strpbrk(_In_z_ char* const _String, _In_z_ char const* const _Control)
507     {
508         return const_cast<char*>(strpbrk(static_cast<char const*>(_String), _Control));
509     }
510 
511     _Check_return_
512     inline char* __CRTDECL strrchr(_In_z_ char* const _String, _In_ int const _Ch)
513     {
514         return const_cast<char*>(strrchr(static_cast<char const*>(_String), _Ch));
515     }
516 
517     _Check_return_ _Ret_maybenull_
518     inline char* __CRTDECL strstr(_In_z_ char* const _String, _In_z_ char const* const _SubString)
519     {
520         return const_cast<char*>(strstr(static_cast<char const*>(_String), _SubString));
521     }
522 }
523 #endif // __cplusplus
524 
525 
526 
527 #if defined(_CRT_INTERNAL_NONSTDC_NAMES) && _CRT_INTERNAL_NONSTDC_NAMES
528 
529     #pragma push_macro("strdup")
530     #undef strdup
531     _Check_return_ _CRT_NONSTDC_DEPRECATE(_strdup)
532     _ACRTIMP char* __cdecl strdup(
533         _In_opt_z_ char const* _String
534         );
535     #pragma pop_macro("strdup")
536 
537     // Declarations of functions defined in oldnames.lib:
538     _Check_return_ _CRT_NONSTDC_DEPRECATE(_strcmpi)
539     _ACRTIMP int __cdecl strcmpi(
540         _In_z_ char const* _String1,
541         _In_z_ char const* _String2
542         );
543 
544     _Check_return_ _CRT_NONSTDC_DEPRECATE(_stricmp)
545     _ACRTIMP int __cdecl stricmp(
546         _In_z_ char const* _String1,
547         _In_z_ char const* _String2
548         );
549 
550     _CRT_NONSTDC_DEPRECATE(_strlwr)
551     _ACRTIMP char* __cdecl strlwr(
552         _Inout_z_ char* _String
553         );
554 
555     _Check_return_ _CRT_NONSTDC_DEPRECATE(_strnicmp)
556     _ACRTIMP int __cdecl strnicmp(
557         _In_reads_or_z_(_MaxCount) char const* _String1,
558         _In_reads_or_z_(_MaxCount) char const* _String2,
559         _In_                       size_t      _MaxCount
560         );
561 
562     _CRT_NONSTDC_DEPRECATE(_strnset)
563     _ACRTIMP char* __cdecl strnset(
564         _Inout_updates_z_(_MaxCount) char*  _String,
565         _In_                         int    _Value,
566         _In_                         size_t _MaxCount
567         );
568 
569     _CRT_NONSTDC_DEPRECATE(_strrev)
570     _ACRTIMP char* __cdecl strrev(
571         _Inout_z_ char* _String
572         );
573 
574     _CRT_NONSTDC_DEPRECATE(_strset)
575     char* __cdecl strset(
576         _Inout_z_ char* _String,
577         _In_      int   _Value);
578 
579     _CRT_NONSTDC_DEPRECATE(_strupr)
580     _ACRTIMP char* __cdecl strupr(
581         _Inout_z_ char* _String
582         );
583 
584 #endif // _CRT_INTERNAL_NONSTDC_NAMES
585 
586 
587 
588 _CRT_END_C_HEADER
589 _UCRT_RESTORE_CLANG_WARNINGS
590 #pragma warning(pop) // _UCRT_DISABLED_WARNINGS
591 #endif // !__midl
592 #endif // _INC_STRING
593