Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_CSTDLIB |
| 11 | #define _LIBCPP_CSTDLIB |
| 12 | |
| 13 | /* |
| 14 | cstdlib synopsis |
| 15 | |
| 16 | Macros: |
| 17 | |
| 18 | EXIT_FAILURE |
| 19 | EXIT_SUCCESS |
| 20 | MB_CUR_MAX |
| 21 | NULL |
| 22 | RAND_MAX |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 23 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | namespace std |
| 25 | { |
| 26 | |
| 27 | Types: |
| 28 | |
| 29 | size_t |
| 30 | div_t |
| 31 | ldiv_t |
| 32 | lldiv_t // C99 |
| 33 | |
| 34 | double atof (const char* nptr); |
| 35 | int atoi (const char* nptr); |
| 36 | long atol (const char* nptr); |
| 37 | long long atoll(const char* nptr); // C99 |
| 38 | double strtod (const char* restrict nptr, char** restrict endptr); |
| 39 | float strtof (const char* restrict nptr, char** restrict endptr); // C99 |
| 40 | long double strtold (const char* restrict nptr, char** restrict endptr); // C99 |
| 41 | long strtol (const char* restrict nptr, char** restrict endptr, int base); |
| 42 | long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99 |
| 43 | unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base); |
| 44 | unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99 |
| 45 | int rand(void); |
| 46 | void srand(unsigned int seed); |
| 47 | void* calloc(size_t nmemb, size_t size); |
| 48 | void free(void* ptr); |
| 49 | void* malloc(size_t size); |
| 50 | void* realloc(void* ptr, size_t size); |
| 51 | void abort(void); |
| 52 | int atexit(void (*func)(void)); |
| 53 | void exit(int status); |
| 54 | void _Exit(int status); |
| 55 | char* getenv(const char* name); |
| 56 | int system(const char* string); |
| 57 | void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, |
| 58 | int (*compar)(const void *, const void *)); |
| 59 | void qsort(void* base, size_t nmemb, size_t size, |
| 60 | int (*compar)(const void *, const void *)); |
| 61 | int abs( int j); |
| 62 | long abs( long j); |
| 63 | long long abs(long long j); // C++0X |
| 64 | long labs( long j); |
| 65 | long long llabs(long long j); // C99 |
| 66 | div_t div( int numer, int denom); |
| 67 | ldiv_t div( long numer, long denom); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 68 | lldiv_t div(long long numer, long long denom); // C++0X |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 69 | ldiv_t ldiv( long numer, long denom); |
| 70 | lldiv_t lldiv(long long numer, long long denom); // C99 |
| 71 | int mblen(const char* s, size_t n); |
| 72 | int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n); |
| 73 | int wctomb(char* s, wchar_t wchar); |
| 74 | size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n); |
| 75 | size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n); |
Howard Hinnant | cabc5a2 | 2012-10-13 18:03:53 +0000 | [diff] [blame] | 76 | int at_quick_exit(void (*func)(void)) // C++11 |
| 77 | void quick_exit(int status); // C++11 |
| 78 | void *aligned_alloc(size_t alignment, size_t size); // C11 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 79 | |
| 80 | } // std |
| 81 | |
| 82 | */ |
| 83 | |
| 84 | #include <__config> |
| 85 | #include <stdlib.h> |
| 86 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 87 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 88 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 89 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | |
Eric Fiselier | f0d9d5d | 2016-08-29 20:43:38 +0000 | [diff] [blame] | 91 | #ifdef __GNUC__ |
| 92 | #define _LIBCPP_UNREACHABLE() __builtin_unreachable() |
| 93 | #else |
| 94 | #define _LIBCPP_UNREACHABLE() _VSTD::abort() |
| 95 | #endif |
| 96 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 97 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 98 | |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 99 | using ::size_t _LIBCPP_USING_IF_EXISTS; |
| 100 | using ::div_t _LIBCPP_USING_IF_EXISTS; |
| 101 | using ::ldiv_t _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 102 | using ::lldiv_t _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 103 | using ::atof _LIBCPP_USING_IF_EXISTS; |
| 104 | using ::atoi _LIBCPP_USING_IF_EXISTS; |
| 105 | using ::atol _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 106 | using ::atoll _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 107 | using ::strtod _LIBCPP_USING_IF_EXISTS; |
| 108 | using ::strtof _LIBCPP_USING_IF_EXISTS; |
| 109 | using ::strtold _LIBCPP_USING_IF_EXISTS; |
| 110 | using ::strtol _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 111 | using ::strtoll _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 112 | using ::strtoul _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 113 | using ::strtoull _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 114 | using ::rand _LIBCPP_USING_IF_EXISTS; |
| 115 | using ::srand _LIBCPP_USING_IF_EXISTS; |
| 116 | using ::calloc _LIBCPP_USING_IF_EXISTS; |
| 117 | using ::free _LIBCPP_USING_IF_EXISTS; |
| 118 | using ::malloc _LIBCPP_USING_IF_EXISTS; |
| 119 | using ::realloc _LIBCPP_USING_IF_EXISTS; |
| 120 | using ::abort _LIBCPP_USING_IF_EXISTS; |
| 121 | using ::atexit _LIBCPP_USING_IF_EXISTS; |
| 122 | using ::exit _LIBCPP_USING_IF_EXISTS; |
| 123 | using ::_Exit _LIBCPP_USING_IF_EXISTS; |
Shoaib Meenai | e2ce360 | 2017-04-06 04:47:49 +0000 | [diff] [blame] | 124 | #ifndef _LIBCPP_WINDOWS_STORE_APP |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 125 | using ::getenv _LIBCPP_USING_IF_EXISTS; |
| 126 | using ::system _LIBCPP_USING_IF_EXISTS; |
Shoaib Meenai | e2ce360 | 2017-04-06 04:47:49 +0000 | [diff] [blame] | 127 | #endif |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 128 | using ::bsearch _LIBCPP_USING_IF_EXISTS; |
| 129 | using ::qsort _LIBCPP_USING_IF_EXISTS; |
| 130 | using ::abs _LIBCPP_USING_IF_EXISTS; |
| 131 | using ::labs _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 132 | using ::llabs _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 133 | using ::div _LIBCPP_USING_IF_EXISTS; |
| 134 | using ::ldiv _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 135 | using ::lldiv _LIBCPP_USING_IF_EXISTS; |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 136 | using ::mblen _LIBCPP_USING_IF_EXISTS; |
| 137 | using ::mbtowc _LIBCPP_USING_IF_EXISTS; |
| 138 | using ::wctomb _LIBCPP_USING_IF_EXISTS; |
| 139 | using ::mbstowcs _LIBCPP_USING_IF_EXISTS; |
| 140 | using ::wcstombs _LIBCPP_USING_IF_EXISTS; |
Marshall Clow | a6a55a8 | 2018-08-15 21:19:08 +0000 | [diff] [blame] | 141 | #if !defined(_LIBCPP_CXX03_LANG) && defined(_LIBCPP_HAS_QUICK_EXIT) |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 142 | using ::at_quick_exit _LIBCPP_USING_IF_EXISTS; |
| 143 | using ::quick_exit _LIBCPP_USING_IF_EXISTS; |
David Chisnall | 277ad05 | 2012-03-14 14:10:37 +0000 | [diff] [blame] | 144 | #endif |
Dan Albert | 1d3cfad | 2019-11-18 12:16:45 -0800 | [diff] [blame] | 145 | #if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_ALIGNED_ALLOC) |
Louis Dionne | 9c660c6 | 2021-06-02 10:41:37 -0400 | [diff] [blame] | 146 | using ::aligned_alloc _LIBCPP_USING_IF_EXISTS; |
Howard Hinnant | cabc5a2 | 2012-10-13 18:03:53 +0000 | [diff] [blame] | 147 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 148 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 149 | _LIBCPP_END_NAMESPACE_STD |
| 150 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 151 | #endif // _LIBCPP_CSTDLIB |