]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/stdlib.h
Fix GCC build errors.
[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
53e1e5c6 104 Copyright (c) 2010 - 2011, 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
169**/\r
170#define MB_CUR_MAX 2\r
171\r
172/** Maximum number of functions that can be registered by atexit.\r
173\r
174 The C standard states that the implementation shall support the\r
175 registration of at least 32 functions.\r
176**/\r
177#define ATEXIT_MAX 32\r
178\r
179__BEGIN_DECLS\r
180\r
181/* ################ Communication with the environment ################## */\r
182\r
183/** The abort function causes abnormal program termination to occur, unless\r
184 the signal SIGABRT is being caught and the signal handler does not return.\r
185\r
186 Open streams with unwritten buffered data are not flushed, open\r
187 streams are not closed, and temporary files are not removed by abort.\r
188\r
189 Unsuccessful termination is returned to the host environment by means of\r
190 the function call, raise(SIGABRT).\r
191\r
192 @sa signal.h\r
193**/\r
d7ce7006 194void abort(void) __noreturn;\r
2aa62f2b 195\r
196/** The atexit function registers the function pointed to by func, to be\r
197 called without arguments at normal program termination.\r
198\r
199 The implementation supports the registration of up to 32 functions.\r
200\r
61403bd7 201 @param[in] Handler Pointer to the function to register as one of the\r
202 routines to call at application exit time.\r
203\r
2aa62f2b 204 @return The atexit function returns zero if the registration succeeds,\r
205 nonzero if it fails.\r
206**/\r
61403bd7 207int atexit(void (*Handler)(void));\r
2aa62f2b 208\r
209/** The exit function causes normal program termination to occur. If more than\r
210 one call to the exit function is executed by a program,\r
211 the behavior is undefined.\r
212\r
213 First, all functions registered by the atexit function are called, in the\r
214 reverse order of their registration, except that a function is called\r
215 after any previously registered functions that had already been called at\r
216 the time it was registered. If, during the call to any such function, a\r
217 call to the longjmp function is made that would terminate the call to the\r
218 registered function, the behavior is undefined.\r
219\r
220 Next, all open streams with unwritten buffered data are flushed, all open\r
221 streams are closed, and all files created by the tmpfile function\r
222 are removed.\r
223\r
61403bd7 224 Finally, control is returned to the host environment.\r
225\r
226 @param[in] status A value to be returned when the application exits.\r
d7ce7006 227\r
61403bd7 228 @return If the value of status is zero, or EXIT_SUCCESS, status is\r
229 returned unchanged. If the value of status is EXIT_FAILURE,\r
230 RETURN_ABORTED is returned. Otherwise, status is returned unchanged.\r
2aa62f2b 231**/\r
232void exit(int status) __noreturn;\r
233\r
234/** The _Exit function causes normal program termination to occur and control\r
235 to be returned to the host environment.\r
236\r
237 No functions registered by the atexit function or signal handlers\r
238 registered by the signal function are called. Open streams with unwritten\r
239 buffered data are not flushed, open streams are not closed, and temporary\r
240 files are not removed by abort.\r
241\r
242 The status returned to the host environment is determined in the same way\r
243 as for the exit function.\r
61403bd7 244\r
245 @param[in] status A value to be returned when the application exits.\r
246\r
247 @return If the value of status is zero, or EXIT_SUCCESS, status is\r
248 returned unchanged. If the value of status is EXIT_FAILURE,\r
249 RETURN_ABORTED is returned. Otherwise, status is returned unchanged.\r
2aa62f2b 250**/\r
d7ce7006 251void _Exit(int status) __noreturn;\r
2aa62f2b 252\r
253/** The getenv function searches an environment list, provided by the host\r
254 environment, for a string that matches the string pointed to by name. The\r
255 set of environment names and the method for altering the environment list\r
256 are determined by the underlying UEFI Shell implementation.\r
257\r
61403bd7 258 @param[in] name Pointer to a string naming the environment variable to retrieve.\r
259\r
2aa62f2b 260 @return The getenv function returns a pointer to a string associated with\r
261 the matched list member. The string pointed to shall not be\r
262 modified by the program, but may be overwritten by a subsequent\r
263 call to the getenv function. If the specified name cannot be\r
264 found, a null pointer is returned.\r
265**/\r
266char *getenv(const char *name);\r
267\r
61403bd7 268/** Add or update a variable in the environment list.\r
53e1e5c6 269\r
61403bd7 270 @param[in] name Address of a zero terminated name string.\r
271 @param[in] value Address of a zero terminated value string.\r
272 @param[in] rewrite TRUE allows overwriting existing values.\r
53e1e5c6 273\r
61403bd7 274 @retval 0 Returns 0 upon success.\r
275 @retval -1 Returns -1 upon failure, sets errno with more information.\r
53e1e5c6 276**/\r
277int\r
278setenv (\r
279 register const char * name,\r
280 register const char * value,\r
281 int rewrite\r
282 );\r
283\r
2aa62f2b 284/** If string is a null pointer, the system function determines whether the\r
285 host environment has a command processor. If string is not a null pointer,\r
286 the system function passes the string pointed to by string to that command\r
287 processor to be executed in a manner which the implementation shall\r
288 document; this might then cause the program calling system to behave in a\r
289 non-conforming manner or to terminate.\r
290\r
61403bd7 291 @param[in] string Pointer to the command string to be executed.\r
292\r
2aa62f2b 293 @return If the argument is a null pointer, the system function returns\r
294 nonzero only if a command processor is available. If the argument\r
295 is not a null pointer, and the system function does return, it\r
296 returns an implementation-defined value.\r
297**/\r
298int system(const char *string);\r
299\r
300\r
301/* ################ Integer arithmetic functions ######################## */\r
302\r
303/** Computes the absolute value of an integer j.\r
304\r
61403bd7 305 @param[in] j The value to find the absolute value of.\r
306\r
2aa62f2b 307 @return The absolute value of j.\r
308**/\r
309int abs(int j);\r
310\r
61403bd7 311/** Computes the absolute value of a long integer j.\r
312\r
313 @param[in] j The value to find the absolute value of.\r
2aa62f2b 314\r
315 @return The absolute value of j.\r
316**/\r
317long labs(long j);\r
318\r
61403bd7 319/** Computes the absolute value of a long long integer j.\r
320\r
321 @param[in] j The value to find the absolute value of.\r
2aa62f2b 322\r
323 @return The absolute value of j.\r
324**/\r
325long long\r
326 llabs(long long j);\r
327\r
328/** Computes numer / denom and numer % denom in a single operation.\r
329\r
61403bd7 330 @param[in] numer The numerator for the division.\r
331 @param[in] denom The denominator for the division.\r
332\r
2aa62f2b 333 @return Returns a structure of type div_t, comprising both the\r
334 quotient and the remainder.\r
335**/\r
336div_t div(int numer, int denom);\r
337\r
338/** Computes numer / denom and numer % denom in a single operation.\r
339\r
61403bd7 340 @param[in] numer The numerator for the division.\r
341 @param[in] denom The denominator for the division.\r
342\r
2aa62f2b 343 @return Returns a structure of type ldiv_t, comprising both the\r
344 quotient and the remainder.\r
345**/\r
346ldiv_t ldiv(long numer, long denom);\r
347\r
348/** Computes numer / denom and numer % denom in a single operation.\r
349\r
61403bd7 350 @param[in] numer The numerator for the division.\r
351 @param[in] denom The denominator for the division.\r
352\r
2aa62f2b 353 @return Returns a structure of type lldiv_t, comprising both the\r
354 quotient and the remainder.\r
355**/\r
356lldiv_t lldiv(long long numer, long long denom);\r
357\r
358/* ############ Integer Numeric conversion functions #################### */\r
359\r
360/** The atoi function converts the initial portion of the string pointed to by\r
361 nptr to int representation. Except for the behavior on error, it is\r
362 equivalent to:\r
363 - atoi: (int)strtol(nptr, (char **)NULL, 10)\r
364\r
61403bd7 365 @param[in] nptr Pointer to the string to be converted.\r
366\r
367 @return The atoi function returns the converted value.\r
2aa62f2b 368**/\r
369int atoi(const char *nptr);\r
370\r
371/** The atol function converts the initial portion of the string pointed to by\r
372 nptr to long int representation. Except for the behavior on error, it is\r
373 equivalent to:\r
374 - atol: strtol(nptr, (char **)NULL, 10)\r
375\r
61403bd7 376 @param[in] nptr Pointer to the string to be converted.\r
377\r
378 @return The atol function returns the converted value.\r
2aa62f2b 379**/\r
380long atol(const char *nptr);\r
381\r
382/** The atoll function converts the initial portion of the string pointed to by\r
383 nptr to long long int representation. Except for the behavior on error, it\r
384 is equivalent to:\r
385 - atoll: strtoll(nptr, (char **)NULL, 10)\r
386\r
61403bd7 387 @param[in] nptr Pointer to the string to be converted.\r
388\r
389 @return The atoll function returns the converted value.\r
2aa62f2b 390**/\r
391long long\r
392 atoll(const char *nptr);\r
393\r
394/** The strtol, strtoll, strtoul, and strtoull functions convert the initial\r
395 portion of the string pointed to by nptr to long int, long long int,\r
396 unsigned long int, and unsigned long long int representation, respectively.\r
397 First, they decompose the input string into three parts: an initial,\r
398 possibly empty, sequence of white-space characters (as specified by the\r
399 isspace function), a subject sequence resembling an integer represented in\r
400 some radix determined by the value of base, and a final string of one or\r
401 more unrecognized characters, including the terminating null character of\r
402 the input string. Then, they attempt to convert the subject sequence to an\r
403 integer, and return the result.\r
404\r
405 If the value of base is zero, the expected form of the subject sequence is\r
61403bd7 406 that of an integer constant, optionally preceded\r
2aa62f2b 407 by a plus or minus sign, but not including an integer suffix. If the value\r
408 of base is between 2 and 36 (inclusive), the expected form of the subject\r
409 sequence is a sequence of letters and digits representing an integer with\r
410 the radix specified by base, optionally preceded by a plus or minus sign,\r
411 but not including an integer suffix. The letters from a (or A) through z\r
412 (or Z) are ascribed the values 10 through 35; only letters and digits whose\r
413 ascribed values are less than that of base are permitted. If the value of\r
414 base is 16, the characters 0x or 0X may optionally precede the sequence of\r
415 letters and digits, following the sign if present.\r
416\r
417 The subject sequence is defined as the longest initial subsequence of the\r
418 input string, starting with the first non-white-space character, that is of\r
419 the expected form. The subject sequence contains no characters if the input\r
420 string is empty or consists entirely of white space, or if the first\r
421 non-white-space character is other than a sign or a permissible letter or digit.\r
422\r
423 If the subject sequence has the expected form and the value of base is\r
424 zero, the sequence of characters starting with the first digit is\r
425 interpreted as an integer constant. If the subject sequence has the\r
426 expected form and the value of base is between 2 and 36, it is used as the\r
427 base for conversion, ascribing to each letter its value as given above. If\r
428 the subject sequence begins with a minus sign, the value resulting from the\r
429 conversion is negated (in the return type). A pointer to the final string\r
430 is stored in the object pointed to by endptr, provided that endptr is\r
431 not a null pointer.\r
432\r
433 In other than the "C" locale, additional locale-specific subject sequence\r
434 forms may be accepted.\r
435\r
436 If the subject sequence is empty or does not have the expected form, no\r
437 conversion is performed; the value of nptr is stored in the object pointed\r
438 to by endptr, provided that endptr is not a null pointer.\r
439\r
61403bd7 440 @param[in] nptr Pointer to the string to be converted.\r
441 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
442 @param[in] base The base, 0 to 36, of the number represented by the input string.\r
443\r
444 @return The strtol, strtoll, strtoul, and strtoull functions return the\r
445 converted value, if any. If no conversion could be performed, zero\r
446 is returned. If the correct value is outside the range of\r
447 representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX,\r
448 ULONG_MAX, or ULLONG_MAX is returned (according to the return type\r
449 and sign of the value, if any), and the value of the macro ERANGE\r
450 is stored in errno.\r
2aa62f2b 451**/\r
452long strtol(const char * __restrict nptr, char ** __restrict endptr, int base);\r
453\r
454/** The strtoul function converts the initial portion of the string pointed to\r
455 by nptr to unsigned long int representation.\r
456\r
457 See the description for strtol for more information.\r
458\r
61403bd7 459 @param[in] nptr Pointer to the string to be converted.\r
460 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
461 @param[in] base The base, 0 to 36, of the number represented by the input string.\r
462\r
463 @return The strtoul function returns the converted value, if any. If no\r
464 conversion could be performed, zero is returned. If the correct\r
465 value is outside the range of representable values, ULONG_MAX is\r
466 returned and the value of the macro ERANGE is stored in errno.\r
2aa62f2b 467**/\r
468unsigned long\r
469 strtoul(const char * __restrict nptr, char ** __restrict endptr, int base);\r
470\r
471/** The strtoll function converts the initial portion of the string pointed to\r
472 by nptr to long long int representation.\r
473\r
474 See the description for strtol for more information.\r
475\r
61403bd7 476 @param[in] nptr Pointer to the string to be converted.\r
477 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
478 @param[in] base The base, 0 to 36, of the number represented by the input string.\r
479\r
480 @return The strtoll function returns the converted value, if any. If no\r
481 conversion could be performed, zero is returned. If the correct\r
482 value is outside the range of representable values, LLONG_MIN or\r
483 LLONG_MAX is returned (according to the sign of the value, if any),\r
484 and the value of the macro ERANGE is stored in errno.\r
2aa62f2b 485**/\r
486long long\r
487 strtoll(const char * __restrict nptr, char ** __restrict endptr, int base);\r
488\r
489/** The strtoull function converts the initial portion of the string pointed to\r
490 by nptr to unsigned long long int representation.\r
491\r
492 See the description for strtol for more information.\r
493\r
61403bd7 494 @param[in] nptr Pointer to the string to be converted.\r
495 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
496 @param[in] base The base, 0 to 36, of the number represented by the input string.\r
497\r
498 @return The strtoull function returns the converted value, if any. If no\r
499 conversion could be performed, zero is returned. If the correct\r
500 value is outside the range of representable values, ULLONG_MAX is\r
501 returned and the value of the macro ERANGE is stored in errno.\r
2aa62f2b 502**/\r
503unsigned long long\r
504 strtoull(const char * __restrict nptr, char ** __restrict endptr, int base);\r
505\r
506/* ######### Floating-point Numeric conversion functions ################ */\r
507\r
61403bd7 508/** Convert the initial part of a string to double representation.\r
509\r
510 @param[in] nptr Pointer to the string to be converted.\r
2aa62f2b 511\r
61403bd7 512 @return The floating-point value representing the string nptr.\r
2aa62f2b 513**/\r
61403bd7 514double atof(const char *nptr);\r
515\r
516/** @{\r
517 The strtod, strtof, and strtold functions convert the initial portion of\r
518 the string pointed to by nptr to double, float, and long double\r
519 representation, respectively. First, they decompose the input string into\r
520 three parts: an initial, possibly empty, sequence of white-space characters\r
521 (as specified by the isspace function), a subject sequence resembling a\r
522 floating-point constant or representing an infinity or NaN; and a final\r
523 string of one or more unrecognized characters, including the terminating\r
524 null character of the input string. Then, they attempt to convert the\r
525 subject sequence to a floating-point number, and return the result.\r
526*/\r
527\r
528/** Convert a string to a double and point to the character after the last converted.\r
2aa62f2b 529\r
61403bd7 530 @param[in] nptr Pointer to the string to be converted.\r
531 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
2aa62f2b 532\r
61403bd7 533 @return A floating-point value representing the string nptr.\r
534 A pointer to the final string is stored in the object pointed to\r
535 by endptr, provided that endptr is not a null pointer.\r
536 If the subject sequence is empty or does not have the expected\r
537 form, no conversion is performed; the value of nptr is stored in\r
538 the object pointed to by endptr, provided that endptr is not a null pointer.\r
2aa62f2b 539**/\r
540double strtod(const char * __restrict nptr, char ** __restrict endptr);\r
541\r
61403bd7 542/** Convert a string to a float and point to the character after the last converted.\r
2aa62f2b 543\r
61403bd7 544 @param[in] nptr Pointer to the string to be converted.\r
545 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
546\r
547 @return A floating-point value representing the string nptr.\r
548 A pointer to the final string is stored in the object pointed to\r
549 by endptr, provided that endptr is not a null pointer.\r
550 If the subject sequence is empty or does not have the expected\r
551 form, no conversion is performed; the value of nptr is stored in\r
552 the object pointed to by endptr, provided that endptr is not a null pointer.\r
2aa62f2b 553**/\r
554float strtof(const char * __restrict nptr, char ** __restrict endptr);\r
555\r
61403bd7 556/** Convert a string to a long double and point to the character after the last converted.\r
557\r
558 @param[in] nptr Pointer to the string to be converted.\r
559 @param[out] endptr If not NULL, points to an object to receive a pointer to the final string.\r
2aa62f2b 560\r
61403bd7 561 @return A floating-point value representing the string nptr.\r
562 A pointer to the final string is stored in the object pointed to\r
563 by endptr, provided that endptr is not a null pointer.\r
564 If the subject sequence is empty or does not have the expected\r
565 form, no conversion is performed; the value of nptr is stored in\r
566 the object pointed to by endptr, provided that endptr is not a null pointer.\r
2aa62f2b 567**/\r
568long double\r
569 strtold(const char * __restrict nptr, char ** __restrict endptr);\r
61403bd7 570/*@}*/\r
2aa62f2b 571\r
572/* ################ Pseudo-random sequence generation functions ######### */\r
573\r
574/** The rand function computes a sequence of pseudo-random integers in the\r
575 range 0 to RAND_MAX.\r
576\r
577 @return The rand function returns a pseudo-random integer.\r
578**/\r
579int rand(void);\r
580\r
581/** The srand function uses the argument as a seed for a new sequence of\r
582 pseudo-random numbers to be returned by subsequent calls to rand.\r
583\r
584 If srand is then called with the same seed value, the sequence of\r
585 pseudo-random numbers shall be repeated. If rand is called before any calls\r
586 to srand have been made, the same sequence shall be generated as when srand\r
587 is first called with a seed value of 1.\r
61403bd7 588\r
589 @param[in] seed The value used to "seed" the random number generator with.\r
2aa62f2b 590**/\r
591void srand(unsigned seed);\r
592\r
593/* ################ Memory management functions ######################### */\r
594\r
595/** The calloc function allocates space for an array of Num objects, each of\r
596 whose size is Size. The space is initialized to all bits zero.\r
597\r
61403bd7 598 @param[in] Num The number of objects to allocate space for.\r
599 @param[in] Size The size, in bytes, of each object.\r
600\r
2aa62f2b 601 @return NULL is returned if the space could not be allocated and errno\r
602 contains the cause. Otherwise, a pointer to an 8-byte aligned\r
603 region of the requested size is returned.\r
604**/\r
605void *calloc(size_t Num, size_t Size);\r
606\r
607/** The free function causes the space pointed to by Ptr to be deallocated,\r
608 that is, made available for further allocation.\r
609\r
610 If Ptr is a null pointer, no action occurs. Otherwise, if the argument\r
611 does not match a pointer earlier returned by the calloc, malloc, or realloc\r
612 function, or if the space has been deallocated by a call to free or\r
613 realloc, the behavior is undefined.\r
614\r
615 @param Ptr Pointer to a previously allocated region of memory to be freed.\r
2aa62f2b 616**/\r
61403bd7 617void free(void *Ptr);\r
2aa62f2b 618\r
619/** The malloc function allocates space for an object whose size is specified\r
620 by size and whose value is indeterminate.\r
621\r
622 This implementation uses the UEFI memory allocation boot services to get a\r
623 region of memory that is 8-byte aligned and of the specified size. The\r
624 region is allocated with type EfiLoaderData.\r
625\r
61403bd7 626 @param Size Size, in bytes, of the region to allocate.\r
2aa62f2b 627\r
628 @return NULL is returned if the space could not be allocated and errno\r
629 contains the cause. Otherwise, a pointer to an 8-byte aligned\r
630 region of the requested size is returned.<BR>\r
631 If NULL is returned, errno may contain:\r
632 - EINVAL: Requested Size is zero.\r
633 - ENOMEM: Memory could not be allocated.\r
634**/\r
61403bd7 635void *malloc(size_t Size);\r
2aa62f2b 636\r
637/** The realloc function changes the size of the object pointed to by Ptr to\r
638 the size specified by NewSize.\r
639\r
640 The contents of the object are unchanged up to the lesser of the new and\r
641 old sizes. If the new size is larger, the value of the newly allocated\r
642 portion of the object is indeterminate.\r
643\r
644 If Ptr is a null pointer, the realloc function behaves like the malloc\r
645 function for the specified size.\r
646\r
647 If Ptr does not match a pointer earlier returned by the calloc, malloc, or\r
648 realloc function, or if the space has been deallocated by a call to the free\r
649 or realloc function, the behavior is undefined.\r
650\r
651 If the space cannot be allocated, the object pointed to by Ptr is unchanged.\r
652\r
653 If NewSize is zero and Ptr is not a null pointer, the object it points to\r
654 is freed.\r
655\r
656 This implementation uses the UEFI memory allocation boot services to get a\r
657 region of memory that is 8-byte aligned and of the specified size. The\r
658 region is allocated with type EfiLoaderData.\r
659\r
660 @param Ptr Pointer to a previously allocated region of memory to be resized.\r
661 @param NewSize Size, in bytes, of the new object to allocate space for.\r
662\r
663 @return NULL is returned if the space could not be allocated and errno\r
664 contains the cause. Otherwise, a pointer to an 8-byte aligned\r
665 region of the requested size is returned. If NewSize is zero,\r
666 NULL is returned and errno will be unchanged.\r
667**/\r
668void *realloc(void *Ptr, size_t NewSize);\r
669\r
670/* ################ Searching and Sorting utilities ##################### */\r
671\r
61403bd7 672/** The bsearch function searches an array of Nmemb objects, the initial\r
673 element of which is pointed to by Base, for an element that matches the\r
674 object pointed to by Key. The size of each element of the array is\r
675 specified by Size.\r
2aa62f2b 676\r
61403bd7 677 The comparison function pointed to by Compar is called with two arguments\r
678 that point to the Key object and to an array element, in that order. The\r
2aa62f2b 679 function returns an integer less than, equal to, or greater than zero if\r
61403bd7 680 the Key object is considered, respectively, to be less than, to match, or\r
2aa62f2b 681 to be greater than the array element. The array consists of: all the\r
682 elements that compare less than, all the elements that compare equal to,\r
683 and all the elements that compare greater than the key object,\r
684 in that order.\r
685\r
61403bd7 686 @param[in] Key Pointer to the object to search for.\r
687 @param[in] Base Pointer to the first element of an array to search.\r
688 @param[in] Nmemb Number of objects in the search array.\r
689 @param[in] Size The size of each object in the search array.\r
690 @param[in] Compar Pointer to the function used to compare two objects.\r
691\r
692 @return The bsearch function returns a pointer to a matching element of the\r
693 array, or a null pointer if no match is found. If two elements\r
694 compare as equal, which element is matched is unspecified.\r
2aa62f2b 695**/\r
61403bd7 696void *bsearch( const void *Key, const void *Base,\r
697 size_t Nmemb, size_t Size,\r
698 int (*Compar)(const void *, const void *)\r
699 );\r
2aa62f2b 700\r
61403bd7 701/** The qsort function sorts an array of Nmemb objects, the initial element of\r
702 which is pointed to by Base. The size of each object is specified by Size.\r
2aa62f2b 703\r
704 The contents of the array are sorted into ascending order according to a\r
61403bd7 705 comparison function pointed to by Compar, which is called with two\r
2aa62f2b 706 arguments that point to the objects being compared. The function shall\r
707 return an integer less than, equal to, or greater than zero if the first\r
708 argument is considered to be respectively less than, equal to, or greater\r
709 than the second.\r
710\r
711 If two elements compare as equal, their order in the resulting sorted array\r
712 is unspecified.\r
61403bd7 713\r
714 @param[in,out] Base Pointer to the first element of an array to sort.\r
715 @param[in] Nmemb Number of objects in the array.\r
716 @param[in] Size The size of each object in the array.\r
717 @param[in] Compar Pointer to the function used to compare two objects.\r
2aa62f2b 718**/\r
61403bd7 719void qsort( void *base, size_t nmemb, size_t size,\r
720 int (*compar)(const void *, const void *));\r
2aa62f2b 721\r
722/* ################ Multibyte/wide character conversion functions ####### */\r
723\r
53e1e5c6 724/** Determine the number of bytes comprising a multibyte character.\r
2aa62f2b 725\r
61403bd7 726 If S is not a null pointer, the mblen function determines the number of bytes\r
727 contained in the multibyte character pointed to by S. Except that the\r
53e1e5c6 728 conversion state of the mbtowc function is not affected, it is equivalent to\r
61403bd7 729 mbtowc((wchar_t *)0, S, N);\r
53e1e5c6 730\r
61403bd7 731 @param[in] S NULL to query whether multibyte characters have\r
732 state-dependent encodings. Otherwise, points to a\r
733 multibyte character.\r
734 @param[in] N The maximum number of bytes in a multibyte character.\r
53e1e5c6 735\r
61403bd7 736 @return If S is a null pointer, the mblen function returns a nonzero or\r
53e1e5c6 737 zero value, if multibyte character encodings, respectively, do\r
61403bd7 738 or do not have state-dependent encodings. If S is not a null\r
739 pointer, the mblen function either returns 0 (if S points to the\r
53e1e5c6 740 null character), or returns the number of bytes that are contained\r
61403bd7 741 in the multibyte character (if the next N or fewer bytes form a\r
53e1e5c6 742 valid multibyte character), or returns -1 (if they do not form a\r
743 valid multibyte character).\r
2aa62f2b 744**/\r
61403bd7 745int mblen(const char *S, size_t N);\r
2aa62f2b 746\r
53e1e5c6 747/** Convert a multibyte character into a wide character.\r
2aa62f2b 748\r
61403bd7 749 If S is not a null pointer, the mbtowc function inspects at most N bytes\r
750 beginning with the byte pointed to by S to determine the number of bytes\r
53e1e5c6 751 needed to complete the next multibyte character (including any shift\r
752 sequences). If the function determines that the next multibyte character\r
753 is complete and valid, it determines the value of the corresponding wide\r
61403bd7 754 character and then, if Pwc is not a null pointer, stores that value in\r
755 the object pointed to by Pwc. If the corresponding wide character is the\r
53e1e5c6 756 null wide character, the function is left in the initial conversion state.\r
757\r
61403bd7 758 @param[out] Pwc Pointer to a wide-character object to receive the converted character.\r
759 @param[in] S Pointer to a multibyte character to convert.\r
760 @param[in] N Maximum number of bytes in a multibyte character.\r
53e1e5c6 761\r
61403bd7 762 @return If S is a null pointer, the mbtowc function returns a nonzero or\r
53e1e5c6 763 zero value, if multibyte character encodings, respectively, do\r
61403bd7 764 or do not have state-dependent encodings. If S is not a null\r
765 pointer, the mbtowc function either returns 0 (if S points to\r
53e1e5c6 766 the null character), or returns the number of bytes that are\r
61403bd7 767 contained in the converted multibyte character (if the next N or\r
53e1e5c6 768 fewer bytes form a valid multibyte character), or returns -1\r
769 (if they do not form a valid multibyte character).\r
770\r
61403bd7 771 In no case will the value returned be greater than N or the value\r
53e1e5c6 772 of the MB_CUR_MAX macro.\r
2aa62f2b 773**/\r
61403bd7 774int mbtowc(wchar_t * __restrict Pwc, const char * __restrict S, size_t N);\r
2aa62f2b 775\r
61403bd7 776/** Convert a wide character into a multibyte character.\r
53e1e5c6 777\r
61403bd7 778 The wctomb function determines the number of bytes needed to represent the\r
779 multibyte character corresponding to the wide character given by WC\r
780 (including any shift sequences), and stores the multibyte character\r
781 representation in the array whose first element is pointed to by S (if S is\r
782 not a null pointer). At most MB_CUR_MAX characters are stored. If WC is a\r
783 null wide character, a null byte is stored, preceded by any shift sequence\r
784 needed to restore the initial shift state, and the function is left in the\r
785 initial conversion state.\r
2aa62f2b 786\r
61403bd7 787 @param[out] S Pointer to the object to receive the converted multibyte character.\r
788 @param[in] WC Wide character to be converted.\r
53e1e5c6 789\r
61403bd7 790 @return If S is a null pointer, the wctomb function returns a nonzero or\r
791 zero value, if multibyte character encodings, respectively, do or\r
792 do not have state-dependent encodings. If S is not a null pointer,\r
793 the wctomb function returns -1 if the value of WC does not\r
794 correspond to a valid multibyte character, or returns the number\r
795 of bytes that are contained in the multibyte character\r
796 corresponding to the value of WC.\r
53e1e5c6 797\r
61403bd7 798 In no case will the value returned be greater than the value of\r
799 the MB_CUR_MAX macro.\r
2aa62f2b 800**/\r
61403bd7 801int wctomb(char *S, wchar_t WC);\r
2aa62f2b 802\r
803/* ################ Multibyte/wide string conversion functions ########## */\r
804\r
53e1e5c6 805/** Convert a multibyte character string into a wide-character string.\r
806\r
807 The mbstowcs function converts a sequence of multibyte characters that\r
61403bd7 808 begins in the initial shift state from the array pointed to by Src into\r
53e1e5c6 809 a sequence of corresponding wide characters and stores not more than limit\r
61403bd7 810 wide characters into the array pointed to by Dest. No multibyte\r
53e1e5c6 811 characters that follow a null character (which is converted into a null\r
812 wide character) will be examined or converted. Each multibyte character\r
813 is converted as if by a call to the mbtowc function, except that the\r
814 conversion state of the mbtowc function is not affected.\r
815\r
61403bd7 816 No more than Limit elements will be modified in the array pointed to by Dest.\r
53e1e5c6 817 If copying takes place between objects that overlap,\r
818 the behavior is undefined.\r
819\r
61403bd7 820 @param[out] Dest Pointer to the array to receive the converted string.\r
821 @param[in] Src Pointer to the string to be converted.\r
822 @param[in] Limit Maximum number of elements to be written to Dest.\r
2aa62f2b 823\r
61403bd7 824 @return If an invalid multibyte character is encountered, the mbstowcs\r
825 function returns (size_t)(-1). Otherwise, the mbstowcs function\r
826 returns the number of array elements modified, not including a\r
827 terminating null wide character, if any.\r
2aa62f2b 828**/\r
61403bd7 829size_t mbstowcs(wchar_t * __restrict Dest, const char * __restrict Src, size_t Limit);\r
2aa62f2b 830\r
53e1e5c6 831/** Convert a wide-character string into a multibyte character string.\r
2aa62f2b 832\r
53e1e5c6 833 The wcstombs function converts a sequence of wide characters from the\r
61403bd7 834 array pointed to by Src into a sequence of corresponding multibyte\r
53e1e5c6 835 characters that begins in the initial shift state, and stores these\r
61403bd7 836 multibyte characters into the array pointed to by Dest, stopping if a\r
837 multibyte character would exceed the limit of Limit total bytes or if a\r
53e1e5c6 838 null character is stored. Each wide character is converted as if by\r
839 a call to the wctomb function, except that the conversion state of\r
840 the wctomb function is not affected.\r
841\r
61403bd7 842 No more than Limit bytes will be modified in the array pointed to by Dest.\r
53e1e5c6 843 If copying takes place between objects that overlap,\r
844 the behavior is undefined.\r
845\r
61403bd7 846 @param[out] Dest Pointer to the array to receive the converted string.\r
847 @param[in] Src Pointer to the string to be converted.\r
848 @param[in] Limit Maximum number of elements to be written to Dest.\r
849\r
850 @return If a wide character is encountered that does not correspond to a\r
851 valid multibyte character, the wcstombs function returns\r
852 (size_t)(-1). Otherwise, the wcstombs function returns the number\r
853 of bytes modified, not including a terminating null character,\r
854 if any.\r
2aa62f2b 855**/\r
61403bd7 856size_t wcstombs(char * __restrict Dest, const wchar_t * __restrict Src, size_t Limit);\r
857\r
858/* ################ Miscelaneous functions for *nix compatibility ########## */\r
2aa62f2b 859\r
61403bd7 860/** The realpath() function shall derive, from the pathname pointed to by\r
861 file_name, an absolute pathname that names the same file, whose resolution\r
862 does not involve '.', '..', or symbolic links. The generated pathname shall\r
863 be stored as a null-terminated string, up to a maximum of {PATH_MAX} bytes,\r
864 in the buffer pointed to by resolved_name.\r
d7ce7006 865\r
61403bd7 866 If resolved_name is a null pointer, the behavior of realpath() is\r
867 implementation-defined.\r
d7ce7006 868\r
61403bd7 869 @param[in] file_name The filename to convert.\r
870 @param[in,out] resolved_name The resultant name.\r
d7ce7006 871\r
61403bd7 872 @retval NULL An error occured.\r
873 @retval resolved_name.\r
d7ce7006 874**/\r
875char * realpath(char *file_name, char *resolved_name);\r
876\r
61403bd7 877/** The getprogname() function returns the name of the program. If the name\r
878 has not been set yet, it will return NULL.\r
d7ce7006 879\r
61403bd7 880 @return The getprogname function returns NULL if the program's name has not\r
881 been set, otherwise it returns the name of the program.\r
d7ce7006 882**/\r
883const char * getprogname(void);\r
884\r
61403bd7 885/** The setprogname() function sets the name of the program.\r
d7ce7006 886\r
61403bd7 887 @param[in] progname The name of the program. This memory must be retained\r
888 by the caller until no calls to "getprogname" will be\r
889 called.\r
d7ce7006 890**/\r
891void setprogname(const char *progname);\r
892\r
2aa62f2b 893__END_DECLS\r
894\r
895#endif /* _STDLIB_H */\r