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