stdlib.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* stdlib.h <ndf@linux.mit.edu> */
  2. #include <features.h>
  3. #include <sys/types.h>
  4. #ifndef __STDLIB_H
  5. #define __STDLIB_H
  6. /* Don't overwrite user definitions of NULL */
  7. #ifndef NULL
  8. #define NULL ((void *) 0)
  9. #endif
  10. /* For program termination */
  11. #define EXIT_FAILURE 1
  12. #define EXIT_SUCCESS 0
  13. /* Call all functions registered with `atexit' and `on_exit',
  14. * in the reverse of the order in which they were registered
  15. * perform stdio cleanup, and terminate program execution with STATUS. */
  16. extern void exit __P ((int __status)) __attribute__ ((__noreturn__));
  17. /* Register a function to be called when `exit' is called. */
  18. extern int atexit __P ((void (*__func) (void)));
  19. /* Abort execution and generate a core-dump. */
  20. extern void abort __P ((void)) __attribute__ ((__noreturn__));
  21. extern void * malloc __P ((size_t));
  22. extern void * calloc __P ((size_t, size_t));
  23. extern void free __P ((void *));
  24. extern void * realloc __P ((void *, size_t));
  25. #if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
  26. # include <alloca.h>
  27. #endif /* Use GNU, BSD, or misc. */
  28. #ifdef DEBUG_MALLOC
  29. extern void * malloc_dbg __P ((size_t, char* func, char* file, int line));
  30. extern void * calloc_dbg __P ((size_t, size_t, char* func, char* file, int line));
  31. extern void free_dbg __P ((void *, char* func, char* file, int line));
  32. extern void * realloc_dbg __P ((void *, size_t, char* func, char* file, int line));
  33. #define malloc(x) malloc_dbg((x),__FUNCTION__,__FILE__,__LINE__)
  34. #define calloc(x,y) calloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
  35. #define free(x) free_dbg((x),__FUNCTION__,__FILE__,__LINE__)
  36. #define realloc(x) realloc((x),__FUNCTION__,__FILE__,__LINE__)
  37. #endif
  38. extern int rand __P ((void));
  39. extern void srand __P ((unsigned int seed));
  40. extern long strtol __P ((const char * nptr, char ** endptr, int base));
  41. extern unsigned long strtoul __P ((const char * nptr,
  42. char ** endptr, int base));
  43. #ifndef __HAS_NO_FLOATS__
  44. extern float strtod __P ((const char * nptr, char ** endptr));
  45. #endif
  46. extern char *getenv __P ((__const char *__name));
  47. extern int putenv __P ((__const char *__string));
  48. extern int setenv __P ((__const char *__name, __const char *__value,
  49. int __replace));
  50. extern void unsetenv __P ((__const char *__name));
  51. extern int system __P ((__const char *__command));
  52. extern char * gcvt __P ((float number, size_t ndigit, char * buf));
  53. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  54. /* Return the canonical absolute name of file NAME. The last file name
  55. * component need not exist, and may be a symlink to a nonexistent file.
  56. * If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
  57. * name is PATH_MAX chars or more, returns null with `errno' set to
  58. * ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
  59. * name in RESOLVED. */
  60. extern char *realpath __P ((__const char *__restrict __name,
  61. char *__restrict __resolved));
  62. #endif
  63. /* Shorthand for type of comparison functions. */
  64. typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
  65. typedef __compar_fn_t comparison_fn_t;
  66. /* Sort NMEMB elements of BASE, of SIZE bytes each,
  67. using COMPAR to perform the comparisons. */
  68. extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size,
  69. __compar_fn_t __compar));
  70. #define atof(x) strtod((x),(char**)0)
  71. #define atoi(x) (int)strtol((x),(char**)0,10)
  72. #define atol(x) strtol((x),(char**)0,10)
  73. /* Returned by `div'. */
  74. typedef struct
  75. {
  76. int quot; /* Quotient. */
  77. int rem; /* Remainder. */
  78. } div_t;
  79. /* Returned by `ldiv'. */
  80. typedef struct
  81. {
  82. long int quot; /* Quotient. */
  83. long int rem; /* Remainder. */
  84. } ldiv_t;
  85. #endif /* __STDLIB_H */