.TH "stdlib.h" 3avr "Fri Nov 24 2023 23:59:10" "Version 2.0.0" "avr-libc" \" -*- nroff -*- .ad l .nh .SH NAME stdlib.h .SH SYNOPSIS .br .PP .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBdiv_t\fP" .br .ti -1c .RI "struct \fBldiv_t\fP" .br .in -1c .SS "Macros" .in +1c .ti -1c .RI "#define \fBRAND_MAX\fP 0x7FFF" .br .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef int(* \fB__compar_fn_t\fP) (const void *, const void *)" .br .in -1c .SS "Functions" .in +1c .ti -1c .RI "void \fBabort\fP (void) __ATTR_NORETURN__" .br .ti -1c .RI "int \fBabs\fP (int __i)" .br .ti -1c .RI "long \fBlabs\fP (long __i)" .br .ti -1c .RI "void * \fBbsearch\fP (const void *__key, const void *__base, size_t __nmemb, size_t __size, int(*__compar)(const void *, const void *))" .br .ti -1c .RI "\fBdiv_t\fP \fBdiv\fP (int __num, int __denom) __asm__('__divmodhi4')" .br .ti -1c .RI "\fBldiv_t\fP \fBldiv\fP (long __num, long __denom) __asm__('__divmodsi4')" .br .ti -1c .RI "void \fBqsort\fP (void *__base, size_t __nmemb, size_t __size, \fB__compar_fn_t\fP __compar)" .br .ti -1c .RI "long \fBstrtol\fP (const char *__nptr, char **__endptr, int __base)" .br .ti -1c .RI "unsigned long \fBstrtoul\fP (const char *__nptr, char **__endptr, int __base)" .br .ti -1c .RI "long \fBatol\fP (const char *__s) __ATTR_PURE__" .br .ti -1c .RI "int \fBatoi\fP (const char *__s) __ATTR_PURE__" .br .ti -1c .RI "void \fBexit\fP (int __status) __ATTR_NORETURN__" .br .ti -1c .RI "void * \fBmalloc\fP (size_t __size) __ATTR_MALLOC__" .br .ti -1c .RI "void \fBfree\fP (void *__ptr)" .br .ti -1c .RI "void * \fBcalloc\fP (size_t __nele, size_t __size) __ATTR_MALLOC__" .br .ti -1c .RI "void * \fBrealloc\fP (void *__ptr, size_t __size) __ATTR_MALLOC__" .br .ti -1c .RI "double \fBstrtod\fP (const char *__nptr, char **__endptr)" .br .ti -1c .RI "double \fBatof\fP (const char *__nptr)" .br .ti -1c .RI "int \fBrand\fP (void)" .br .ti -1c .RI "void \fBsrand\fP (unsigned int __seed)" .br .ti -1c .RI "int \fBrand_r\fP (unsigned long *__ctx)" .br .in -1c .SS "Variables" .in +1c .ti -1c .RI "size_t \fB__malloc_margin\fP" .br .ti -1c .RI "char * \fB__malloc_heap_start\fP" .br .ti -1c .RI "char * \fB__malloc_heap_end\fP" .br .in -1c .SS "Non-standard (i\&.e\&. non-ISO C) functions\&." .in +1c .ti -1c .RI "#define \fBRANDOM_MAX\fP 0x7FFFFFFF" .br .ti -1c .RI "char * \fBitoa\fP (int val, char *s, int radix)" .br .ti -1c .RI "char * \fBltoa\fP (long val, char *s, int radix)" .br .ti -1c .RI "char * \fButoa\fP (unsigned int val, char *s, int radix)" .br .ti -1c .RI "char * \fBultoa\fP (unsigned long val, char *s, int radix)" .br .ti -1c .RI "long \fBrandom\fP (void)" .br .ti -1c .RI "void \fBsrandom\fP (unsigned long __seed)" .br .ti -1c .RI "long \fBrandom_r\fP (unsigned long *__ctx)" .br .in -1c .SS "Conversion functions for double arguments\&." Note that these functions are not located in the default library, \fClibc\&.a\fP, but in the mathematical library, \fClibm\&.a\fP\&. So when linking the application, the \fC-lm\fP option needs to be specified\&. .in +1c .ti -1c .RI "#define \fBDTOSTR_ALWAYS_SIGN\fP 0x01 /* put '+' or ' ' for positives */" .br .ti -1c .RI "#define \fBDTOSTR_PLUS_SIGN\fP 0x02 /* put '+' rather than ' ' */" .br .ti -1c .RI "#define \fBDTOSTR_UPPERCASE\fP 0x04 /* put 'E' rather 'e' */" .br .ti -1c .RI "#define \fBEXIT_SUCCESS\fP 0" .br .ti -1c .RI "#define \fBEXIT_FAILURE\fP 1" .br .ti -1c .RI "char * \fBdtostre\fP (double __val, char *__s, unsigned char __prec, unsigned char __flags)" .br .ti -1c .RI "char * \fBdtostrf\fP (double __val, signed char __width, unsigned char __prec, char *__s)" .br .in -1c .SH "Macro Definition Documentation" .PP .SS "#define RAND_MAX 0x7FFF" Highest number that can be generated by \fBrand()\fP\&. .SH "Typedef Documentation" .PP .SS "typedef int(* __compar_fn_t) (const void *, const void *)" Comparision function type for \fBqsort()\fP, just for convenience\&. .SH "Function Documentation" .PP .SS "void abort (void)\fC [extern]\fP" The \fBabort()\fP function causes abnormal program termination to occur\&. This realization disables interrupts and jumps to _exit() function with argument equal to 1\&. In the limited AVR environment, execution is effectively halted by entering an infinite loop\&. .SS "int abs (int __i)\fC [extern]\fP" The \fBabs()\fP function computes the absolute value of the integer \fCi\fP\&. .PP \fBNote\fP .RS 4 The \fBabs()\fP and \fBlabs()\fP functions are builtins of gcc\&. .RE .PP .SS "int atoi (const char * __s)\fC [extern]\fP" The \fBatoi()\fP function converts the initial portion of the string pointed to by \fCs\fP to integer representation\&. In contrast to .PP .PP .nf (int)strtol(s, (char **)NULL, 10); .fi .PP .PP this function does not detect overflow (\fCerrno\fP is not changed and the result value is not predictable), uses smaller memory (flash and stack) and works more quickly\&. .SS "long atol (const char * __s)\fC [extern]\fP" The \fBatol()\fP function converts the initial portion of the string pointed to by \fCs\fP to long integer representation\&. In contrast to .PP .PP .nf strtol(s, (char **)NULL, 10); .fi .PP .PP this function does not detect overflow (\fCerrno\fP is not changed and the result value is not predictable), uses smaller memory (flash and stack) and works more quickly\&. .SS "void * bsearch (const void * __key, const void * __base, size_t __nmemb, size_t __size, int(*)(const void *, const void *) __compar)\fC [extern]\fP" The \fBbsearch()\fP function searches an array of \fCnmemb\fP objects, the initial member of which is pointed to by \fCbase\fP, for a member that matches the object pointed to by \fCkey\fP\&. The size of each member of the array is specified by \fCsize\fP\&. .PP The contents of the array should be in ascending sorted order according to the comparison function referenced by \fCcompar\fP\&. The \fCcompar\fP routine is expected to have two arguments which point to the key object and to an array member, in that order, and should return an integer less than, equal to, or greater than zero if the key object is found, respectively, to be less than, to match, or be greater than the array member\&. .PP The \fBbsearch()\fP function returns a pointer to a matching member of the array, or a null pointer if no match is found\&. If two members compare as equal, which member is matched is unspecified\&. .SS "void * calloc (size_t __nele, size_t __size)\fC [extern]\fP" Allocate \fCnele\fP elements of \fCsize\fP each\&. Identical to calling \fCmalloc()\fP using \fCnele * size\fP as argument, except the allocated memory will be cleared to zero\&. .SS "\fBdiv_t\fP div (int __num, int __denom)\fC [extern]\fP" The \fBdiv()\fP function computes the value \fCnum/denom\fP and returns the quotient and remainder in a structure named \fC\fBdiv_t\fP\fP that contains two int members named \fCquot\fP and \fCrem\fP\&. .SS "void exit (int __status)\fC [extern]\fP" The \fBexit()\fP function terminates the application\&. Since there is no environment to return to, \fCstatus\fP is ignored, and code execution will eventually reach an infinite loop, thereby effectively halting all code processing\&. Before entering the infinite loop, interrupts are globally disabled\&. .PP In a C++ context, global destructors will be called before halting execution\&. .SS "void free (void * __ptr)\fC [extern]\fP" The free() function causes the allocated memory referenced by \fCptr\fP to be made available for future allocations\&. If \fCptr\fP is NULL, no action occurs\&. .SS "long labs (long __i)\fC [extern]\fP" The \fBlabs()\fP function computes the absolute value of the long integer \fCi\fP\&. .PP \fBNote\fP .RS 4 The \fBabs()\fP and \fBlabs()\fP functions are builtins of gcc\&. .RE .PP .SS "\fBldiv_t\fP ldiv (long __num, long __denom)\fC [extern]\fP" The \fBldiv()\fP function computes the value \fCnum/denom\fP and returns the quotient and remainder in a structure named \fC\fBldiv_t\fP\fP that contains two long integer members named \fCquot\fP and \fCrem\fP\&. .SS "void * malloc (size_t __size)\fC [extern]\fP" The malloc() function allocates \fCsize\fP bytes of memory\&. If malloc() fails, a NULL pointer is returned\&. .PP Note that malloc() does \fInot\fP initialize the returned memory to zero bytes\&. .PP See the chapter about \fBmalloc() usage\fP for implementation details\&. .SS "void qsort (void * __base, size_t __nmemb, size_t __size, \fB__compar_fn_t\fP __compar)\fC [extern]\fP" The \fBqsort()\fP function is a modified partition-exchange sort, or quicksort\&. .PP The \fBqsort()\fP function sorts an array of \fCnmemb\fP objects, the initial member of which is pointed to by \fCbase\fP\&. The size of each object is specified by \fCsize\fP\&. The contents of the array base are sorted in ascending order according to a comparison function pointed to by \fCcompar\fP, which requires two arguments pointing to the objects being compared\&. .PP The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second\&. .SS "int rand (void)\fC [extern]\fP" The \fBrand()\fP function computes a sequence of pseudo-random integers in the range of 0 to \fCRAND_MAX\fP (as defined by the header file <\fBstdlib\&.h\fP>)\&. .PP The \fBsrand()\fP function sets its argument \fCseed\fP as the seed for a new sequence of pseudo-random numbers to be returned by \fBrand()\fP\&. These sequences are repeatable by calling \fBsrand()\fP with the same seed value\&. .PP If no seed value is provided, the functions are automatically seeded with a value of 1\&. .PP In compliance with the C standard, these functions operate on \fCint\fP arguments\&. Since the underlying algorithm already uses 32-bit calculations, this causes a loss of precision\&. See \fC\fBrandom()\fP\fP for an alternate set of functions that retains full 32-bit precision\&. .SS "int rand_r (unsigned long * __ctx)\fC [extern]\fP" Variant of \fBrand()\fP that stores the context in the user-supplied variable located at \fCctx\fP instead of a static library variable so the function becomes re-entrant\&. .SS "void * realloc (void * __ptr, size_t __size)\fC [extern]\fP" The realloc() function tries to change the size of the region allocated at \fCptr\fP to the new \fCsize\fP value\&. It returns a pointer to the new region\&. The returned pointer might be the same as the old pointer, or a pointer to a completely different region\&. .PP The contents of the returned region up to either the old or the new size value (whatever is less) will be identical to the contents of the old region, even in case a new region had to be allocated\&. .PP It is acceptable to pass \fCptr\fP as NULL, in which case realloc() will behave identical to malloc()\&. .PP If the new memory cannot be allocated, realloc() returns NULL, and the region at \fCptr\fP will not be changed\&. .SS "void srand (unsigned int __seed)\fC [extern]\fP" Pseudo-random number generator seeding; see \fBrand()\fP\&. .SS "double strtod (const char * nptr, char ** endptr)\fC [extern]\fP" The strtod() function converts the initial portion of the string pointed to by \fInptr\fP to double representation\&. .PP The expected form of the string is an optional plus ( \fC'+'\fP ) or minus sign ( \fC'-'\fP ) followed by a sequence of digits optionally containing a decimal-point character, optionally followed by an exponent\&. An exponent consists of an \fC'E'\fP or \fC'e'\fP, followed by an optional plus or minus sign, followed by a sequence of digits\&. .PP Leading white-space characters in the string are skipped\&. .PP The strtod() function returns the converted value, if any\&. .PP If \fIendptr\fP is not \fCNULL\fP, a pointer to the character after the last character used in the conversion is stored in the location referenced by \fIendptr\fP\&. .PP If no conversion is performed, zero is returned and the value of \fInptr\fP is stored in the location referenced by \fIendptr\fP\&. .PP If the correct value would cause overflow, plus or minus \fCINFINITY\fP is returned (according to the sign of the value), and \fCERANGE\fP is stored in \fCerrno\fP\&. If the correct value would cause underflow, zero is returned and \fCERANGE\fP is stored in \fCerrno\fP\&. .SS "long strtol (const char * __nptr, char ** __endptr, int __base)\fC [extern]\fP" The \fBstrtol()\fP function converts the string in \fCnptr\fP to a long value\&. The conversion is done according to the given base, which must be between 2 and 36 inclusive, or be the special value 0\&. .PP The string may begin with an arbitrary amount of white space (as determined by \fBisspace()\fP) followed by a single optional \fC'+'\fP or \fC'-'\fP sign\&. If \fCbase\fP is zero or 16, the string may then include a \fC'0x'\fP prefix, and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is \fC'0'\fP, in which case it is taken as 8 (octal)\&. .PP The remainder of the string is converted to a long value in the obvious manner, stopping at the first character which is not a valid digit in the given base\&. (In bases above 10, the letter \fC'A'\fP in either upper or lower case represents 10, \fC'B'\fP represents 11, and so forth, with \fC'Z'\fP representing 35\&.) .PP If \fCendptr\fP is not NULL, \fBstrtol()\fP stores the address of the first invalid character in \fC*endptr\fP\&. If there were no digits at all, however, \fBstrtol()\fP stores the original value of \fCnptr\fP in \fCendptr\fP\&. (Thus, if \fC*nptr\fP is not \fC'\\0'\fP but \fC**endptr\fP is \fC'\\0'\fP on return, the entire string was valid\&.) .PP The \fBstrtol()\fP function returns the result of the conversion, unless the value would underflow or overflow\&. If no conversion could be performed, 0 is returned\&. If an overflow or underflow occurs, \fCerrno\fP is set to \fBERANGE\fP and the function return value is clamped to \fCLONG_MIN\fP or \fCLONG_MAX\fP, respectively\&. .SS "unsigned long strtoul (const char * __nptr, char ** __endptr, int __base)\fC [extern]\fP" The \fBstrtoul()\fP function converts the string in \fCnptr\fP to an unsigned long value\&. The conversion is done according to the given base, which must be between 2 and 36 inclusive, or be the special value 0\&. .PP The string may begin with an arbitrary amount of white space (as determined by \fBisspace()\fP) followed by a single optional \fC'+'\fP or \fC'-'\fP sign\&. If \fCbase\fP is zero or 16, the string may then include a \fC'0x'\fP prefix, and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is \fC'0'\fP, in which case it is taken as 8 (octal)\&. .PP The remainder of the string is converted to an unsigned long value in the obvious manner, stopping at the first character which is not a valid digit in the given base\&. (In bases above 10, the letter \fC'A'\fP in either upper or lower case represents 10, \fC'B'\fP represents 11, and so forth, with \fC'Z'\fP representing 35\&.) .PP If \fCendptr\fP is not NULL, \fBstrtoul()\fP stores the address of the first invalid character in \fC*endptr\fP\&. If there were no digits at all, however, \fBstrtoul()\fP stores the original value of \fCnptr\fP in \fCendptr\fP\&. (Thus, if \fC*nptr\fP is not \fC'\\0'\fP but \fC**endptr\fP is \fC'\\0'\fP on return, the entire string was valid\&.) .PP The \fBstrtoul()\fP function return either the result of the conversion or, if there was a leading minus sign, the negation of the result of the conversion, unless the original (non-negated) value would overflow; in the latter case, \fBstrtoul()\fP returns ULONG_MAX, and \fCerrno\fP is set to \fBERANGE\fP\&. If no conversion could be performed, 0 is returned\&. .SH "Variable Documentation" .PP .SS "char* __malloc_heap_end\fC [extern]\fP" \fCmalloc()\fP \fBtunable\fP\&. .SS "char* __malloc_heap_start\fC [extern]\fP" \fCmalloc()\fP \fBtunable\fP\&. .SS "size_t __malloc_margin\fC [extern]\fP" \fCmalloc()\fP \fBtunable\fP\&. .SH "Author" .PP Generated automatically by Doxygen for avr-libc from the source code\&.