stdlib.h - standard library definitions
#include <stdlib.h>
[CX]Some of the functionality described on this reference page extends the ISO C standard. Applications shall define the appropriate feature test macro (see XSH The Compilation Environment ) to enable the visibility of these symbols in this header.
The <stdlib.h> header shall define the following macros which shall expand to integer constant expressions:
- EXIT_FAILURE
- Unsuccessful termination for exit(); evaluates to a non-zero value.
- EXIT_SUCCESS
- Successful termination for exit(); evaluates to 0.
- {RAND_MAX}
- Maximum value returned by rand(); at least 32767.
The <stdlib.h> header shall define the following macro which shall expand to a positive integer expression with type size_t:
- {MB_CUR_MAX}
- Maximum number of bytes in a character specified by the current locale (category LC_CTYPE ).
The <stdlib.h> header shall define NULL as described in <stddef.h>.
The <stdlib.h> header shall define the following data types through typedef:
- div_t
- Structure type returned by the div() function.
- ldiv_t
- Structure type returned by the ldiv() function.
- lldiv_t
- Structure type returned by the lldiv() function.
- size_t
- As described in <stddef.h>.
- wchar_t
- As described in <stddef.h>.
[CX]
In addition, the <stdlib.h> header shall define the following symbolic constants and macros as described in <sys/wait.h>:
WEXITSTATUS
WIFEXITED
WIFSIGNALED
WIFSTOPPED
WNOHANG
WSTOPSIG
WTERMSIG
WUNTRACED
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.
void _Exit(int); [XSI]long a64l(const char *);
void abort(void); int abs(int); int atexit(void (*)(void)); double atof(const char *); int atoi(const char *); long atol(const char *); long long atoll(const char *); void *bsearch(const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); void *calloc(size_t, size_t); div_t div(int, int); [XSI]
double drand48(void); double erand48(unsigned short [3]);
void exit(int); void free(void *); char *getenv(const char *); int getsubopt(char **, char *const *, char **); [XSI]
int grantpt(int); char *initstate(unsigned, char *, size_t); long jrand48(unsigned short [3]); char *l64a(long);
long labs(long); [XSI]
void lcong48(unsigned short [7]);
ldiv_t ldiv(long, long); long long llabs(long long); lldiv_t lldiv(long long, long long); [XSI]
long lrand48(void);
void *malloc(size_t); int mblen(const char *, size_t); size_t mbstowcs(wchar_t *restrict, const char *restrict, size_t); int mbtowc(wchar_t *restrict, const char *restrict, size_t); [CX]
char *mkdtemp(char *); int mkstemp(char *);
[XSI]
long mrand48(void); long nrand48(unsigned short [3]);
[ADV]
int posix_memalign(void **, size_t, size_t);
[XSI]
int posix_openpt(int); char *ptsname(int); int putenv(char *);
void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); int rand(void); [OB CX]
int rand_r(unsigned *);
[XSI]
long random(void);
void *realloc(void *, size_t); [XSI]
char *realpath(const char *restrict, char *restrict); unsigned short *seed48(unsigned short [3]);
[CX]
int setenv(const char *, const char *, int);
[XSI]
void setkey(const char *); char *setstate(char *);
void srand(unsigned); [XSI]
void srand48(long); void srandom(unsigned);
double strtod(const char *restrict, char **restrict); float strtof(const char *restrict, char **restrict); long strtol(const char *restrict, char **restrict, int); long double strtold(const char *restrict, char **restrict); long long strtoll(const char *restrict, char **restrict, int); unsigned long strtoul(const char *restrict, char **restrict, int); unsigned long long strtoull(const char *restrict, char **restrict, int); int system(const char *); [XSI]
int unlockpt(int);
[CX]
int unsetenv(const char *);
size_t wcstombs(char *restrict, const wchar_t *restrict, size_t); int wctomb(char *, wchar_t);
[CX]
Inclusion of the <stdlib.h> header may also make visible all symbols from <stddef.h>, <limits.h>, <math.h>, and <sys/wait.h>.
None.
None.
None.
<limits.h> , <math.h> , <stddef.h> , <sys/types.h> , <sys/wait.h>
XSH The Compilation Environment , _Exit , a64l , abort , abs , atexit , atof , atoi , atol , bsearch , calloc , div , drand48 , exit , free , getenv , getsubopt , grantpt , initstate , labs , ldiv , malloc , mblen , mbstowcs , mbtowc , mkdtemp , posix_memalign , posix_openpt , ptsname , putenv , qsort , rand , realloc , realpath , setenv , setkey , strtod , strtol , strtoul , system , unlockpt , unsetenv , wcstombs , wctomb
First released in Issue 3.
The DESCRIPTION is updated for alignment with the POSIX Threads Extension.
The ttyslot() and valloc() functions are marked LEGACY.
The type of the third argument to initstate() is changed from int to size_t. The type of the return value from setstate() is changed from char to char *, and the type of the first argument is changed from char * to const char *.
The Open Group Corrigendum U021/1 is applied, correcting the prototype for realpath() to be consistent with the reference page.
The Open Group Corrigendum U028/13 is applied, correcting the prototype for putenv() to be consistent with the reference page.
The rand_r() function is marked as part of the Thread-Safe Functions option.
Function prototypes for setenv() and unsetenv() are added.
The posix_memalign() function is added for alignment with IEEE Std 1003.1d-1999.
This reference page is updated to align with the ISO/IEC 9899:1999 standard.
The ecvt(), fcvt(), gcvt(), and mktemp() functions are marked LEGACY.
The ttyslot() and valloc() functions are removed as they were previously marked LEGACY.
Extensions beyond the ISO C standard are marked.
SD5-XBD-ERN-79 and SD5-XBD-ERN-105 are applied.
The LEGACY functions are removed.
The mkdtemp() function is added from The Open Group Technical Standard, 2006, Extended API Set Part 1.
The rand_r() function is marked obsolescent.
This reference page is clarified with respect to macros and symbolic constants.
The type of the first argument to setstate() is changed from const char * to char *.
return to top of page