Richard Smith | f650ea7 | 2015-10-09 01:41:45 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- stdlib.h ---------------------------------===// |
| 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 | |
| 11 | #if defined(__need_malloc_and_calloc) |
| 12 | |
| 13 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 14 | #pragma GCC system_header |
| 15 | #endif |
| 16 | |
| 17 | #include_next <stdlib.h> |
| 18 | |
| 19 | #elif !defined(_LIBCPP_STDLIB_H) |
| 20 | #define _LIBCPP_STDLIB_H |
| 21 | |
| 22 | /* |
| 23 | stdlib.h synopsis |
| 24 | |
| 25 | Macros: |
| 26 | |
| 27 | EXIT_FAILURE |
| 28 | EXIT_SUCCESS |
| 29 | MB_CUR_MAX |
| 30 | NULL |
| 31 | RAND_MAX |
| 32 | |
| 33 | Types: |
| 34 | |
| 35 | size_t |
| 36 | div_t |
| 37 | ldiv_t |
| 38 | lldiv_t // C99 |
| 39 | |
| 40 | double atof (const char* nptr); |
| 41 | int atoi (const char* nptr); |
| 42 | long atol (const char* nptr); |
| 43 | long long atoll(const char* nptr); // C99 |
| 44 | double strtod (const char* restrict nptr, char** restrict endptr); |
| 45 | float strtof (const char* restrict nptr, char** restrict endptr); // C99 |
| 46 | long double strtold (const char* restrict nptr, char** restrict endptr); // C99 |
| 47 | long strtol (const char* restrict nptr, char** restrict endptr, int base); |
| 48 | long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99 |
| 49 | unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base); |
| 50 | unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99 |
| 51 | int rand(void); |
| 52 | void srand(unsigned int seed); |
| 53 | void* calloc(size_t nmemb, size_t size); |
| 54 | void free(void* ptr); |
| 55 | void* malloc(size_t size); |
| 56 | void* realloc(void* ptr, size_t size); |
| 57 | void abort(void); |
| 58 | int atexit(void (*func)(void)); |
| 59 | void exit(int status); |
| 60 | void _Exit(int status); |
| 61 | char* getenv(const char* name); |
| 62 | int system(const char* string); |
| 63 | void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, |
| 64 | int (*compar)(const void *, const void *)); |
| 65 | void qsort(void* base, size_t nmemb, size_t size, |
| 66 | int (*compar)(const void *, const void *)); |
| 67 | int abs( int j); |
| 68 | long abs( long j); |
| 69 | long long abs(long long j); // C++0X |
| 70 | long labs( long j); |
| 71 | long long llabs(long long j); // C99 |
| 72 | div_t div( int numer, int denom); |
| 73 | ldiv_t div( long numer, long denom); |
| 74 | lldiv_t div(long long numer, long long denom); // C++0X |
| 75 | ldiv_t ldiv( long numer, long denom); |
| 76 | lldiv_t lldiv(long long numer, long long denom); // C99 |
| 77 | int mblen(const char* s, size_t n); |
| 78 | int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n); |
| 79 | int wctomb(char* s, wchar_t wchar); |
| 80 | size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n); |
| 81 | size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n); |
| 82 | int at_quick_exit(void (*func)(void)) // C++11 |
| 83 | void quick_exit(int status); // C++11 |
| 84 | void *aligned_alloc(size_t alignment, size_t size); // C11 |
| 85 | |
| 86 | */ |
| 87 | |
| 88 | #include <__config> |
| 89 | |
| 90 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 91 | #pragma GCC system_header |
| 92 | #endif |
| 93 | |
| 94 | #include_next <stdlib.h> |
| 95 | |
| 96 | #ifdef __cplusplus |
Eric Fiselier | 38e7a30 | 2015-11-06 06:30:12 +0000 | [diff] [blame] | 97 | |
Richard Smith | f650ea7 | 2015-10-09 01:41:45 +0000 | [diff] [blame] | 98 | extern "C++" { |
| 99 | |
| 100 | #ifdef _LIBCPP_MSVCRT |
| 101 | #include "support/win32/locale_win32.h" |
| 102 | #endif // _LIBCPP_MSVCRT |
| 103 | |
| 104 | #undef abs |
| 105 | #undef div |
| 106 | #undef labs |
| 107 | #undef ldiv |
| 108 | #ifndef _LIBCPP_HAS_NO_LONG_LONG |
| 109 | #undef llabs |
| 110 | #undef lldiv |
| 111 | #endif |
| 112 | |
| 113 | // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined |
| 114 | #if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) |
| 115 | inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);} |
| 116 | #ifndef _LIBCPP_HAS_NO_LONG_LONG |
| 117 | inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);} |
| 118 | #endif // _LIBCPP_HAS_NO_LONG_LONG |
| 119 | |
| 120 | inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);} |
| 121 | #ifndef _LIBCPP_HAS_NO_LONG_LONG |
| 122 | inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);} |
| 123 | #endif // _LIBCPP_HAS_NO_LONG_LONG |
| 124 | #endif // _LIBCPP_MSVCRT / __sun__ / _AIX |
| 125 | |
| 126 | } // extern "C++" |
Eric Fiselier | 38e7a30 | 2015-11-06 06:30:12 +0000 | [diff] [blame] | 127 | |
Richard Smith | f650ea7 | 2015-10-09 01:41:45 +0000 | [diff] [blame] | 128 | #endif // __cplusplus |
| 129 | |
| 130 | #endif // _LIBCPP_STDLIB_H |