10b57cec5SDimitry Andric // -*- C++ -*- 2349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric // 40b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric // 80b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 105ffd83dbSDimitry Andric #if defined(__need_malloc_and_calloc) 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 130b57cec5SDimitry Andric # pragma GCC system_header 140b57cec5SDimitry Andric # endif 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric # include_next <stdlib.h> 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric #elif !defined(_LIBCPP_STDLIB_H) 190b57cec5SDimitry Andric # define _LIBCPP_STDLIB_H 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric /* 220b57cec5SDimitry Andric stdlib.h synopsis 230b57cec5SDimitry Andric 240b57cec5SDimitry Andric Macros: 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric EXIT_FAILURE 270b57cec5SDimitry Andric EXIT_SUCCESS 280b57cec5SDimitry Andric MB_CUR_MAX 290b57cec5SDimitry Andric NULL 300b57cec5SDimitry Andric RAND_MAX 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric Types: 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric size_t 350b57cec5SDimitry Andric div_t 360b57cec5SDimitry Andric ldiv_t 370b57cec5SDimitry Andric lldiv_t // C99 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric double atof (const char* nptr); 400b57cec5SDimitry Andric int atoi (const char* nptr); 410b57cec5SDimitry Andric long atol (const char* nptr); 420b57cec5SDimitry Andric long long atoll(const char* nptr); // C99 430b57cec5SDimitry Andric double strtod (const char* restrict nptr, char** restrict endptr); 440b57cec5SDimitry Andric float strtof (const char* restrict nptr, char** restrict endptr); // C99 450b57cec5SDimitry Andric long double strtold (const char* restrict nptr, char** restrict endptr); // C99 460b57cec5SDimitry Andric long strtol (const char* restrict nptr, char** restrict endptr, int base); 470b57cec5SDimitry Andric long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99 480b57cec5SDimitry Andric unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base); 490b57cec5SDimitry Andric unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99 500b57cec5SDimitry Andric int rand(void); 510b57cec5SDimitry Andric void srand(unsigned int seed); 520b57cec5SDimitry Andric void* calloc(size_t nmemb, size_t size); 530b57cec5SDimitry Andric void free(void* ptr); 540b57cec5SDimitry Andric void* malloc(size_t size); 550b57cec5SDimitry Andric void* realloc(void* ptr, size_t size); 560b57cec5SDimitry Andric void abort(void); 570b57cec5SDimitry Andric int atexit(void (*func)(void)); 580b57cec5SDimitry Andric void exit(int status); 590b57cec5SDimitry Andric void _Exit(int status); 600b57cec5SDimitry Andric char* getenv(const char* name); 610b57cec5SDimitry Andric int system(const char* string); 620b57cec5SDimitry Andric void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, 630b57cec5SDimitry Andric int (*compar)(const void *, const void *)); 640b57cec5SDimitry Andric void qsort(void* base, size_t nmemb, size_t size, 650b57cec5SDimitry Andric int (*compar)(const void *, const void *)); 660b57cec5SDimitry Andric int abs( int j); 670b57cec5SDimitry Andric long abs( long j); 680b57cec5SDimitry Andric long long abs(long long j); // C++0X 690b57cec5SDimitry Andric long labs( long j); 700b57cec5SDimitry Andric long long llabs(long long j); // C99 710b57cec5SDimitry Andric div_t div( int numer, int denom); 720b57cec5SDimitry Andric ldiv_t div( long numer, long denom); 730b57cec5SDimitry Andric lldiv_t div(long long numer, long long denom); // C++0X 740b57cec5SDimitry Andric ldiv_t ldiv( long numer, long denom); 750b57cec5SDimitry Andric lldiv_t lldiv(long long numer, long long denom); // C99 760b57cec5SDimitry Andric int mblen(const char* s, size_t n); 770b57cec5SDimitry Andric int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n); 780b57cec5SDimitry Andric int wctomb(char* s, wchar_t wchar); 790b57cec5SDimitry Andric size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n); 800b57cec5SDimitry Andric size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n); 810b57cec5SDimitry Andric int at_quick_exit(void (*func)(void)) // C++11 820b57cec5SDimitry Andric void quick_exit(int status); // C++11 830b57cec5SDimitry Andric void *aligned_alloc(size_t alignment, size_t size); // C11 840b57cec5SDimitry Andric 850b57cec5SDimitry Andric */ 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric # include <__config> 880b57cec5SDimitry Andric 890b57cec5SDimitry Andric # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 900b57cec5SDimitry Andric # pragma GCC system_header 910b57cec5SDimitry Andric # endif 920b57cec5SDimitry Andric 93bdd1243dSDimitry Andric # if __has_include_next(<stdlib.h>) 940b57cec5SDimitry Andric # include_next <stdlib.h> 95bdd1243dSDimitry Andric # endif 960b57cec5SDimitry Andric 970b57cec5SDimitry Andric # ifdef __cplusplus 985ffd83dbSDimitry Andric extern "C++" { 995ffd83dbSDimitry Andric // abs 1005ffd83dbSDimitry Andric 101349cc55cSDimitry Andric # ifdef abs 1025ffd83dbSDimitry Andric # undef abs 103349cc55cSDimitry Andric # endif 104349cc55cSDimitry Andric # ifdef labs 1055ffd83dbSDimitry Andric # undef labs 106349cc55cSDimitry Andric # endif 107349cc55cSDimitry Andric # ifdef llabs 1085ffd83dbSDimitry Andric # undef llabs 1095ffd83dbSDimitry Andric # endif 1105ffd83dbSDimitry Andric 1115ffd83dbSDimitry Andric // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined 11206c3fb27SDimitry Andric # if !defined(_LIBCPP_MSVCRT) 113*0fca6ea1SDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long abs(long __x) _NOEXCEPT { return __builtin_labs(__x); } 114*0fca6ea1SDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long long abs(long long __x) _NOEXCEPT { return __builtin_llabs(__x); } 11506c3fb27SDimitry Andric # endif // !defined(_LIBCPP_MSVCRT) 1165ffd83dbSDimitry Andric 117*0fca6ea1SDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float abs(float __lcpp_x) _NOEXCEPT { 1185ffd83dbSDimitry Andric return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h 1195ffd83dbSDimitry Andric } 1205ffd83dbSDimitry Andric 121*0fca6ea1SDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double abs(double __lcpp_x) _NOEXCEPT { 1225ffd83dbSDimitry Andric return __builtin_fabs(__lcpp_x); 1235ffd83dbSDimitry Andric } 1245ffd83dbSDimitry Andric 125*0fca6ea1SDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __lcpp_x) _NOEXCEPT { 1265ffd83dbSDimitry Andric return __builtin_fabsl(__lcpp_x); 1275ffd83dbSDimitry Andric } 1285ffd83dbSDimitry Andric 1295ffd83dbSDimitry Andric // div 1305ffd83dbSDimitry Andric 131349cc55cSDimitry Andric # ifdef div 1325ffd83dbSDimitry Andric # undef div 133349cc55cSDimitry Andric # endif 134349cc55cSDimitry Andric # ifdef ldiv 1355ffd83dbSDimitry Andric # undef ldiv 136349cc55cSDimitry Andric # endif 137349cc55cSDimitry Andric # ifdef lldiv 1385ffd83dbSDimitry Andric # undef lldiv 1395ffd83dbSDimitry Andric # endif 1405ffd83dbSDimitry Andric 1415ffd83dbSDimitry Andric // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined 14206c3fb27SDimitry Andric # if !defined(_LIBCPP_MSVCRT) 143cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(__x, __y); } 144349cc55cSDimitry Andric # if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED)) 145cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(__x, __y); } 146349cc55cSDimitry Andric # endif 14706c3fb27SDimitry Andric # endif // _LIBCPP_MSVCRT 1485ffd83dbSDimitry Andric } // extern "C++" 1490b57cec5SDimitry Andric # endif // __cplusplus 1500b57cec5SDimitry Andric 1510b57cec5SDimitry Andric #endif // _LIBCPP_STDLIB_H 152