cstdlib 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // -*- C++ -*-
  2. //===--------------------------- cstdlib ----------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_CSTDLIB
  11. #define _LIBCPP_CSTDLIB
  12. /*
  13. cstdlib synopsis
  14. Macros:
  15. EXIT_FAILURE
  16. EXIT_SUCCESS
  17. MB_CUR_MAX
  18. NULL
  19. RAND_MAX
  20. namespace std
  21. {
  22. Types:
  23. size_t
  24. div_t
  25. ldiv_t
  26. lldiv_t // C99
  27. double atof (const char* nptr);
  28. int atoi (const char* nptr);
  29. long atol (const char* nptr);
  30. long long atoll(const char* nptr); // C99
  31. double strtod (const char* restrict nptr, char** restrict endptr);
  32. float strtof (const char* restrict nptr, char** restrict endptr); // C99
  33. long double strtold (const char* restrict nptr, char** restrict endptr); // C99
  34. long strtol (const char* restrict nptr, char** restrict endptr, int base);
  35. long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99
  36. unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base);
  37. unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99
  38. int rand(void);
  39. void srand(unsigned int seed);
  40. void* calloc(size_t nmemb, size_t size);
  41. void free(void* ptr);
  42. void* malloc(size_t size);
  43. void* realloc(void* ptr, size_t size);
  44. void abort(void);
  45. int atexit(void (*func)(void));
  46. void exit(int status);
  47. void _Exit(int status);
  48. char* getenv(const char* name);
  49. int system(const char* string);
  50. void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
  51. int (*compar)(const void *, const void *));
  52. void qsort(void* base, size_t nmemb, size_t size,
  53. int (*compar)(const void *, const void *));
  54. int abs( int j);
  55. long abs( long j);
  56. long long abs(long long j); // C++0X
  57. long labs( long j);
  58. long long llabs(long long j); // C99
  59. div_t div( int numer, int denom);
  60. ldiv_t div( long numer, long denom);
  61. lldiv_t div(long long numer, long long denom); // C++0X
  62. ldiv_t ldiv( long numer, long denom);
  63. lldiv_t lldiv(long long numer, long long denom); // C99
  64. int mblen(const char* s, size_t n);
  65. int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);
  66. int wctomb(char* s, wchar_t wchar);
  67. size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);
  68. size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);
  69. int at_quick_exit(void (*func)(void)) // C++11
  70. void quick_exit(int status); // C++11
  71. void *aligned_alloc(size_t alignment, size_t size); // C11
  72. } // std
  73. */
  74. #include <__config>
  75. #include <stdlib.h>
  76. #ifdef _LIBCPP_MSVCRT
  77. #ifndef _LIBCPP_SGX_CONFIG
  78. #include "support/win32/locale_win32.h"
  79. #endif _LIBCPP_SGX_CONFIG
  80. #endif // _LIBCPP_MSVCRT
  81. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  82. #pragma GCC system_header
  83. #endif
  84. _LIBCPP_BEGIN_NAMESPACE_STD
  85. using ::size_t;
  86. using ::div_t;
  87. using ::ldiv_t;
  88. #ifndef _LIBCPP_HAS_NO_LONG_LONG
  89. using ::lldiv_t;
  90. #endif // _LIBCPP_HAS_NO_LONG_LONG
  91. using ::atof;
  92. using ::atoi;
  93. using ::atol;
  94. #ifndef _LIBCPP_HAS_NO_LONG_LONG
  95. using ::atoll;
  96. #endif // _LIBCPP_HAS_NO_LONG_LONG
  97. using ::strtod;
  98. using ::strtof;
  99. using ::strtold;
  100. using ::strtol;
  101. #ifndef _LIBCPP_HAS_NO_LONG_LONG
  102. using ::strtoll;
  103. #endif // _LIBCPP_HAS_NO_LONG_LONG
  104. using ::strtoul;
  105. #ifndef _LIBCPP_HAS_NO_LONG_LONG
  106. using ::strtoull;
  107. #endif // _LIBCPP_HAS_NO_LONG_LONG
  108. #ifndef _LIBCPP_SGX_CONFIG
  109. using ::rand;
  110. using ::srand;
  111. #endif //_LIBCPP_SGX_CONFIG
  112. using ::calloc;
  113. using ::free;
  114. using ::malloc;
  115. using ::realloc;
  116. using ::abort;
  117. #ifndef _LIBCPP_SGX_CONFIG
  118. using ::atexit;
  119. using ::exit;
  120. using ::_Exit;
  121. using ::getenv;
  122. using ::system;
  123. #endif //_LIBCPP_SGX_CONFIG
  124. using ::bsearch;
  125. using ::qsort;
  126. #undef abs
  127. using ::abs;
  128. #undef labs
  129. using ::labs;
  130. #ifndef _LIBCPP_HAS_NO_LONG_LONG
  131. #undef llabs
  132. using ::llabs;
  133. #endif // _LIBCPP_HAS_NO_LONG_LONG
  134. #undef div
  135. using ::div;
  136. #undef ldiv
  137. using ::ldiv;
  138. #ifndef _LIBCPP_HAS_NO_LONG_LONG
  139. #undef lldiv
  140. using ::lldiv;
  141. #endif // _LIBCPP_HAS_NO_LONG_LONG
  142. #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
  143. using ::mblen;
  144. using ::mbtowc;
  145. using ::wctomb;
  146. #endif
  147. using ::mbstowcs;
  148. using ::wcstombs;
  149. #ifdef _LIBCPP_HAS_QUICK_EXIT
  150. using ::at_quick_exit;
  151. using ::quick_exit;
  152. #endif
  153. #ifdef _LIBCPP_HAS_C11_FEATURES
  154. using ::aligned_alloc;
  155. #endif
  156. // MSVCRT already has the correct prototype in <stdlib.h> #ifdef __cplusplus
  157. #if (!defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)) || defined(_LIBCPP_SGX_CONFIG)
  158. inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);}
  159. #ifndef _LIBCPP_HAS_NO_LONG_LONG
  160. inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
  161. #endif // _LIBCPP_HAS_NO_LONG_LONG
  162. inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);}
  163. #ifndef _LIBCPP_HAS_NO_LONG_LONG
  164. inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
  165. #endif // _LIBCPP_HAS_NO_LONG_LONG
  166. #endif // _LIBCPP_MSVCRT
  167. _LIBCPP_END_NAMESPACE_STD
  168. #endif // _LIBCPP_CSTDLIB