stdlib.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifdef DEBUG_MALLOC
  26. extern void * malloc_dbg __P ((size_t, char* func, char* file, int line));
  27. extern void * calloc_dbg __P ((size_t, size_t, char* func, char* file, int line));
  28. extern void free_dbg __P ((void *, char* func, char* file, int line));
  29. extern void * realloc_dbg __P ((void *, size_t, char* func, char* file, int line));
  30. #define malloc(x) malloc_dbg((x),__FUNCTION__,__FILE__,__LINE__)
  31. #define calloc(x,y) calloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
  32. #define free(x) free_dbg((x),__FUNCTION__,__FILE__,__LINE__)
  33. #define realloc(x) realloc((x),__FUNCTION__,__FILE__,__LINE__)
  34. #endif
  35. extern int rand __P ((void));
  36. extern void srand __P ((unsigned int seed));
  37. extern long strtol __P ((const char * nptr, char ** endptr, int base));
  38. extern unsigned long strtoul __P ((const char * nptr,
  39. char ** endptr, int base));
  40. #ifndef __HAS_NO_FLOATS__
  41. extern float strtod __P ((const char * nptr, char ** endptr));
  42. #endif
  43. extern char *getenv __P ((__const char *__name));
  44. extern int putenv __P ((__const char *__string));
  45. extern int setenv __P ((__const char *__name, __const char *__value,
  46. int __replace));
  47. extern void unsetenv __P ((__const char *__name));
  48. extern int system __P ((__const char *__command));
  49. extern char * gcvt __P ((float number, size_t ndigit, char * buf));
  50. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  51. /* Return the canonical absolute name of file NAME. The last file name
  52. * component need not exist, and may be a symlink to a nonexistent file.
  53. * If RESOLVED is null, the result is malloc'd; otherwise, if the canonical
  54. * name is PATH_MAX chars or more, returns null with `errno' set to
  55. * ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, returns the
  56. * name in RESOLVED. */
  57. extern char *realpath __P ((__const char *__restrict __name,
  58. char *__restrict __resolved));
  59. #endif
  60. /* Shorthand for type of comparison functions. */
  61. typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
  62. typedef __compar_fn_t comparison_fn_t;
  63. /* Sort NMEMB elements of BASE, of SIZE bytes each,
  64. using COMPAR to perform the comparisons. */
  65. extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size,
  66. __compar_fn_t __compar));
  67. #define atof(x) strtod((x),(char**)0)
  68. #define atoi(x) (int)strtol((x),(char**)0,10)
  69. #define atol(x) strtol((x),(char**)0,10)
  70. /* Returned by `div'. */
  71. typedef struct
  72. {
  73. int quot; /* Quotient. */
  74. int rem; /* Remainder. */
  75. } div_t;
  76. /* Returned by `ldiv'. */
  77. typedef struct
  78. {
  79. long int quot; /* Quotient. */
  80. long int rem; /* Remainder. */
  81. } ldiv_t;
  82. #endif /* __STDLIB_H */