stdlib.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* stdlib.h */
  2. #include <features.h>
  3. #include <sys/types.h>
  4. #include <limits.h>
  5. #ifndef __STDLIB_H
  6. #define __STDLIB_H
  7. /* Don't overwrite user definitions of NULL */
  8. #ifndef NULL
  9. #define NULL ((void *) 0)
  10. #endif
  11. /* We define these the same for all machines.
  12. * Changes from this to the outside world should be done in `_exit'. */
  13. #define EXIT_FAILURE 1 /* Failing exit status. */
  14. #define EXIT_SUCCESS 0 /* Successful exit status. */
  15. /* The largest number rand will return */
  16. #define RAND_MAX INT_MIN
  17. /* Maximum length of a multibyte character in the current locale. */
  18. #define MB_CUR_MAX 1
  19. typedef struct
  20. {
  21. int quot; /* Quotient. */
  22. int rem; /* Remainder. */
  23. } div_t;
  24. typedef struct
  25. {
  26. long int quot; /* Quotient. */
  27. long int rem; /* Remainder. */
  28. } ldiv_t;
  29. /* comparison function used by bsearch() and qsort() */
  30. typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
  31. typedef __compar_fn_t comparison_fn_t;
  32. /* String to number conversion functions */
  33. #define atof(x) strtod((x),(char**)0)
  34. #define atoi(x) (int)strtol((x),(char**)0,10)
  35. #define atol(x) strtol((x),(char**)0,10)
  36. extern long strtol __P ((const char * nptr, char ** endptr, int base));
  37. extern unsigned long strtoul __P ((const char * nptr, char ** endptr, int base));
  38. #ifndef __HAS_NO_FLOATS__
  39. extern char * gcvt __P ((float number, size_t ndigit, char * buf));
  40. extern float strtod __P ((const char * nptr, char ** endptr));
  41. #endif
  42. /* Random number functions */
  43. extern int rand __P ((void));
  44. extern void srand __P ((unsigned int seed));
  45. /* Memory management functions */
  46. extern __ptr_t alloca __P ((size_t __size));
  47. extern __ptr_t calloc __P ((size_t, size_t));
  48. extern __ptr_t malloc __P ((size_t));
  49. extern __ptr_t realloc __P ((__ptr_t, size_t));
  50. extern void free __P ((__ptr_t));
  51. #ifdef DEBUG_MALLOC
  52. extern __ptr_t malloc_dbg __P ((size_t, char* func, char* file, int line));
  53. extern __ptr_t calloc_dbg __P ((size_t, size_t, char* func, char* file, int line));
  54. extern void free_dbg __P ((__ptr_t, char* func, char* file, int line));
  55. extern __ptr_t realloc_dbg __P ((__ptr_t, size_t, char* func, char* file, int line));
  56. #define malloc(x) malloc_dbg((x),__FUNCTION__,__FILE__,__LINE__)
  57. #define calloc(x,y) calloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
  58. #define free(x) free_dbg((x),__FUNCTION__,__FILE__,__LINE__)
  59. #define realloc(x) realloc((x),__FUNCTION__,__FILE__,__LINE__)
  60. #endif
  61. /* System and environment functions */
  62. extern void abort __P ((void)) __attribute__ ((__noreturn__));
  63. extern int atexit __P ((void (*__func) (void)));
  64. extern void exit __P ((int __status)) __attribute__ ((__noreturn__));
  65. extern void _exit __P ((int __status)) __attribute__ ((__noreturn__));
  66. extern char *getenv __P ((__const char *__name));
  67. extern int putenv __P ((__const char *__string));
  68. extern char *realpath __P ((__const char *__restrict __name,
  69. char *__restrict __resolved));
  70. extern int setenv __P ((__const char *__name, __const char *__value,
  71. int __replace));
  72. extern int system __P ((__const char *__command));
  73. extern void unsetenv __P ((__const char *__name));
  74. /* Search and sort functions */
  75. extern __ptr_t bsearch __P ((__const __ptr_t __key, __const __ptr_t __base,
  76. size_t __nmemb, size_t __size, __compar_fn_t __compar));
  77. extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size,
  78. __compar_fn_t __compar));
  79. /* Integer math functions */
  80. extern int abs __P ((int __x)) __attribute__ ((__const__));
  81. extern div_t div __P ((int __numer, int __denom)) __attribute__ ((__const__));
  82. extern long int labs __P ((long int __x)) __attribute__ ((__const__));
  83. extern ldiv_t ldiv __P ((long int __numer, long int __denom)) __attribute__ ((__const__));
  84. #endif /* __STDLIB_H */