136 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10/*11 stdlib.h synopsis12 13Macros:14 15 EXIT_FAILURE16 EXIT_SUCCESS17 MB_CUR_MAX18 NULL19 RAND_MAX20 21Types:22 23 size_t24 div_t25 ldiv_t26 lldiv_t // C9927 28double atof (const char* nptr);29int atoi (const char* nptr);30long atol (const char* nptr);31long long atoll(const char* nptr); // C9932double strtod (const char* restrict nptr, char** restrict endptr);33float strtof (const char* restrict nptr, char** restrict endptr); // C9934long double strtold (const char* restrict nptr, char** restrict endptr); // C9935long strtol (const char* restrict nptr, char** restrict endptr, int base);36long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C9937unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base);38unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C9939int rand(void);40void srand(unsigned int seed);41void* calloc(size_t nmemb, size_t size);42void free(void* ptr);43void* malloc(size_t size);44void* realloc(void* ptr, size_t size);45void abort(void);46int atexit(void (*func)(void));47void exit(int status);48void _Exit(int status);49char* getenv(const char* name);50int system(const char* string);51void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,52 int (*compar)(const void *, const void *));53void qsort(void* base, size_t nmemb, size_t size,54 int (*compar)(const void *, const void *));55int abs( int j);56long abs( long j);57long long abs(long long j); // C++0X58long labs( long j);59long long llabs(long long j); // C9960div_t div( int numer, int denom);61ldiv_t div( long numer, long denom);62lldiv_t div(long long numer, long long denom); // C++0X63ldiv_t ldiv( long numer, long denom);64lldiv_t lldiv(long long numer, long long denom); // C9965int mblen(const char* s, size_t n);66int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);67int wctomb(char* s, wchar_t wchar);68size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);69size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);70int at_quick_exit(void (*func)(void)) // C++1171void quick_exit(int status); // C++1172void *aligned_alloc(size_t alignment, size_t size); // C1173 74*/75 76#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)77# include <__cxx03/stdlib.h>78#else79# include <__config>80 81# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)82# pragma GCC system_header83# endif84 85// The inclusion of the system's <stdlib.h> is intentionally done once outside of any include86// guards because some code expects to be able to include the underlying system header multiple87// 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# endif91 92# if !defined(_LIBCPP_STDLIB_H)93# define _LIBCPP_STDLIB_H94 95# ifdef __cplusplus96extern "C++" {97// abs98 99# ifdef abs100# undef abs101# endif102# ifdef labs103# undef labs104# endif105# ifdef llabs106# undef llabs107# endif108 109# include <__math/abs.h>110using std::__math::abs;111 112// div113 114# ifdef div115# undef div116# endif117# ifdef ldiv118# undef ldiv119# endif120# ifdef lldiv121# undef lldiv122# endif123 124// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined125# if !defined(_LIBCPP_MSVCRT)126inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(__x, __y); }127# if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))128inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(__x, __y); }129# endif130# endif // _LIBCPP_MSVCRT131} // extern "C++"132# endif // __cplusplus133# endif // _LIBCPP_STDLIB_H134 135#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)136