stdlib.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* stdlib.h */
  2. #ifndef __STDLIB_H
  3. #define __STDLIB_H
  4. #include <features.h>
  5. #include <sys/types.h>
  6. #include <limits.h>
  7. __BEGIN_DECLS
  8. /* Don't overwrite user definitions of NULL */
  9. #ifndef NULL
  10. #define NULL ((void *) 0)
  11. #endif
  12. /* We define these the same for all machines.
  13. * Changes from this to the outside world should be done in `_exit'. */
  14. #define EXIT_FAILURE 1 /* Failing exit status. */
  15. #define EXIT_SUCCESS 0 /* Successful exit status. */
  16. /* The largest number rand will return */
  17. #define RAND_MAX INT_MAX
  18. /* Maximum length of a multibyte character in the current locale. */
  19. #define MB_CUR_MAX 1
  20. typedef struct
  21. {
  22. int quot; /* Quotient. */
  23. int rem; /* Remainder. */
  24. } div_t;
  25. typedef struct
  26. {
  27. long int quot; /* Quotient. */
  28. long int rem; /* Remainder. */
  29. } ldiv_t;
  30. /* comparison function used by bsearch() and qsort() */
  31. typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
  32. typedef __compar_fn_t comparison_fn_t;
  33. /* String to number conversion functions */
  34. extern double atof(const char *nptr);
  35. extern int atoi(const char *nptr);
  36. extern long atol(const char *nptr);
  37. extern long strtol __P ((const char * nptr, char ** endptr, int base));
  38. extern unsigned long strtoul __P ((const char * nptr, char ** endptr, int base));
  39. #if defined __UCLIBC_HAS_LONG_LONG__
  40. extern long long atoll(const char *nptr);
  41. extern long long strtoll __P ((const char * nptr, char ** endptr, int base));
  42. extern unsigned long long strtoull __P ((const char * nptr, char ** endptr, int base));
  43. #endif
  44. #ifdef __UCLIBC_HAS_FLOATS__
  45. /*TODO: extern char * gcvt __P ((double number, size_t ndigit, char * buf)); */
  46. extern double strtod __P ((const char * nptr, char ** endptr));
  47. #endif
  48. /* Random number functions */
  49. extern int rand __P ((void));
  50. extern void srand __P ((unsigned int seed));
  51. extern long int random(void);
  52. extern void srandom(unsigned int seed);
  53. /* Memory management functions */
  54. extern __ptr_t calloc __P ((size_t, size_t));
  55. extern __ptr_t malloc __P ((size_t));
  56. extern __ptr_t realloc __P ((__ptr_t, size_t));
  57. extern void free __P ((__ptr_t));
  58. /* Allocate a block on the stack that will be freed
  59. * when the calling function exits. We use gcc's
  60. * version to make life better... */
  61. #undef alloca
  62. extern __ptr_t alloca __P ((size_t __size));
  63. #define alloca(size) __builtin_alloca (size)
  64. #ifdef DEBUG_MALLOC
  65. extern __ptr_t calloc_dbg __P ((size_t, size_t, char* func, char* file, int line));
  66. extern __ptr_t malloc_dbg __P ((size_t, char* func, char* file, int line));
  67. extern __ptr_t realloc_dbg __P ((__ptr_t, size_t, char* func, char* file, int line));
  68. extern void free_dbg __P ((__ptr_t, char* func, char* file, int line));
  69. #define calloc(x,y) calloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
  70. #define malloc(x) malloc_dbg((x),__FUNCTION__,__FILE__,__LINE__)
  71. #define realloc(x,y) realloc_dbg((x),(y),__FUNCTION__,__FILE__,__LINE__)
  72. #define free(x) free_dbg((x),__FUNCTION__,__FILE__,__LINE__)
  73. #endif
  74. /* System and environment functions */
  75. extern void abort __P ((void)) __attribute__ ((__noreturn__));
  76. extern int atexit __P ((void (*__func) (void)));
  77. extern void exit __P ((int __status)) __attribute__ ((__noreturn__));
  78. extern void _exit __P ((int __status)) __attribute__ ((__noreturn__));
  79. extern char *getenv __P ((__const char *__name));
  80. extern int putenv __P ((__const char *__string));
  81. extern char *realpath __P ((__const char *__restrict __name,
  82. char *__restrict __resolved));
  83. extern int setenv __P ((__const char *__name, __const char *__value,
  84. int __replace));
  85. extern int system __P ((__const char *__command));
  86. extern void unsetenv __P ((__const char *__name));
  87. /* The following is used by uClibc in atexit.c and sysconf.c */
  88. #define __UCLIBC_MAX_ATEXIT 20
  89. /* Search and sort functions */
  90. extern __ptr_t bsearch __P ((__const __ptr_t __key, __const __ptr_t __base,
  91. size_t __nmemb, size_t __size, __compar_fn_t __compar));
  92. extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size,
  93. __compar_fn_t __compar));
  94. /* Integer math functions */
  95. extern int abs __P ((int __x)) __attribute__ ((__const__));
  96. extern div_t div __P ((int __numer, int __denom)) __attribute__ ((__const__));
  97. extern long int labs __P ((long int __x)) __attribute__ ((__const__));
  98. extern ldiv_t ldiv __P ((long int __numer, long int __denom)) __attribute__ ((__const__));
  99. /* Generate a unique temporary file name from TEMPLATE. */
  100. extern char *mktemp __P ((char *__template));
  101. extern int mkstemp __P ((char *__template));
  102. __END_DECLS
  103. #endif /* __STDLIB_H */