stdlib.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #if defined(__need_malloc_and_calloc)
  10. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  11. # pragma GCC system_header
  12. #endif
  13. #ifdef _LIBCPP_COMPILER_MSVC
  14. #include Y_UCRT_INCLUDE_NEXT(stdlib.h)
  15. #else
  16. #include_next <stdlib.h>
  17. #endif
  18. #elif !defined(_LIBCPP_STDLIB_H)
  19. #define _LIBCPP_STDLIB_H
  20. /*
  21. stdlib.h synopsis
  22. Macros:
  23. EXIT_FAILURE
  24. EXIT_SUCCESS
  25. MB_CUR_MAX
  26. NULL
  27. RAND_MAX
  28. Types:
  29. size_t
  30. div_t
  31. ldiv_t
  32. lldiv_t // C99
  33. double atof (const char* nptr);
  34. int atoi (const char* nptr);
  35. long atol (const char* nptr);
  36. long long atoll(const char* nptr); // C99
  37. double strtod (const char* restrict nptr, char** restrict endptr);
  38. float strtof (const char* restrict nptr, char** restrict endptr); // C99
  39. long double strtold (const char* restrict nptr, char** restrict endptr); // C99
  40. long strtol (const char* restrict nptr, char** restrict endptr, int base);
  41. long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99
  42. unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base);
  43. unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99
  44. int rand(void);
  45. void srand(unsigned int seed);
  46. void* calloc(size_t nmemb, size_t size);
  47. void free(void* ptr);
  48. void* malloc(size_t size);
  49. void* realloc(void* ptr, size_t size);
  50. void abort(void);
  51. int atexit(void (*func)(void));
  52. void exit(int status);
  53. void _Exit(int status);
  54. char* getenv(const char* name);
  55. int system(const char* string);
  56. void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
  57. int (*compar)(const void *, const void *));
  58. void qsort(void* base, size_t nmemb, size_t size,
  59. int (*compar)(const void *, const void *));
  60. int abs( int j);
  61. long abs( long j);
  62. long long abs(long long j); // C++0X
  63. long labs( long j);
  64. long long llabs(long long j); // C99
  65. div_t div( int numer, int denom);
  66. ldiv_t div( long numer, long denom);
  67. lldiv_t div(long long numer, long long denom); // C++0X
  68. ldiv_t ldiv( long numer, long denom);
  69. lldiv_t lldiv(long long numer, long long denom); // C99
  70. int mblen(const char* s, size_t n);
  71. int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);
  72. int wctomb(char* s, wchar_t wchar);
  73. size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);
  74. size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);
  75. int at_quick_exit(void (*func)(void)) // C++11
  76. void quick_exit(int status); // C++11
  77. void *aligned_alloc(size_t alignment, size_t size); // C11
  78. */
  79. #include <__config>
  80. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  81. # pragma GCC system_header
  82. #endif
  83. #ifdef _LIBCPP_COMPILER_MSVC
  84. #include Y_UCRT_INCLUDE_NEXT(stdlib.h)
  85. #ifdef __cplusplus
  86. extern "C" {
  87. #endif
  88. float fabsf(float);
  89. double fabs(double);
  90. long double fabsl(long double);
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #else
  95. #include_next <stdlib.h>
  96. #endif
  97. #ifdef __cplusplus
  98. extern "C++" {
  99. // abs
  100. #ifdef abs
  101. # undef abs
  102. #endif
  103. #ifdef labs
  104. # undef labs
  105. #endif
  106. #ifdef llabs
  107. # undef llabs
  108. #endif
  109. // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
  110. #if !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
  111. inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
  112. return __builtin_labs(__x);
  113. }
  114. inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
  115. return __builtin_llabs(__x);
  116. }
  117. #endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
  118. #if !defined(__sun__)
  119. inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT {
  120. #ifdef _LIBCPP_COMPILER_MSVC
  121. return fabsf(__lcpp_x);
  122. #else
  123. return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h
  124. #endif
  125. }
  126. inline _LIBCPP_INLINE_VISIBILITY double abs(double __lcpp_x) _NOEXCEPT {
  127. #ifdef _LIBCPP_COMPILER_MSVC
  128. return fabs(__lcpp_x);
  129. #else
  130. return __builtin_fabs(__lcpp_x);
  131. #endif
  132. }
  133. inline _LIBCPP_INLINE_VISIBILITY long double
  134. abs(long double __lcpp_x) _NOEXCEPT {
  135. #ifdef _LIBCPP_COMPILER_MSVC
  136. return fabsl(__lcpp_x);
  137. #else
  138. return __builtin_fabsl(__lcpp_x);
  139. #endif
  140. }
  141. #endif // !defined(__sun__)
  142. // div
  143. #ifdef div
  144. # undef div
  145. #endif
  146. #ifdef ldiv
  147. # undef ldiv
  148. #endif
  149. #ifdef lldiv
  150. # undef lldiv
  151. #endif
  152. // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
  153. #if !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
  154. inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
  155. return ::ldiv(__x, __y);
  156. }
  157. #if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))
  158. inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
  159. long long __y) _NOEXCEPT {
  160. return ::lldiv(__x, __y);
  161. }
  162. #endif
  163. #endif // _LIBCPP_MSVCRT / __sun__
  164. } // extern "C++"
  165. #endif // __cplusplus
  166. #endif // _LIBCPP_STDLIB_H