master
  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-exception
  7//
  8//===----------------------------------------------------------------------===//
  9
 10/*
 11    stdlib.h synopsis
 12
 13Macros:
 14
 15    EXIT_FAILURE
 16    EXIT_SUCCESS
 17    MB_CUR_MAX
 18    NULL
 19    RAND_MAX
 20
 21Types:
 22
 23    size_t
 24    div_t
 25    ldiv_t
 26    lldiv_t                                                               // C99
 27
 28double    atof (const char* nptr);
 29int       atoi (const char* nptr);
 30long      atol (const char* nptr);
 31long long atoll(const char* nptr);                                        // C99
 32double             strtod  (const char* restrict nptr, char** restrict endptr);
 33float              strtof  (const char* restrict nptr, char** restrict endptr); // C99
 34long double        strtold (const char* restrict nptr, char** restrict endptr); // C99
 35long               strtol  (const char* restrict nptr, char** restrict endptr, int base);
 36long long          strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99
 37unsigned long      strtoul (const char* restrict nptr, char** restrict endptr, int base);
 38unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99
 39int 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++0X
 58long       labs(     long j);
 59long long llabs(long long j);                                             // C99
 60div_t     div(      int numer,       int denom);
 61ldiv_t    div(     long numer,      long denom);
 62lldiv_t   div(long long numer, long long denom);                          // C++0X
 63ldiv_t   ldiv(     long numer,      long denom);
 64lldiv_t lldiv(long long numer, long long denom);                          // C99
 65int 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++11
 71void quick_exit(int status);                                              // C++11
 72void *aligned_alloc(size_t alignment, size_t size);                       // C11
 73
 74*/
 75
 76#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
 77#  include <__cxx03/stdlib.h>
 78#else
 79#  include <__config>
 80
 81#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 82#    pragma GCC system_header
 83#  endif
 84
 85// The inclusion of the system's <stdlib.h> is intentionally done once outside of any include
 86// guards because some code expects to be able to include the underlying system header multiple
 87// 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#  endif
 91
 92#  if !defined(_LIBCPP_STDLIB_H)
 93#    define _LIBCPP_STDLIB_H
 94
 95#    ifdef __cplusplus
 96extern "C++" {
 97// abs
 98
 99#      ifdef abs
100#        undef abs
101#      endif
102#      ifdef labs
103#        undef labs
104#      endif
105#      ifdef llabs
106#        undef llabs
107#      endif
108
109#      include <__math/abs.h>
110using std::__math::abs;
111
112// div
113
114#      ifdef div
115#        undef div
116#      endif
117#      ifdef ldiv
118#        undef ldiv
119#      endif
120#      ifdef lldiv
121#        undef lldiv
122#      endif
123
124// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
125#      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#        endif
130#      endif // _LIBCPP_MSVCRT
131} // extern "C++"
132#    endif   // __cplusplus
133#  endif     // _LIBCPP_STDLIB_H
134
135#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)