| 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 | |
| 10 | /* |
| 11 | stdlib.h synopsis |
| 12 | |
| 13 | Macros: |
| 14 | |
| 15 | EXIT_FAILURE |
| 16 | EXIT_SUCCESS |
| 17 | MB_CUR_MAX |
| 18 | NULL |
| 19 | RAND_MAX |
| 20 | |
| 21 | Types: |
| 22 | |
| 23 | size_t |
| 24 | div_t |
| 25 | ldiv_t |
| 26 | lldiv_t // C99 |
| 27 | |
| 28 | double atof (const char* nptr); |
| 29 | int atoi (const char* nptr); |
| 30 | long atol (const char* nptr); |
| 31 | long long atoll(const char* nptr); // C99 |
| 32 | double strtod (const char* restrict nptr, char** restrict endptr); |
| 33 | float strtof (const char* restrict nptr, char** restrict endptr); // C99 |
| 34 | long double strtold (const char* restrict nptr, char** restrict endptr); // C99 |
| 35 | long strtol (const char* restrict nptr, char** restrict endptr, int base); |
| 36 | long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99 |
| 37 | unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base); |
| 38 | unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99 |
| 39 | int rand(void); |
| 40 | void srand(unsigned int seed); |
| 41 | void* calloc(size_t nmemb, size_t size); |
| 42 | void free(void* ptr); |
| 43 | void* malloc(size_t size); |
| 44 | void* realloc(void* ptr, size_t size); |
| 45 | void abort(void); |
| 46 | int atexit(void (*func)(void)); |
| 47 | void exit(int status); |
| 48 | void _Exit(int status); |
| 49 | char* getenv(const char* name); |
| 50 | int system(const char* string); |
| 51 | void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, |
| 52 | int (*compar)(const void *, const void *)); |
| 53 | void qsort(void* base, size_t nmemb, size_t size, |
| 54 | int (*compar)(const void *, const void *)); |
| 55 | int abs( int j); |
| 56 | long abs( long j); |
| 57 | long long abs(long long j); // C++0X |
| 58 | long labs( long j); |
| 59 | long long llabs(long long j); // C99 |
| 60 | div_t div( int numer, int denom); |
| 61 | ldiv_t div( long numer, long denom); |
| 62 | lldiv_t div(long long numer, long long denom); // C++0X |
| 63 | ldiv_t ldiv( long numer, long denom); |
| 64 | lldiv_t lldiv(long long numer, long long denom); // C99 |
| 65 | int mblen(const char* s, size_t n); |
| 66 | int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n); |
| 67 | int wctomb(char* s, wchar_t wchar); |
| 68 | size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n); |
| 69 | size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n); |
| 70 | int at_quick_exit(void (*func)(void)) // C++11 |
| 71 | void quick_exit(int status); // C++11 |
| 72 | void *aligned_alloc(size_t alignment, size_t size); // C11 |
| 73 | |
| 74 | */ |
| 75 | |
| 76 | #if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 77 | # include <__cxx03/stdlib.h> |
| 78 | #else |
| 79 | # include <__config> |
| 80 | |
| 81 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 82 | # pragma GCC system_header |
| 83 | # endif |
| 84 | |
| 85 | // The inclusion of the system's <stdlib.h> is intentionally done once outside of any include |
| 86 | // guards because some code expects to be able to include the underlying system header multiple |
| 87 | // times to get different definitions based on the macros that are set before inclusion. |
| 88 | # if __has_include_next(<stdlib.h>) |
| 89 | # include_next <stdlib.h> |
| 90 | # endif |
| 91 | |
| 92 | # if !defined(_LIBCPP_STDLIB_H) |
| 93 | # define _LIBCPP_STDLIB_H |
| 94 | |
| 95 | # ifdef __cplusplus |
| 96 | extern "C++" { |
| 97 | // abs |
| 98 | |
| 99 | # ifdef abs |
| 100 | # undef abs |
| 101 | # endif |
| 102 | # ifdef labs |
| 103 | # undef labs |
| 104 | # endif |
| 105 | # ifdef llabs |
| 106 | # undef llabs |
| 107 | # endif |
| 108 | |
| 109 | # include <__math/abs.h> |
| 110 | using std::__math::abs; |
| 111 | |
| 112 | // div |
| 113 | |
| 114 | # ifdef div |
| 115 | # undef div |
| 116 | # endif |
| 117 | # ifdef ldiv |
| 118 | # undef ldiv |
| 119 | # endif |
| 120 | # ifdef lldiv |
| 121 | # undef lldiv |
| 122 | # endif |
| 123 | |
| 124 | // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined |
| 125 | # if !defined(_LIBCPP_MSVCRT) |
| 126 | inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(numer: __x, denom: __y); } |
| 127 | # if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED)) |
| 128 | inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(numer: __x, denom: __y); } |
| 129 | # endif |
| 130 | # endif // _LIBCPP_MSVCRT |
| 131 | } // extern "C++" |
| 132 | # endif // __cplusplus |
| 133 | # endif // _LIBCPP_STDLIB_H |
| 134 | |
| 135 | #endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 136 | |