]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/stdlib.h
StdLib: Remove EfiSocketLib and Ip4Config Protocol dependency.
[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
61403bd7 5 The files stddef.h and stdlib.h are "catch all" headers for definitions and declarations\r
6 that don't fit well in the other headers. There are two separate header files because\r
7 the contents of <stddef.h> are valid in both freestanding and hosted environment, while the\r
8 header <stdlib.h> contains elements that are only valid in a hosted environment.\r
9\r
10 The following macros are defined in this file:<BR>\r
11 @verbatim\r
12 EXIT_FAILURE An expression indicating application failure, used as an argument to exit().\r
13 EXIT_SUCCESS An expression indicating application success, used as an argument to exit().\r
14 RAND_MAX The maximum value returned by the rand function.\r
15 MB_CUR_MAX Maximum number of bytes in a multibyte character for the current locale.\r
16 ATEXIT_MAX Maximum number of routines that may be registered by the atexit function.\r
17 @endverbatim\r
18\r
19 The following types are defined in this file:<BR>\r
20 @verbatim\r
21 size_t Unsigned integer type of the result of the sizeof operator.\r
22 wchar_t The type of a wide character.\r
23 div_t Type of the value returned by the div function.\r
24 ldiv_t Type of the value returned by the ldiv function.\r
25 lldiv_t Type of the value returned by the lldiv function.\r
26 @endverbatim\r
27\r
28 The following functions are declared in this file:<BR>\r
29 @verbatim\r
30 ################ Communication with the environment\r
31 void abort (void) __noreturn;\r
32 int atexit (void (*)(void));\r
33 void exit (int status) __noreturn;\r
34 void _Exit (int status) __noreturn;\r
35 char *getenv (const char *name);\r
36 int setenv (register const char * name,\r
37 register const char * value, int rewrite);\r
38 int system (const char *string);\r
39\r
40 ################ Integer arithmetic functions\r
41 int abs (int j);\r
42 long labs (long j);\r
43 long long llabs (long long j);\r
44 div_t div (int numer, int denom);\r
45 ldiv_t ldiv (long numer, long denom);\r
46 lldiv_t lldiv (long long numer, long long denom);\r
47\r
48 ################ Pseudo-random sequence generation functions\r
49 int rand (void);\r
50 void srand (unsigned seed);\r
51\r
52 ################ Memory management functions\r
53 void *calloc (size_t Num, size_t Size);\r
54 void free (void *);\r
55 void *malloc (size_t);\r
56 void *realloc (void *Ptr, size_t NewSize);\r
57\r
58 ################ Searching and Sorting utilities\r
59 void *bsearch (const void *key, const void *base0,\r
60 size_t nmemb, size_t size,\r
61 int (*compar)(const void *, const void *));\r
62 void qsort (void *base, size_t nmemb, size_t size,\r
63 int (*compar)(const void *, const void *));\r
64\r
65 ################ Multibyte/wide character conversion functions\r
66 int mblen (const char *, size_t);\r
67 int mbtowc (wchar_t * __restrict, const char * __restrict, size_t);\r
68 int wctomb (char *, wchar_t);\r
69\r
70 ################ Multibyte/wide string conversion functions\r
71 size_t mbstowcs (wchar_t * __restrict dest,\r
72 const char * __restrict src, size_t limit);\r
73 size_t wcstombs (char * __restrict dest,\r
74 const wchar_t * __restrict src, size_t limit);\r
75\r
76 ################ Miscelaneous functions for *nix compatibility\r
77 char *realpath (char *file_name, char *resolved_name);\r
78 const char *getprogname (void);\r
79 void setprogname (const char *progname);\r
80\r
81 ############ Integer Numeric conversion functions\r
82 int atoi (const char *nptr);\r
83 long atol (const char *nptr);\r
84 long long atoll (const char *nptr);\r
85 long strtol (const char * __restrict nptr,\r
86 char ** __restrict endptr, int base);\r
87 unsigned long strtoul (const char * __restrict nptr,\r
88 char ** __restrict endptr, int base);\r
89 long long strtoll (const char * __restrict nptr,\r
90 char ** __restrict endptr, int base);\r
91 unsigned long long strtoull (const char * __restrict nptr,\r
92 char ** __restrict endptr, int base);\r
93\r
94 ######### Floating-point Numeric conversion functions\r
95 double atof (const char *);\r
96 double strtod (const char * __restrict nptr,\r
97 char ** __restrict endptr);\r
98 float strtof (const char * __restrict nptr,\r
99 char ** __restrict endptr);\r
100 long double strtold (const char * __restrict nptr,\r
101 char ** __restrict endptr);\r
102 @endverbatim\r
103\r
c352b298 104 Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
2aa62f2b 105 This program and the accompanying materials are licensed and made available under\r
106 the terms and conditions of the BSD License that accompanies this distribution.\r
107 The full text of the license may be found at\r
61403bd7 108 http://opensource.org/licenses/bsd-license.\r
2aa62f2b 109\r
110 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
111 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
2aa62f2b 112**/\r
113#ifndef _STDLIB_H\r
114#define _STDLIB_H\r
115#include <sys/EfiCdefs.h>\r
116\r
117#ifdef _EFI_SIZE_T_\r
61403bd7 118 /** Unsigned integer type of the result of the sizeof operator. **/\r
2aa62f2b 119 typedef _EFI_SIZE_T_ size_t;\r
120 #undef _EFI_SIZE_T_\r
121 #undef _BSD_SIZE_T_\r
122#endif\r
123\r
124#ifndef __cplusplus\r
125 #ifdef _EFI_WCHAR_T\r
61403bd7 126 /** Type of a wide (Unicode) character. **/\r
2aa62f2b 127 typedef _EFI_WCHAR_T wchar_t;\r
128 #undef _EFI_WCHAR_T\r
129 #undef _BSD_WCHAR_T_\r
130 #endif\r
131#endif\r
132\r
133/// A structure type that is the type of the value returned by the div function.\r
134typedef struct {\r
61403bd7 135 int quot; /**< quotient */\r
136 int rem; /**< remainder */\r
2aa62f2b 137} div_t;\r
138\r
139/// A structure type that is the type of the value returned by the ldiv function.\r
140typedef struct {\r
141 long quot;\r
142 long rem;\r
143} ldiv_t;\r
144\r
145/// A structure type that is the type of the value returned by the lldiv function.\r
146typedef struct {\r
147 long long quot;\r
148 long long rem;\r
149} lldiv_t;\r
150\r
61403bd7 151/** @{\r
152 Expand to integer constant expressions that can be used as the argument to\r
2aa62f2b 153 the exit function to return unsuccessful or successful termination status,\r
154 respectively, to the host environment.\r
155**/\r
156#define EXIT_FAILURE 1\r
157#define EXIT_SUCCESS 0\r
61403bd7 158/*@}*/\r
2aa62f2b 159\r
160/** Expands to an integer constant expression that is the maximum value\r
161 returned by the rand function.\r
2aa62f2b 162**/\r
163#define RAND_MAX 0x7fffffff\r
164\r
165/** Expands to a positive integer expression with type size_t that is the\r
166 maximum number of bytes in a multibyte character for the extended character\r
167 set specified by the current locale (category LC_CTYPE), which is never\r
168 greater than MB_LEN_MAX.\r
c352b298 169\r
170 Since UEFI only supports the Unicode Base Multilingual Plane (BMP),\r
171 correctly formed characters will only produce 1, 2, or 3-byte UTF-8 characters.\r
2aa62f2b 172**/\r
c352b298 173#define MB_CUR_MAX 3\r
2aa62f2b 174\r
175/** Maximum number of functions that can be registered by atexit.\r
176\r
177 The C standard states that the implementation shall support the\r
178 registration of at least 32 functions.\r
179**/\r
180#define ATEXIT_MAX 32\r
181\r
182__BEGIN_DECLS\r
183\r
184/* ################ Communication with the environment ################## */\r
185\r
186/** The abort function causes abnormal program termination to occur, unless\r
187 the signal SIGABRT is being caught and the signal handler does not return.\r
188\r
189 Open streams with unwritten buffered data are not flushed, open\r
190 streams are not closed, and temporary files are not removed by abort.\r
191\r
192 Unsuccessful termination is returned to the host environment by means of\r
193 the function call, raise(SIGABRT).\r
194\r
195 @sa signal.h\r
196**/\r
d7ce7006 197void abort(void) __noreturn;\r
2aa62f2b 198\r
199/** The atexit function registers the function pointed to by func, to be\r
200 called without arguments at normal program termination.\r
201\r
202 The implementation supports the registration of up to 32 functions.\r
203\r
61403bd7 204 @param[in] Handler Pointer to the function to register as one of the\r
205 routines to call at application exit time.\r
206\r
2aa62f2b 207 @return The atexit function returns zero if the registration succeeds,\r
208 nonzero if it fails.\r
209**/\r
61403bd7 210int atexit(void (*Handler)(void));\r
2aa62f2b 211\r
212/** The exit function causes normal program termination to occur. If more than\r
213 one call to the exit function is executed by a program,\r
214 the behavior is undefined.\r
215\r
216 First, all functions registered by the atexit function are called, in the\r
217 reverse order of their registration, except that a function is called\r
218 after any previously registered functions that had already been called at\r
219 the time it was registered. If, during the call to any such function, a\r
220 call to the longjmp function is made that would terminate the call to the\r
221 registered function, the behavior is undefined.\r
222\r
223 Next, all open streams with unwritten buffered data are flushed, all open\r
224 streams are closed, and all files created by the tmpfile function\r
225 are removed.\r
226\r
61403bd7 227 Finally, control is returned to the host environment.\r
228\r
229 @param[in] status A value to be returned when the application exits.\r
d7ce7006 230\r
61403bd7 231 @return If the value of status is zero, or EXIT_SUCCESS, status is\r
232 returned unchanged. If the value of status is EXIT_FAILURE,\r
233 RETURN_ABORTED is returned. Otherwise, status is returned unchanged.\r
2aa62f2b 234**/\r
235void exit(int status) __noreturn;\r
236\r
237/** The _Exit function causes normal program termination to occur and control\r
238 to be returned to the host environment.\r
239\r
240 No functions registered by the atexit function or signal handlers\r
241 registered by the signal function are called. Open streams with unwritten\r
242 buffered data are not flushed, open streams are not closed, and temporary\r
243 files are not removed by abort.\r
244\r
245 The status returned to the host environment is determined in the same way\r
246 as for the exit function.\r
61403bd7 247\r
248 @param[in] status A value to be returned when the application exits.\r
249\r
250 @return If the value of status is zero, or EXIT_SUCCESS, status is\r
251 returned unchanged. If the value of status is EXIT_FAILURE,\r
252 RETURN_ABORTED is returned. Otherwise, status is returned unchanged.\r
2aa62f2b 253**/\r
d7ce7006 254void _Exit(int status) __noreturn;\r
2aa62f2b 255\r
256/** The getenv function searches an environment list, provided by the host\r
257 environment, for a string that matches the string pointed to by name. The\r
258 set of environment names and the method for altering the environment list\r
259 are determined by the underlying UEFI Shell implementation.\r
260\r
61403bd7 261 @param[in] name Pointer to a string naming the environment variable to retrieve.\r
262\r
2aa62f2b 263 @return The getenv function returns a pointer to a string associated with\r
264 the matched list member. The string pointed to shall not be\r
265 modified by the program, but may be overwritten by a subsequent\r
266 call to the getenv function. If the specified name cannot be\r
267 found, a null pointer is returned.\r
268**/\r
269char *getenv(const char *name);\r
270\r
61403bd7 271/** Add or update a variable in the environment list.\r
53e1e5c6 272\r
61403bd7 273 @param[in] name Address of a zero terminated name string.\r
274 @param[in] value Address of a zero terminated value string.\r
275 @param[in] rewrite TRUE allows overwriting existing values.\r
53e1e5c6 276\r
61403bd7 277 @retval 0 Returns 0 upon success.\r
278 @retval -1 Returns -1 upon failure, sets errno with more information.\r
53e1e5c6 279**/\r
280int\r
281setenv (\r
282 register const char * name,\r
283 register const char * value,\r
284 int rewrite\r
285 );\r
286\r
2aa62f2b 287/** If string is a null pointer, the system function determines whether the\r
288 host environment has a command processor. If string is not a null pointer,\r
289 the system function passes the string pointed to by string to that command\r
290 processor to be executed in a manner which the implementation shall\r
291 document; this might then cause the program calling system to behave in a\r
292 non-conforming manner or to terminate.\r
293\r
61403bd7 294 @param[in] string Pointer to the command string to be executed.\r
295\r
2aa62f2b 296 @return If the argument is a null pointer, the system function returns\r
297 nonzero only if a command processor is available. If the argument\r
298 is not a null pointer, and the system function does return, it\r
299 returns an implementation-defined value.\r
300**/\r
301int system(const char *string);\r
302\r
303\r
304/* ################ Integer arithmetic functions ######################## */\r
305\r
306/** Computes the absolute value of an integer j.\r
307\r
61403bd7 308 @param[in] j The value to find the absolute value of.\r
309\r
2aa62f2b 310 @return The absolute value of j.\r
311**/\r
312int abs(int j);\r
313\r
61403bd7 314/** Computes the absolute value of a long integer j.\r
315\r
316 @param[in] j The value to find the absolute value of.\r
2aa62f2b 317\r
318 @return The absolute value of j.\r
319**/\r
320long labs(long j);\r
321\r
61403bd7 322/** Computes the absolute value of a long long integer j.\r
323\r
324 @param[in] j The value to find the absolute value of.\r
2aa62f2b 325\r
326 @return The absolute value of j.\r
327**/\r
328long long\r
329 llabs(long long j);\r
330\r
331/** Computes numer / denom and numer % denom in a single operation.\r
332\r
61403bd7 333 @param[in] numer The numerator for the division.\r
334 @param[in] denom The denominator for the division.\r
335\r
2aa62f2b 336 @return Returns a structure of type div_t, comprising both the\r
337 quotient and the remainder.\r
338**/\r
339div_t div(int numer, int denom);\r
340\r
341/** Computes numer / denom and numer % denom in a single operation.\r
342\r
61403bd7 343 @param[in] numer The numerator for the division.\r
344 @param[in] denom The denominator for the division.\r
345\r
2aa62f2b 346 @return Returns a structure of type ldiv_t, comprising both the\r
347 quotient and the remainder.\r
348**/\r
349ldiv_t ldiv(long numer, long denom);\r
350\r
351/** Computes numer / denom and numer % denom in a single operation.\r
352\r
61403bd7 353 @param[in] numer The numerator for the division.\r
354 @param[in] denom The denominator for the division.\r
355\r
2aa62f2b 356 @return Returns a structure of type lldiv_t, comprising both the\r
357 quotient and the remainder.\r
358**/\r
359lldiv_t lldiv(long long numer, long long denom);\r
360\r
361/* ############ Integer Numeric conversion functions #################### */\r
362\r
363/** The atoi function converts the initial portion of the string pointed to by\r
364 nptr to int representation. Except for the behavior on error, it is\r
365 equivalent to:\r
366 - atoi: (int)strtol(nptr, (char **)NULL, 10)\r
367\r
61403bd7 368 @param[in] nptr Pointer to the string to be converted.\r
369\r
370 @return The atoi function returns the converted value.\r
2aa62f2b 371**/\r
372int atoi(const char *nptr);\r
373\r
374/** The atol function converts the initial portion of the string pointed to by\r
375 nptr to long int representation. Except for the behavior on error, it is\r
376 equivalent to:\r
377 - atol: strtol(nptr, (char **)NULL, 10)\r
378\r
61403bd7 379 @param[in] nptr Pointer to the string to be converted.\r
380\r
381 @return The atol function returns the converted value.\r
2aa62f2b 382**/\r
383long atol(const char *nptr);\r
384\r
385/** The atoll function converts the initial portion of the string pointed to by\r
386 nptr to long long int representation. Except for the behavior on error, it\r
387 is equivalent to:\r
388 - atoll: strtoll(nptr, (char **)NULL, 10)\r
389\r
61403bd7 390 @param[in] nptr Pointer to the string to be converted.\r
391\r
392 @return The atoll function returns the converted value.\r
2aa62f2b 393**/\r
394long long\r
395 atoll(const char *nptr);\r
396\r
397/** The strtol, strtoll, strtoul, and strtoull functions convert the initial\r
398 portion of the string pointed to by nptr to long int, long long int,\r
399 unsigned long int, and unsigned long long int representation, respectively.\r
400 First, they decompose the input string into three parts: an initial,\r
401 possibly empty, sequence of white-space characters (as specified by the\r
402 isspace function), a subject sequence resembling an integer represented in\r
403 some radix determined by the value of base, and a final string of one or\r
404 more unrecognized characters, including the terminating null character of\r
405 the input string. Then, they attempt to convert the subject sequence to an\r
406 integer, and return the result.\r
407\r
408 If the value of base is zero, the expected form of the subject sequence is\r
61403bd7 409 that of an integer constant, optionally preceded\r
2aa62f2b 410 by a plus or minus sign, but not including an integer suffix. If the value\r
411 of base is between 2 and 36 (inclusive), the expected form of the subject\r
412 sequence is a sequence of letters and digits representing an integer with\r
413 the radix specified by base, optionally preceded by a plus or minus sign,\r
414 but not including an integer suffix. The letters from a (or A) through z\r
415 (or Z) are ascribed the values 10 through 35; only letters and digits whose\r
416 ascribed values are less than that of base are permitted. If the value of\r
417 base is 16, the characters 0x or 0X may optionally precede the sequence of\r
418 letters and digits, following the sign if present.\r
419\r
420 The subject sequence is defined as the longest initial subsequence of the\r
421 input string, starting with the first non-white-space character, that is of\r
422 the expected form. The subject sequence contains no characters if the input\r
423 string is empty or consists entirely of white space, or if the first\r
424 non-white-space character is other than a sign or a permissible letter or digit.\r
425\r
426 If the subject sequence has the expected form and the value of base is\r
427 zero, the sequence of characters starting with the first digit is\r
428 interpreted as an integer constant. If the subject sequence has the\r
429 expected form and the value of base is between 2 and 36, it is used as the\r
430 base for conversion, ascribing to each letter its value as given above. If\r
431 the subject sequence begins with a minus sign, the value resulting from the\r
432 conversion is negated (in the return type). A pointer to the final string\r
433 is stored in the object pointed to by endptr, provided that endptr is\r
434 not a null pointer.\r
435\r
436 In other than the "C" locale, additional locale-specific subject sequence\r
437 forms may be accepted.\r
438\r
439 If the subject sequence is empty or does not have the expected form, no\r
440 conversion is performed; the value of nptr is stored in the object pointed\r
441 to by endptr, provided that endptr is not a null pointer.\r
442\r
61403bd7 443 @param[in] nptr Pointer to the string to be converted.\r
444 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
445 @param[in] base The base, 0 to 36, of the number represented by the input string.\r
446\r
447 @return The strtol, strtoll, strtoul, and strtoull functions return the\r
448 converted value, if any. If no conversion could be performed, zero\r
449 is returned. If the correct value is outside the range of\r
450 representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX,\r
451 ULONG_MAX, or ULLONG_MAX is returned (according to the return type\r
452 and sign of the value, if any), and the value of the macro ERANGE\r
453 is stored in errno.\r
2aa62f2b 454**/\r
455long strtol(const char * __restrict nptr, char ** __restrict endptr, int base);\r
456\r
457/** The strtoul function converts the initial portion of the string pointed to\r
458 by nptr to unsigned long int representation.\r
459\r
460 See the description for strtol for more information.\r
461\r
61403bd7 462 @param[in] nptr Pointer to the string to be converted.\r
463 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
464 @param[in] base The base, 0 to 36, of the number represented by the input string.\r
465\r
466 @return The strtoul function returns the converted value, if any. If no\r
467 conversion could be performed, zero is returned. If the correct\r
468 value is outside the range of representable values, ULONG_MAX is\r
469 returned and the value of the macro ERANGE is stored in errno.\r
2aa62f2b 470**/\r
471unsigned long\r
472 strtoul(const char * __restrict nptr, char ** __restrict endptr, int base);\r
473\r
474/** The strtoll function converts the initial portion of the string pointed to\r
475 by nptr to long long int representation.\r
476\r
477 See the description for strtol for more information.\r
478\r
61403bd7 479 @param[in] nptr Pointer to the string to be converted.\r
480 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
481 @param[in] base The base, 0 to 36, of the number represented by the input string.\r
482\r
483 @return The strtoll function returns the converted value, if any. If no\r
484 conversion could be performed, zero is returned. If the correct\r
485 value is outside the range of representable values, LLONG_MIN or\r
486 LLONG_MAX is returned (according to the sign of the value, if any),\r
487 and the value of the macro ERANGE is stored in errno.\r
2aa62f2b 488**/\r
489long long\r
490 strtoll(const char * __restrict nptr, char ** __restrict endptr, int base);\r
491\r
492/** The strtoull function converts the initial portion of the string pointed to\r
493 by nptr to unsigned long long int representation.\r
494\r
495 See the description for strtol for more information.\r
496\r
61403bd7 497 @param[in] nptr Pointer to the string to be converted.\r
498 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
499 @param[in] base The base, 0 to 36, of the number represented by the input string.\r
500\r
501 @return The strtoull function returns the converted value, if any. If no\r
502 conversion could be performed, zero is returned. If the correct\r
503 value is outside the range of representable values, ULLONG_MAX is\r
504 returned and the value of the macro ERANGE is stored in errno.\r
2aa62f2b 505**/\r
506unsigned long long\r
507 strtoull(const char * __restrict nptr, char ** __restrict endptr, int base);\r
508\r
509/* ######### Floating-point Numeric conversion functions ################ */\r
510\r
61403bd7 511/** Convert the initial part of a string to double representation.\r
512\r
513 @param[in] nptr Pointer to the string to be converted.\r
2aa62f2b 514\r
61403bd7 515 @return The floating-point value representing the string nptr.\r
2aa62f2b 516**/\r
61403bd7 517double atof(const char *nptr);\r
518\r
519/** @{\r
520 The strtod, strtof, and strtold functions convert the initial portion of\r
521 the string pointed to by nptr to double, float, and long double\r
522 representation, respectively. First, they decompose the input string into\r
523 three parts: an initial, possibly empty, sequence of white-space characters\r
524 (as specified by the isspace function), a subject sequence resembling a\r
525 floating-point constant or representing an infinity or NaN; and a final\r
526 string of one or more unrecognized characters, including the terminating\r
527 null character of the input string. Then, they attempt to convert the\r
528 subject sequence to a floating-point number, and return the result.\r
529*/\r
530\r
531/** Convert a string to a double and point to the character after the last converted.\r
2aa62f2b 532\r
61403bd7 533 @param[in] nptr Pointer to the string to be converted.\r
534 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
2aa62f2b 535\r
61403bd7 536 @return A floating-point value representing the string nptr.\r
537 A pointer to the final string is stored in the object pointed to\r
538 by endptr, provided that endptr is not a null pointer.\r
539 If the subject sequence is empty or does not have the expected\r
540 form, no conversion is performed; the value of nptr is stored in\r
541 the object pointed to by endptr, provided that endptr is not a null pointer.\r
2aa62f2b 542**/\r
543double strtod(const char * __restrict nptr, char ** __restrict endptr);\r
544\r
61403bd7 545/** Convert a string to a float and point to the character after the last converted.\r
2aa62f2b 546\r
61403bd7 547 @param[in] nptr Pointer to the string to be converted.\r
548 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
549\r
550 @return A floating-point value representing the string nptr.\r
551 A pointer to the final string is stored in the object pointed to\r
552 by endptr, provided that endptr is not a null pointer.\r
553 If the subject sequence is empty or does not have the expected\r
554 form, no conversion is performed; the value of nptr is stored in\r
555 the object pointed to by endptr, provided that endptr is not a null pointer.\r
2aa62f2b 556**/\r
557float strtof(const char * __restrict nptr, char ** __restrict endptr);\r
558\r
61403bd7 559/** Convert a string to a long double and point to the character after the last converted.\r
560\r
561 @param[in] nptr Pointer to the string to be converted.\r
562 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
2aa62f2b 563\r
61403bd7 564 @return A floating-point value representing the string nptr.\r
565 A pointer to the final string is stored in the object pointed to\r
566 by endptr, provided that endptr is not a null pointer.\r
567 If the subject sequence is empty or does not have the expected\r
568 form, no conversion is performed; the value of nptr is stored in\r
569 the object pointed to by endptr, provided that endptr is not a null pointer.\r
2aa62f2b 570**/\r
571long double\r
572 strtold(const char * __restrict nptr, char ** __restrict endptr);\r
61403bd7 573/*@}*/\r
2aa62f2b 574\r
575/* ################ Pseudo-random sequence generation functions ######### */\r
576\r
577/** The rand function computes a sequence of pseudo-random integers in the\r
578 range 0 to RAND_MAX.\r
579\r
580 @return The rand function returns a pseudo-random integer.\r
581**/\r
582int rand(void);\r
583\r
584/** The srand function uses the argument as a seed for a new sequence of\r
585 pseudo-random numbers to be returned by subsequent calls to rand.\r
586\r
587 If srand is then called with the same seed value, the sequence of\r
588 pseudo-random numbers shall be repeated. If rand is called before any calls\r
589 to srand have been made, the same sequence shall be generated as when srand\r
590 is first called with a seed value of 1.\r
61403bd7 591\r
592 @param[in] seed The value used to "seed" the random number generator with.\r
2aa62f2b 593**/\r
594void srand(unsigned seed);\r
595\r
596/* ################ Memory management functions ######################### */\r
597\r
598/** The calloc function allocates space for an array of Num objects, each of\r
599 whose size is Size. The space is initialized to all bits zero.\r
600\r
61403bd7 601 @param[in] Num The number of objects to allocate space for.\r
602 @param[in] Size The size, in bytes, of each object.\r
603\r
2aa62f2b 604 @return NULL is returned if the space could not be allocated and errno\r
605 contains the cause. Otherwise, a pointer to an 8-byte aligned\r
606 region of the requested size is returned.\r
607**/\r
608void *calloc(size_t Num, size_t Size);\r
609\r
610/** The free function causes the space pointed to by Ptr to be deallocated,\r
611 that is, made available for further allocation.\r
612\r
613 If Ptr is a null pointer, no action occurs. Otherwise, if the argument\r
614 does not match a pointer earlier returned by the calloc, malloc, or realloc\r
615 function, or if the space has been deallocated by a call to free or\r
616 realloc, the behavior is undefined.\r
617\r
618 @param Ptr Pointer to a previously allocated region of memory to be freed.\r
2aa62f2b 619**/\r
61403bd7 620void free(void *Ptr);\r
2aa62f2b 621\r
622/** The malloc function allocates space for an object whose size is specified\r
623 by size and whose value is indeterminate.\r
624\r
625 This implementation uses the UEFI memory allocation boot services to get a\r
626 region of memory that is 8-byte aligned and of the specified size. The\r
627 region is allocated with type EfiLoaderData.\r
628\r
61403bd7 629 @param Size Size, in bytes, of the region to allocate.\r
2aa62f2b 630\r
631 @return NULL is returned if the space could not be allocated and errno\r
632 contains the cause. Otherwise, a pointer to an 8-byte aligned\r
633 region of the requested size is returned.<BR>\r
634 If NULL is returned, errno may contain:\r
635 - EINVAL: Requested Size is zero.\r
636 - ENOMEM: Memory could not be allocated.\r
637**/\r
61403bd7 638void *malloc(size_t Size);\r
2aa62f2b 639\r
640/** The realloc function changes the size of the object pointed to by Ptr to\r
641 the size specified by NewSize.\r
642\r
643 The contents of the object are unchanged up to the lesser of the new and\r
644 old sizes. If the new size is larger, the value of the newly allocated\r
645 portion of the object is indeterminate.\r
646\r
647 If Ptr is a null pointer, the realloc function behaves like the malloc\r
648 function for the specified size.\r
649\r
650 If Ptr does not match a pointer earlier returned by the calloc, malloc, or\r
651 realloc function, or if the space has been deallocated by a call to the free\r
652 or realloc function, the behavior is undefined.\r
653\r
654 If the space cannot be allocated, the object pointed to by Ptr is unchanged.\r
655\r
656 If NewSize is zero and Ptr is not a null pointer, the object it points to\r
657 is freed.\r
658\r
659 This implementation uses the UEFI memory allocation boot services to get a\r
660 region of memory that is 8-byte aligned and of the specified size. The\r
661 region is allocated with type EfiLoaderData.\r
662\r
663 @param Ptr Pointer to a previously allocated region of memory to be resized.\r
664 @param NewSize Size, in bytes, of the new object to allocate space for.\r
665\r
666 @return NULL is returned if the space could not be allocated and errno\r
667 contains the cause. Otherwise, a pointer to an 8-byte aligned\r
668 region of the requested size is returned. If NewSize is zero,\r
669 NULL is returned and errno will be unchanged.\r
670**/\r
671void *realloc(void *Ptr, size_t NewSize);\r
672\r
673/* ################ Searching and Sorting utilities ##################### */\r
674\r
61403bd7 675/** The bsearch function searches an array of Nmemb objects, the initial\r
676 element of which is pointed to by Base, for an element that matches the\r
677 object pointed to by Key. The size of each element of the array is\r
678 specified by Size.\r
2aa62f2b 679\r
61403bd7 680 The comparison function pointed to by Compar is called with two arguments\r
681 that point to the Key object and to an array element, in that order. The\r
2aa62f2b 682 function returns an integer less than, equal to, or greater than zero if\r
61403bd7 683 the Key object is considered, respectively, to be less than, to match, or\r
2aa62f2b 684 to be greater than the array element. The array consists of: all the\r
685 elements that compare less than, all the elements that compare equal to,\r
686 and all the elements that compare greater than the key object,\r
687 in that order.\r
688\r
61403bd7 689 @param[in] Key Pointer to the object to search for.\r
690 @param[in] Base Pointer to the first element of an array to search.\r
691 @param[in] Nmemb Number of objects in the search array.\r
692 @param[in] Size The size of each object in the search array.\r
693 @param[in] Compar Pointer to the function used to compare two objects.\r
694\r
695 @return The bsearch function returns a pointer to a matching element of the\r
696 array, or a null pointer if no match is found. If two elements\r
697 compare as equal, which element is matched is unspecified.\r
2aa62f2b 698**/\r
61403bd7 699void *bsearch( const void *Key, const void *Base,\r
700 size_t Nmemb, size_t Size,\r
701 int (*Compar)(const void *, const void *)\r
702 );\r
2aa62f2b 703\r
61403bd7 704/** The qsort function sorts an array of Nmemb objects, the initial element of\r
705 which is pointed to by Base. The size of each object is specified by Size.\r
2aa62f2b 706\r
707 The contents of the array are sorted into ascending order according to a\r
61403bd7 708 comparison function pointed to by Compar, which is called with two\r
2aa62f2b 709 arguments that point to the objects being compared. The function shall\r
710 return an integer less than, equal to, or greater than zero if the first\r
711 argument is considered to be respectively less than, equal to, or greater\r
712 than the second.\r
713\r
714 If two elements compare as equal, their order in the resulting sorted array\r
715 is unspecified.\r
61403bd7 716\r
717 @param[in,out] Base Pointer to the first element of an array to sort.\r
718 @param[in] Nmemb Number of objects in the array.\r
719 @param[in] Size The size of each object in the array.\r
720 @param[in] Compar Pointer to the function used to compare two objects.\r
2aa62f2b 721**/\r
61403bd7 722void qsort( void *base, size_t nmemb, size_t size,\r
723 int (*compar)(const void *, const void *));\r
2aa62f2b 724\r
725/* ################ Multibyte/wide character conversion functions ####### */\r
726\r
53e1e5c6 727/** Determine the number of bytes comprising a multibyte character.\r
2aa62f2b 728\r
61403bd7 729 If S is not a null pointer, the mblen function determines the number of bytes\r
730 contained in the multibyte character pointed to by S. Except that the\r
53e1e5c6 731 conversion state of the mbtowc function is not affected, it is equivalent to\r
61403bd7 732 mbtowc((wchar_t *)0, S, N);\r
53e1e5c6 733\r
61403bd7 734 @param[in] S NULL to query whether multibyte characters have\r
735 state-dependent encodings. Otherwise, points to a\r
736 multibyte character.\r
737 @param[in] N The maximum number of bytes in a multibyte character.\r
53e1e5c6 738\r
61403bd7 739 @return If S is a null pointer, the mblen function returns a nonzero or\r
53e1e5c6 740 zero value, if multibyte character encodings, respectively, do\r
61403bd7 741 or do not have state-dependent encodings. If S is not a null\r
742 pointer, the mblen function either returns 0 (if S points to the\r
53e1e5c6 743 null character), or returns the number of bytes that are contained\r
61403bd7 744 in the multibyte character (if the next N or fewer bytes form a\r
53e1e5c6 745 valid multibyte character), or returns -1 (if they do not form a\r
746 valid multibyte character).\r
2aa62f2b 747**/\r
61403bd7 748int mblen(const char *S, size_t N);\r
2aa62f2b 749\r
53e1e5c6 750/** Convert a multibyte character into a wide character.\r
2aa62f2b 751\r
61403bd7 752 If S is not a null pointer, the mbtowc function inspects at most N bytes\r
753 beginning with the byte pointed to by S to determine the number of bytes\r
53e1e5c6 754 needed to complete the next multibyte character (including any shift\r
755 sequences). If the function determines that the next multibyte character\r
756 is complete and valid, it determines the value of the corresponding wide\r
61403bd7 757 character and then, if Pwc is not a null pointer, stores that value in\r
758 the object pointed to by Pwc. If the corresponding wide character is the\r
53e1e5c6 759 null wide character, the function is left in the initial conversion state.\r
760\r
61403bd7 761 @param[out] Pwc Pointer to a wide-character object to receive the converted character.\r
762 @param[in] S Pointer to a multibyte character to convert.\r
763 @param[in] N Maximum number of bytes in a multibyte character.\r
53e1e5c6 764\r
61403bd7 765 @return If S is a null pointer, the mbtowc function returns a nonzero or\r
53e1e5c6 766 zero value, if multibyte character encodings, respectively, do\r
61403bd7 767 or do not have state-dependent encodings. If S is not a null\r
768 pointer, the mbtowc function either returns 0 (if S points to\r
53e1e5c6 769 the null character), or returns the number of bytes that are\r
61403bd7 770 contained in the converted multibyte character (if the next N or\r
53e1e5c6 771 fewer bytes form a valid multibyte character), or returns -1\r
772 (if they do not form a valid multibyte character).\r
773\r
61403bd7 774 In no case will the value returned be greater than N or the value\r
53e1e5c6 775 of the MB_CUR_MAX macro.\r
2aa62f2b 776**/\r
61403bd7 777int mbtowc(wchar_t * __restrict Pwc, const char * __restrict S, size_t N);\r
2aa62f2b 778\r
61403bd7 779/** Convert a wide character into a multibyte character.\r
53e1e5c6 780\r
61403bd7 781 The wctomb function determines the number of bytes needed to represent the\r
782 multibyte character corresponding to the wide character given by WC\r
783 (including any shift sequences), and stores the multibyte character\r
784 representation in the array whose first element is pointed to by S (if S is\r
785 not a null pointer). At most MB_CUR_MAX characters are stored. If WC is a\r
786 null wide character, a null byte is stored, preceded by any shift sequence\r
787 needed to restore the initial shift state, and the function is left in the\r
788 initial conversion state.\r
2aa62f2b 789\r
61403bd7 790 @param[out] S Pointer to the object to receive the converted multibyte character.\r
791 @param[in] WC Wide character to be converted.\r
53e1e5c6 792\r
61403bd7 793 @return If S is a null pointer, the wctomb function returns a nonzero or\r
794 zero value, if multibyte character encodings, respectively, do or\r
795 do not have state-dependent encodings. If S is not a null pointer,\r
796 the wctomb function returns -1 if the value of WC does not\r
797 correspond to a valid multibyte character, or returns the number\r
798 of bytes that are contained in the multibyte character\r
799 corresponding to the value of WC.\r
53e1e5c6 800\r
61403bd7 801 In no case will the value returned be greater than the value of\r
802 the MB_CUR_MAX macro.\r
2aa62f2b 803**/\r
61403bd7 804int wctomb(char *S, wchar_t WC);\r
2aa62f2b 805\r
806/* ################ Multibyte/wide string conversion functions ########## */\r
807\r
53e1e5c6 808/** Convert a multibyte character string into a wide-character string.\r
809\r
810 The mbstowcs function converts a sequence of multibyte characters that\r
61403bd7 811 begins in the initial shift state from the array pointed to by Src into\r
53e1e5c6 812 a sequence of corresponding wide characters and stores not more than limit\r
61403bd7 813 wide characters into the array pointed to by Dest. No multibyte\r
53e1e5c6 814 characters that follow a null character (which is converted into a null\r
815 wide character) will be examined or converted. Each multibyte character\r
816 is converted as if by a call to the mbtowc function, except that the\r
817 conversion state of the mbtowc function is not affected.\r
818\r
61403bd7 819 No more than Limit elements will be modified in the array pointed to by Dest.\r
53e1e5c6 820 If copying takes place between objects that overlap,\r
821 the behavior is undefined.\r
822\r
61403bd7 823 @param[out] Dest Pointer to the array to receive the converted string.\r
824 @param[in] Src Pointer to the string to be converted.\r
825 @param[in] Limit Maximum number of elements to be written to Dest.\r
2aa62f2b 826\r
61403bd7 827 @return If an invalid multibyte character is encountered, the mbstowcs\r
828 function returns (size_t)(-1). Otherwise, the mbstowcs function\r
829 returns the number of array elements modified, not including a\r
830 terminating null wide character, if any.\r
2aa62f2b 831**/\r
61403bd7 832size_t mbstowcs(wchar_t * __restrict Dest, const char * __restrict Src, size_t Limit);\r
2aa62f2b 833\r
53e1e5c6 834/** Convert a wide-character string into a multibyte character string.\r
2aa62f2b 835\r
53e1e5c6 836 The wcstombs function converts a sequence of wide characters from the\r
61403bd7 837 array pointed to by Src into a sequence of corresponding multibyte\r
53e1e5c6 838 characters that begins in the initial shift state, and stores these\r
61403bd7 839 multibyte characters into the array pointed to by Dest, stopping if a\r
840 multibyte character would exceed the limit of Limit total bytes or if a\r
53e1e5c6 841 null character is stored. Each wide character is converted as if by\r
842 a call to the wctomb function, except that the conversion state of\r
843 the wctomb function is not affected.\r
844\r
61403bd7 845 No more than Limit bytes will be modified in the array pointed to by Dest.\r
53e1e5c6 846 If copying takes place between objects that overlap,\r
847 the behavior is undefined.\r
848\r
61403bd7 849 @param[out] Dest Pointer to the array to receive the converted string.\r
850 @param[in] Src Pointer to the string to be converted.\r
c352b298 851 @param[in] Limit Maximum number of bytes to be written to Dest.\r
61403bd7 852\r
853 @return If a wide character is encountered that does not correspond to a\r
854 valid multibyte character, the wcstombs function returns\r
855 (size_t)(-1). Otherwise, the wcstombs function returns the number\r
856 of bytes modified, not including a terminating null character,\r
857 if any.\r
2aa62f2b 858**/\r
61403bd7 859size_t wcstombs(char * __restrict Dest, const wchar_t * __restrict Src, size_t Limit);\r
860\r
c352b298 861/* ############## Miscelaneous functions for *nix compatibility ########## */\r
2aa62f2b 862\r
61403bd7 863/** The realpath() function shall derive, from the pathname pointed to by\r
864 file_name, an absolute pathname that names the same file, whose resolution\r
865 does not involve '.', '..', or symbolic links. The generated pathname shall\r
866 be stored as a null-terminated string, up to a maximum of {PATH_MAX} bytes,\r
867 in the buffer pointed to by resolved_name.\r
d7ce7006 868\r
61403bd7 869 If resolved_name is a null pointer, the behavior of realpath() is\r
870 implementation-defined.\r
d7ce7006 871\r
61403bd7 872 @param[in] file_name The filename to convert.\r
873 @param[in,out] resolved_name The resultant name.\r
d7ce7006 874\r
61403bd7 875 @retval NULL An error occured.\r
876 @retval resolved_name.\r
d7ce7006 877**/\r
878char * realpath(char *file_name, char *resolved_name);\r
879\r
61403bd7 880/** The getprogname() function returns the name of the program. If the name\r
881 has not been set yet, it will return NULL.\r
d7ce7006 882\r
61403bd7 883 @return The getprogname function returns NULL if the program's name has not\r
884 been set, otherwise it returns the name of the program.\r
d7ce7006 885**/\r
886const char * getprogname(void);\r
887\r
61403bd7 888/** The setprogname() function sets the name of the program.\r
d7ce7006 889\r
61403bd7 890 @param[in] progname The name of the program. This memory must be retained\r
891 by the caller until no calls to "getprogname" will be\r
892 called.\r
d7ce7006 893**/\r
894void setprogname(const char *progname);\r
895\r
c352b298 896/* ############### Functions specific to this implementation ############# */\r
897\r
898/* Determine the number of bytes needed to represent a Wide character\r
899 as a MBCS character.\r
900\r
901 A single wide character may convert into a one, two, three, or four byte\r
902 narrow (MBCS or UTF-8) character. The number of MBCS bytes can be determined\r
903 as follows.\r
904\r
905 If WCS char < 0x00000080 One Byte\r
906 Else if WCS char < 0x0000D800 Two Bytes\r
907 Else Three Bytes\r
908\r
909 Since UEFI only supports the Unicode Base Multilingual Plane (BMP),\r
910 Four-byte characters are not supported.\r
911\r
912 @param[in] InCh Wide character to test.\r
913\r
914 @retval -1 Improperly formed character\r
915 @retval 0 InCh is 0x0000\r
916 @retval >0 Number of bytes needed for the MBCS character\r
917*/\r
918int\r
919EFIAPI\r
920OneWcToMcLen(const wchar_t InCh);\r
921\r
922/* Determine the number of bytes needed to represent a Wide character string\r
923 as a MBCS string of given maximum length. Will optionally return the number\r
924 of wide characters that would be consumed.\r
925\r
926 @param[in] Src Pointer to a wide character string.\r
927 @param[in] Limit Maximum number of bytes the converted string may occupy.\r
928 @param[out] NumChar Pointer to where to store the number of wide characters, or NULL.\r
929\r
930 @return The number of bytes required to convert Src to MBCS,\r
931 not including the terminating NUL. If NumChar is not NULL, the number\r
932 of characters represented by the return value will be written to\r
933 where it points.\r
934**/\r
935size_t\r
936EFIAPI\r
937EstimateWtoM(const wchar_t * Src, size_t Limit, size_t *NumChar);\r
938\r
939/** Determine the number of characters in a MBCS string.\r
940\r
941 @param[in] Src The string to examine\r
942\r
943 @return The number of characters represented by the MBCS string.\r
944**/\r
945size_t\r
946EFIAPI\r
947CountMbcsChars(const char *Src);\r
948\r
2aa62f2b 949__END_DECLS\r
950\r
951#endif /* _STDLIB_H */\r