]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/stdlib.h
Changes so that Argv points to narrow-character versions of the command-line arguments.
[mirror_edk2.git] / StdLib / Include / stdlib.h
CommitLineData
2aa62f2b 1/** @file\r
2 The header <stdlib.h> declares five types and several functions of general\r
3 utility, and defines several macros.\r
4\r
53e1e5c6 5 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
2aa62f2b 6 This program and the accompanying materials are licensed and made available under\r
7 the terms and conditions of the BSD License that accompanies this distribution.\r
8 The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15#ifndef _STDLIB_H\r
16#define _STDLIB_H\r
17#include <sys/EfiCdefs.h>\r
18\r
19#ifdef _EFI_SIZE_T_\r
20 typedef _EFI_SIZE_T_ size_t;\r
21 #undef _EFI_SIZE_T_\r
22 #undef _BSD_SIZE_T_\r
23#endif\r
24\r
25#ifndef __cplusplus\r
26 #ifdef _EFI_WCHAR_T\r
27 typedef _EFI_WCHAR_T wchar_t;\r
28 #undef _EFI_WCHAR_T\r
29 #undef _BSD_WCHAR_T_\r
30 #endif\r
31#endif\r
32\r
33/// A structure type that is the type of the value returned by the div function.\r
34typedef struct {\r
35 int quot; /* quotient */\r
36 int rem; /* remainder */\r
37} div_t;\r
38\r
39/// A structure type that is the type of the value returned by the ldiv function.\r
40typedef struct {\r
41 long quot;\r
42 long rem;\r
43} ldiv_t;\r
44\r
45/// A structure type that is the type of the value returned by the lldiv function.\r
46typedef struct {\r
47 long long quot;\r
48 long long rem;\r
49} lldiv_t;\r
50\r
51/** Expand to integer constant expressions that can be used as the argument to\r
52 the exit function to return unsuccessful or successful termination status,\r
53 respectively, to the host environment.\r
54**/\r
55#define EXIT_FAILURE 1\r
56#define EXIT_SUCCESS 0\r
57\r
58/** Expands to an integer constant expression that is the maximum value\r
59 returned by the rand function.\r
60\r
61 The value of the RAND_MAX macro shall be at least 32767.\r
62**/\r
63#define RAND_MAX 0x7fffffff\r
64\r
65/** Expands to a positive integer expression with type size_t that is the\r
66 maximum number of bytes in a multibyte character for the extended character\r
67 set specified by the current locale (category LC_CTYPE), which is never\r
68 greater than MB_LEN_MAX.\r
69**/\r
70#define MB_CUR_MAX 2\r
71\r
72/** Maximum number of functions that can be registered by atexit.\r
73\r
74 The C standard states that the implementation shall support the\r
75 registration of at least 32 functions.\r
76**/\r
77#define ATEXIT_MAX 32\r
78\r
79__BEGIN_DECLS\r
80\r
81/* ################ Communication with the environment ################## */\r
82\r
83/** The abort function causes abnormal program termination to occur, unless\r
84 the signal SIGABRT is being caught and the signal handler does not return.\r
85\r
86 Open streams with unwritten buffered data are not flushed, open\r
87 streams are not closed, and temporary files are not removed by abort.\r
88\r
89 Unsuccessful termination is returned to the host environment by means of\r
90 the function call, raise(SIGABRT).\r
91\r
92 @sa signal.h\r
93**/\r
94void abort(void);\r
95\r
96/** The atexit function registers the function pointed to by func, to be\r
97 called without arguments at normal program termination.\r
98\r
99 The implementation supports the registration of up to 32 functions.\r
100\r
101 @return The atexit function returns zero if the registration succeeds,\r
102 nonzero if it fails.\r
103**/\r
104int atexit(void (*)(void));\r
105\r
106/** The exit function causes normal program termination to occur. If more than\r
107 one call to the exit function is executed by a program,\r
108 the behavior is undefined.\r
109\r
110 First, all functions registered by the atexit function are called, in the\r
111 reverse order of their registration, except that a function is called\r
112 after any previously registered functions that had already been called at\r
113 the time it was registered. If, during the call to any such function, a\r
114 call to the longjmp function is made that would terminate the call to the\r
115 registered function, the behavior is undefined.\r
116\r
117 Next, all open streams with unwritten buffered data are flushed, all open\r
118 streams are closed, and all files created by the tmpfile function\r
119 are removed.\r
120\r
121 Finally, control is returned to the host environment. If the value of\r
122 status is zero, or EXIT_SUCCESS, status is returned unchanged. If the value\r
123 of status is EXIT_FAILURE, EAPPLICATION is returned.\r
124 Otherwise, status is returned unchanged.\r
125**/\r
126void exit(int status) __noreturn;\r
127\r
128/** The _Exit function causes normal program termination to occur and control\r
129 to be returned to the host environment.\r
130\r
131 No functions registered by the atexit function or signal handlers\r
132 registered by the signal function are called. Open streams with unwritten\r
133 buffered data are not flushed, open streams are not closed, and temporary\r
134 files are not removed by abort.\r
135\r
53e1e5c6 136 While this function does not return, it can NOT be marked as "__noreturn"\r
137 without causing a warning to be emitted because the compilers can not\r
138 determine that the function truly does not return.\r
139\r
2aa62f2b 140 The status returned to the host environment is determined in the same way\r
141 as for the exit function.\r
142**/\r
53e1e5c6 143void _Exit(int status);\r
2aa62f2b 144\r
145/** The getenv function searches an environment list, provided by the host\r
146 environment, for a string that matches the string pointed to by name. The\r
147 set of environment names and the method for altering the environment list\r
148 are determined by the underlying UEFI Shell implementation.\r
149\r
150 @return The getenv function returns a pointer to a string associated with\r
151 the matched list member. The string pointed to shall not be\r
152 modified by the program, but may be overwritten by a subsequent\r
153 call to the getenv function. If the specified name cannot be\r
154 found, a null pointer is returned.\r
155**/\r
156char *getenv(const char *name);\r
157\r
53e1e5c6 158/**\r
159 Add or update a variable in the environment list\r
160\r
161 @param name Address of a zero terminated name string\r
162 @param value Address of a zero terminated value string\r
163 @param rewrite TRUE allows overwriting existing values\r
164\r
165 @retval Returns 0 upon success\r
166 @retval Returns -1 upon failure, sets errno with more information\r
167\r
168**/\r
169int\r
170setenv (\r
171 register const char * name,\r
172 register const char * value,\r
173 int rewrite\r
174 );\r
175\r
2aa62f2b 176/** If string is a null pointer, the system function determines whether the\r
177 host environment has a command processor. If string is not a null pointer,\r
178 the system function passes the string pointed to by string to that command\r
179 processor to be executed in a manner which the implementation shall\r
180 document; this might then cause the program calling system to behave in a\r
181 non-conforming manner or to terminate.\r
182\r
183 @return If the argument is a null pointer, the system function returns\r
184 nonzero only if a command processor is available. If the argument\r
185 is not a null pointer, and the system function does return, it\r
186 returns an implementation-defined value.\r
187**/\r
188int system(const char *string);\r
189\r
190\r
191/* ################ Integer arithmetic functions ######################## */\r
192\r
193/** Computes the absolute value of an integer j.\r
194\r
195 @return The absolute value of j.\r
196**/\r
197int abs(int j);\r
198\r
199/** Computes the absolute value of an integer j.\r
200\r
201 @return The absolute value of j.\r
202**/\r
203long labs(long j);\r
204\r
205/** Computes the absolute value of an integer j.\r
206\r
207 @return The absolute value of j.\r
208**/\r
209long long\r
210 llabs(long long j);\r
211\r
212/** Computes numer / denom and numer % denom in a single operation.\r
213\r
214 @return Returns a structure of type div_t, comprising both the\r
215 quotient and the remainder.\r
216**/\r
217div_t div(int numer, int denom);\r
218\r
219/** Computes numer / denom and numer % denom in a single operation.\r
220\r
221 @return Returns a structure of type ldiv_t, comprising both the\r
222 quotient and the remainder.\r
223**/\r
224ldiv_t ldiv(long numer, long denom);\r
225\r
226/** Computes numer / denom and numer % denom in a single operation.\r
227\r
228 @return Returns a structure of type lldiv_t, comprising both the\r
229 quotient and the remainder.\r
230**/\r
231lldiv_t lldiv(long long numer, long long denom);\r
232\r
233/* ############ Integer Numeric conversion functions #################### */\r
234\r
235/** The atoi function converts the initial portion of the string pointed to by\r
236 nptr to int representation. Except for the behavior on error, it is\r
237 equivalent to:\r
238 - atoi: (int)strtol(nptr, (char **)NULL, 10)\r
239\r
240 @return The atoi function returns the converted value.\r
241**/\r
242int atoi(const char *nptr);\r
243\r
244/** The atol function converts the initial portion of the string pointed to by\r
245 nptr to long int representation. Except for the behavior on error, it is\r
246 equivalent to:\r
247 - atol: strtol(nptr, (char **)NULL, 10)\r
248\r
249 @return The atol function returns the converted value.\r
250**/\r
251long atol(const char *nptr);\r
252\r
253/** The atoll function converts the initial portion of the string pointed to by\r
254 nptr to long long int representation. Except for the behavior on error, it\r
255 is equivalent to:\r
256 - atoll: strtoll(nptr, (char **)NULL, 10)\r
257\r
258 @return The atoll function returns the converted value.\r
259**/\r
260long long\r
261 atoll(const char *nptr);\r
262\r
263/** The strtol, strtoll, strtoul, and strtoull functions convert the initial\r
264 portion of the string pointed to by nptr to long int, long long int,\r
265 unsigned long int, and unsigned long long int representation, respectively.\r
266 First, they decompose the input string into three parts: an initial,\r
267 possibly empty, sequence of white-space characters (as specified by the\r
268 isspace function), a subject sequence resembling an integer represented in\r
269 some radix determined by the value of base, and a final string of one or\r
270 more unrecognized characters, including the terminating null character of\r
271 the input string. Then, they attempt to convert the subject sequence to an\r
272 integer, and return the result.\r
273\r
274 If the value of base is zero, the expected form of the subject sequence is\r
275 that of an integer constant as described in 6.4.4.1, optionally preceded\r
276 by a plus or minus sign, but not including an integer suffix. If the value\r
277 of base is between 2 and 36 (inclusive), the expected form of the subject\r
278 sequence is a sequence of letters and digits representing an integer with\r
279 the radix specified by base, optionally preceded by a plus or minus sign,\r
280 but not including an integer suffix. The letters from a (or A) through z\r
281 (or Z) are ascribed the values 10 through 35; only letters and digits whose\r
282 ascribed values are less than that of base are permitted. If the value of\r
283 base is 16, the characters 0x or 0X may optionally precede the sequence of\r
284 letters and digits, following the sign if present.\r
285\r
286 The subject sequence is defined as the longest initial subsequence of the\r
287 input string, starting with the first non-white-space character, that is of\r
288 the expected form. The subject sequence contains no characters if the input\r
289 string is empty or consists entirely of white space, or if the first\r
290 non-white-space character is other than a sign or a permissible letter or digit.\r
291\r
292 If the subject sequence has the expected form and the value of base is\r
293 zero, the sequence of characters starting with the first digit is\r
294 interpreted as an integer constant. If the subject sequence has the\r
295 expected form and the value of base is between 2 and 36, it is used as the\r
296 base for conversion, ascribing to each letter its value as given above. If\r
297 the subject sequence begins with a minus sign, the value resulting from the\r
298 conversion is negated (in the return type). A pointer to the final string\r
299 is stored in the object pointed to by endptr, provided that endptr is\r
300 not a null pointer.\r
301\r
302 In other than the "C" locale, additional locale-specific subject sequence\r
303 forms may be accepted.\r
304\r
305 If the subject sequence is empty or does not have the expected form, no\r
306 conversion is performed; the value of nptr is stored in the object pointed\r
307 to by endptr, provided that endptr is not a null pointer.\r
308\r
309 @return The strtol, strtoll, strtoul, and strtoull functions return the\r
310 converted value, if any. If no conversion could be performed, zero\r
311 is returned. If the correct value is outside the range of\r
312 representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX,\r
313 ULONG_MAX, or ULLONG_MAX is returned (according to the return type\r
314 and sign of the value, if any), and the value of the macro ERANGE\r
315 is stored in errno.\r
316**/\r
317long strtol(const char * __restrict nptr, char ** __restrict endptr, int base);\r
318\r
319/** The strtoul function converts the initial portion of the string pointed to\r
320 by nptr to unsigned long int representation.\r
321\r
322 See the description for strtol for more information.\r
323\r
324 @return The strtoul function returns the converted value, if any. If no\r
325 conversion could be performed, zero is returned. If the correct\r
326 value is outside the range of representable values, ULONG_MAX is\r
327 returned and the value of the macro ERANGE is stored in errno.\r
328**/\r
329unsigned long\r
330 strtoul(const char * __restrict nptr, char ** __restrict endptr, int base);\r
331\r
332/** The strtoll function converts the initial portion of the string pointed to\r
333 by nptr to long long int representation.\r
334\r
335 See the description for strtol for more information.\r
336\r
337 @return The strtoll function returns the converted value, if any. If no\r
338 conversion could be performed, zero is returned. If the correct\r
339 value is outside the range of representable values, LLONG_MIN or\r
340 LLONG_MAX is returned (according to the sign of the value, if any),\r
341 and the value of the macro ERANGE is stored in errno.\r
342**/\r
343long long\r
344 strtoll(const char * __restrict nptr, char ** __restrict endptr, int base);\r
345\r
346/** The strtoull function converts the initial portion of the string pointed to\r
347 by nptr to unsigned long long int representation.\r
348\r
349 See the description for strtol for more information.\r
350\r
351 @return The strtoull function returns the converted value, if any. If no\r
352 conversion could be performed, zero is returned. If the correct\r
353 value is outside the range of representable values, ULLONG_MAX is\r
354 returned and the value of the macro ERANGE is stored in errno.\r
355**/\r
356unsigned long long\r
357 strtoull(const char * __restrict nptr, char ** __restrict endptr, int base);\r
358\r
359/* ######### Floating-point Numeric conversion functions ################ */\r
360\r
361/**\r
362\r
363 @return\r
364**/\r
365double atof(const char *);\r
366\r
367/**\r
368\r
369 @return\r
370**/\r
371double strtod(const char * __restrict nptr, char ** __restrict endptr);\r
372\r
373/**\r
374\r
375 @return\r
376**/\r
377float strtof(const char * __restrict nptr, char ** __restrict endptr);\r
378\r
379/**\r
380\r
381 @return\r
382**/\r
383long double\r
384 strtold(const char * __restrict nptr, char ** __restrict endptr);\r
385\r
386/* ################ Pseudo-random sequence generation functions ######### */\r
387\r
388/** The rand function computes a sequence of pseudo-random integers in the\r
389 range 0 to RAND_MAX.\r
390\r
391 @return The rand function returns a pseudo-random integer.\r
392**/\r
393int rand(void);\r
394\r
395/** The srand function uses the argument as a seed for a new sequence of\r
396 pseudo-random numbers to be returned by subsequent calls to rand.\r
397\r
398 If srand is then called with the same seed value, the sequence of\r
399 pseudo-random numbers shall be repeated. If rand is called before any calls\r
400 to srand have been made, the same sequence shall be generated as when srand\r
401 is first called with a seed value of 1.\r
402**/\r
403void srand(unsigned seed);\r
404\r
405/* ################ Memory management functions ######################### */\r
406\r
407/** The calloc function allocates space for an array of Num objects, each of\r
408 whose size is Size. The space is initialized to all bits zero.\r
409\r
410 @return NULL is returned if the space could not be allocated and errno\r
411 contains the cause. Otherwise, a pointer to an 8-byte aligned\r
412 region of the requested size is returned.\r
413**/\r
414void *calloc(size_t Num, size_t Size);\r
415\r
416/** The free function causes the space pointed to by Ptr to be deallocated,\r
417 that is, made available for further allocation.\r
418\r
419 If Ptr is a null pointer, no action occurs. Otherwise, if the argument\r
420 does not match a pointer earlier returned by the calloc, malloc, or realloc\r
421 function, or if the space has been deallocated by a call to free or\r
422 realloc, the behavior is undefined.\r
423\r
424 @param Ptr Pointer to a previously allocated region of memory to be freed.\r
425\r
426**/\r
427void free(void *);\r
428\r
429/** The malloc function allocates space for an object whose size is specified\r
430 by size and whose value is indeterminate.\r
431\r
432 This implementation uses the UEFI memory allocation boot services to get a\r
433 region of memory that is 8-byte aligned and of the specified size. The\r
434 region is allocated with type EfiLoaderData.\r
435\r
436 @param size Size, in bytes, of the region to allocate.\r
437\r
438 @return NULL is returned if the space could not be allocated and errno\r
439 contains the cause. Otherwise, a pointer to an 8-byte aligned\r
440 region of the requested size is returned.<BR>\r
441 If NULL is returned, errno may contain:\r
442 - EINVAL: Requested Size is zero.\r
443 - ENOMEM: Memory could not be allocated.\r
444**/\r
445void *malloc(size_t);\r
446\r
447/** The realloc function changes the size of the object pointed to by Ptr to\r
448 the size specified by NewSize.\r
449\r
450 The contents of the object are unchanged up to the lesser of the new and\r
451 old sizes. If the new size is larger, the value of the newly allocated\r
452 portion of the object is indeterminate.\r
453\r
454 If Ptr is a null pointer, the realloc function behaves like the malloc\r
455 function for the specified size.\r
456\r
457 If Ptr does not match a pointer earlier returned by the calloc, malloc, or\r
458 realloc function, or if the space has been deallocated by a call to the free\r
459 or realloc function, the behavior is undefined.\r
460\r
461 If the space cannot be allocated, the object pointed to by Ptr is unchanged.\r
462\r
463 If NewSize is zero and Ptr is not a null pointer, the object it points to\r
464 is freed.\r
465\r
466 This implementation uses the UEFI memory allocation boot services to get a\r
467 region of memory that is 8-byte aligned and of the specified size. The\r
468 region is allocated with type EfiLoaderData.\r
469\r
470 @param Ptr Pointer to a previously allocated region of memory to be resized.\r
471 @param NewSize Size, in bytes, of the new object to allocate space for.\r
472\r
473 @return NULL is returned if the space could not be allocated and errno\r
474 contains the cause. Otherwise, a pointer to an 8-byte aligned\r
475 region of the requested size is returned. If NewSize is zero,\r
476 NULL is returned and errno will be unchanged.\r
477**/\r
478void *realloc(void *Ptr, size_t NewSize);\r
479\r
480/* ################ Searching and Sorting utilities ##################### */\r
481\r
482/** The bsearch function searches an array of nmemb objects, the initial\r
483 element of which is pointed to by base, for an element that matches the\r
484 object pointed to by key. The size of each element of the array is\r
485 specified by size.\r
486\r
487 The comparison function pointed to by compar is called with two arguments\r
488 that point to the key object and to an array element, in that order. The\r
489 function returns an integer less than, equal to, or greater than zero if\r
490 the key object is considered, respectively, to be less than, to match, or\r
491 to be greater than the array element. The array consists of: all the\r
492 elements that compare less than, all the elements that compare equal to,\r
493 and all the elements that compare greater than the key object,\r
494 in that order.\r
495\r
496 @return The bsearch function returns a pointer to a matching element of the\r
497 array, or a null pointer if no match is found. If two elements\r
498 compare as equal, which element is matched is unspecified.\r
499**/\r
500void *\r
501bsearch( const void *key, const void *base0,\r
502 size_t nmemb, size_t size,\r
503 int (*compar)(const void *, const void *)\r
504);\r
505\r
506/** The qsort function sorts an array of nmemb objects, the initial element of\r
507 which is pointed to by base. The size of each object is specified by size.\r
508\r
509 The contents of the array are sorted into ascending order according to a\r
510 comparison function pointed to by compar, which is called with two\r
511 arguments that point to the objects being compared. The function shall\r
512 return an integer less than, equal to, or greater than zero if the first\r
513 argument is considered to be respectively less than, equal to, or greater\r
514 than the second.\r
515\r
516 If two elements compare as equal, their order in the resulting sorted array\r
517 is unspecified.\r
518**/\r
519void qsort( void *base, size_t nmemb, size_t size,\r
520 int (*compar)(const void *, const void *));\r
521\r
522/* ################ Multibyte/wide character conversion functions ####### */\r
523\r
53e1e5c6 524/** Determine the number of bytes comprising a multibyte character.\r
2aa62f2b 525\r
53e1e5c6 526 If s is not a null pointer, the mblen function determines the number of bytes\r
527 contained in the multibyte character pointed to by s. Except that the\r
528 conversion state of the mbtowc function is not affected, it is equivalent to\r
529 mbtowc((wchar_t *)0, s, n);\r
530\r
531 The implementation shall behave as if no library function calls the mblen\r
532 function.\r
533\r
534 @return If s is a null pointer, the mblen function returns a nonzero or\r
535 zero value, if multibyte character encodings, respectively, do\r
536 or do not have state-dependent encodings. If s is not a null\r
537 pointer, the mblen function either returns 0 (if s points to the\r
538 null character), or returns the number of bytes that are contained\r
539 in the multibyte character (if the next n or fewer bytes form a\r
540 valid multibyte character), or returns -1 (if they do not form a\r
541 valid multibyte character).\r
2aa62f2b 542**/\r
543int mblen(const char *, size_t);\r
544\r
53e1e5c6 545/** Convert a multibyte character into a wide character.\r
2aa62f2b 546\r
53e1e5c6 547 If s is not a null pointer, the mbtowc function inspects at most n bytes\r
548 beginning with the byte pointed to by s to determine the number of bytes\r
549 needed to complete the next multibyte character (including any shift\r
550 sequences). If the function determines that the next multibyte character\r
551 is complete and valid, it determines the value of the corresponding wide\r
552 character and then, if pwc is not a null pointer, stores that value in\r
553 the object pointed to by pwc. If the corresponding wide character is the\r
554 null wide character, the function is left in the initial conversion state.\r
555\r
556 The implementation shall behave as if no library function calls the\r
557 mbtowc function.\r
558\r
559 @return If s is a null pointer, the mbtowc function returns a nonzero or\r
560 zero value, if multibyte character encodings, respectively, do\r
561 or do not have state-dependent encodings. If s is not a null\r
562 pointer, the mbtowc function either returns 0 (if s points to\r
563 the null character), or returns the number of bytes that are\r
564 contained in the converted multibyte character (if the next n or\r
565 fewer bytes form a valid multibyte character), or returns -1\r
566 (if they do not form a valid multibyte character).\r
567\r
568 In no case will the value returned be greater than n or the value\r
569 of the MB_CUR_MAX macro.\r
2aa62f2b 570**/\r
571int mbtowc(wchar_t * __restrict, const char * __restrict, size_t);\r
572\r
573/**\r
53e1e5c6 574The wctomb function determines the number of bytes needed to represent the multibyte\r
575character corresponding to the wide character given by wc (including any shift\r
576sequences), and stores the multibyte character representation in the array whose first\r
577element is pointed to by s (if s is not a null pointer). At most MB_CUR_MAX characters\r
578are stored. If wc is a null wide character, a null byte is stored, preceded by any shift\r
579sequence needed to restore the initial shift state, and the function is left in the initial\r
580conversion state.\r
581\r
582The implementation shall behave as if no library function calls the wctomb function.\r
2aa62f2b 583\r
584 @return\r
53e1e5c6 585If s is a null pointer, the wctomb function returns a nonzero or zero value, if multibyte\r
586character encodings, respectively, do or do not have state-dependent encodings. If s is\r
587not a null pointer, the wctomb function returns -1 if the value of wc does not correspond\r
588to a valid multibyte character, or returns the number of bytes that are contained in the\r
589multibyte character corresponding to the value of wc.\r
590\r
591In no case will the value returned be greater than the value of the MB_CUR_MAX macro.\r
592\r
2aa62f2b 593**/\r
594int wctomb(char *, wchar_t);\r
595\r
596/* ################ Multibyte/wide string conversion functions ########## */\r
597\r
53e1e5c6 598/** Convert a multibyte character string into a wide-character string.\r
599\r
600 The mbstowcs function converts a sequence of multibyte characters that\r
601 begins in the initial shift state from the array pointed to by src into\r
602 a sequence of corresponding wide characters and stores not more than limit\r
603 wide characters into the array pointed to by dest. No multibyte\r
604 characters that follow a null character (which is converted into a null\r
605 wide character) will be examined or converted. Each multibyte character\r
606 is converted as if by a call to the mbtowc function, except that the\r
607 conversion state of the mbtowc function is not affected.\r
608\r
609 No more than limit elements will be modified in the array pointed to by dest.\r
610 If copying takes place between objects that overlap,\r
611 the behavior is undefined.\r
612\r
613 @return If an invalid multibyte character is encountered, the mbstowcs\r
614 function returns (size_t)(-1). Otherwise, the mbstowcs function\r
615 returns the number of array elements modified, not including a\r
616 terminating null wide character, if any.\r
2aa62f2b 617\r
2aa62f2b 618**/\r
53e1e5c6 619size_t mbstowcs(wchar_t * __restrict dest, const char * __restrict src, size_t limit);\r
2aa62f2b 620\r
53e1e5c6 621/** Convert a wide-character string into a multibyte character string.\r
2aa62f2b 622\r
53e1e5c6 623 The wcstombs function converts a sequence of wide characters from the\r
624 array pointed to by src into a sequence of corresponding multibyte\r
625 characters that begins in the initial shift state, and stores these\r
626 multibyte characters into the array pointed to by dest, stopping if a\r
627 multibyte character would exceed the limit of limit total bytes or if a\r
628 null character is stored. Each wide character is converted as if by\r
629 a call to the wctomb function, except that the conversion state of\r
630 the wctomb function is not affected.\r
631\r
632 No more than limit bytes will be modified in the array pointed to by dest.\r
633 If copying takes place between objects that overlap,\r
634 the behavior is undefined.\r
635\r
636 @return If a wide character is encountered that does not correspond to a\r
637 valid multibyte character, the wcstombs function returns\r
638 (size_t)(-1). Otherwise, the wcstombs function returns the number\r
639 of bytes modified, not including a terminating null character,\r
640 if any.\r
2aa62f2b 641**/\r
53e1e5c6 642size_t wcstombs(char * __restrict dest, const wchar_t * __restrict src, size_t limit);\r
2aa62f2b 643\r
644__END_DECLS\r
645\r
646#endif /* _STDLIB_H */\r