xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/stdlib.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric // -*- C++ -*-
2*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
3*700637cbSDimitry Andric //
4*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*700637cbSDimitry Andric //
8*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
9*700637cbSDimitry Andric 
10*700637cbSDimitry Andric #if defined(__need_malloc_and_calloc)
11*700637cbSDimitry Andric 
12*700637cbSDimitry Andric #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
13*700637cbSDimitry Andric #    pragma GCC system_header
14*700637cbSDimitry Andric #  endif
15*700637cbSDimitry Andric 
16*700637cbSDimitry Andric #  include_next <stdlib.h>
17*700637cbSDimitry Andric 
18*700637cbSDimitry Andric #elif !defined(_LIBCPP___CXX03_STDLIB_H)
19*700637cbSDimitry Andric #  define _LIBCPP___CXX03_STDLIB_H
20*700637cbSDimitry Andric 
21*700637cbSDimitry Andric /*
22*700637cbSDimitry Andric     stdlib.h synopsis
23*700637cbSDimitry Andric 
24*700637cbSDimitry Andric Macros:
25*700637cbSDimitry Andric 
26*700637cbSDimitry Andric     EXIT_FAILURE
27*700637cbSDimitry Andric     EXIT_SUCCESS
28*700637cbSDimitry Andric     MB_CUR_MAX
29*700637cbSDimitry Andric     NULL
30*700637cbSDimitry Andric     RAND_MAX
31*700637cbSDimitry Andric 
32*700637cbSDimitry Andric Types:
33*700637cbSDimitry Andric 
34*700637cbSDimitry Andric     size_t
35*700637cbSDimitry Andric     div_t
36*700637cbSDimitry Andric     ldiv_t
37*700637cbSDimitry Andric     lldiv_t                                                               // C99
38*700637cbSDimitry Andric 
39*700637cbSDimitry Andric double    atof (const char* nptr);
40*700637cbSDimitry Andric int       atoi (const char* nptr);
41*700637cbSDimitry Andric long      atol (const char* nptr);
42*700637cbSDimitry Andric long long atoll(const char* nptr);                                        // C99
43*700637cbSDimitry Andric double             strtod  (const char* restrict nptr, char** restrict endptr);
44*700637cbSDimitry Andric float              strtof  (const char* restrict nptr, char** restrict endptr); // C99
45*700637cbSDimitry Andric long double        strtold (const char* restrict nptr, char** restrict endptr); // C99
46*700637cbSDimitry Andric long               strtol  (const char* restrict nptr, char** restrict endptr, int base);
47*700637cbSDimitry Andric long long          strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99
48*700637cbSDimitry Andric unsigned long      strtoul (const char* restrict nptr, char** restrict endptr, int base);
49*700637cbSDimitry Andric unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99
50*700637cbSDimitry Andric int rand(void);
51*700637cbSDimitry Andric void srand(unsigned int seed);
52*700637cbSDimitry Andric void* calloc(size_t nmemb, size_t size);
53*700637cbSDimitry Andric void free(void* ptr);
54*700637cbSDimitry Andric void* malloc(size_t size);
55*700637cbSDimitry Andric void* realloc(void* ptr, size_t size);
56*700637cbSDimitry Andric void abort(void);
57*700637cbSDimitry Andric int atexit(void (*func)(void));
58*700637cbSDimitry Andric void exit(int status);
59*700637cbSDimitry Andric void _Exit(int status);
60*700637cbSDimitry Andric char* getenv(const char* name);
61*700637cbSDimitry Andric int system(const char* string);
62*700637cbSDimitry Andric void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
63*700637cbSDimitry Andric               int (*compar)(const void *, const void *));
64*700637cbSDimitry Andric void qsort(void* base, size_t nmemb, size_t size,
65*700637cbSDimitry Andric            int (*compar)(const void *, const void *));
66*700637cbSDimitry Andric int         abs(      int j);
67*700637cbSDimitry Andric long        abs(     long j);
68*700637cbSDimitry Andric long long   abs(long long j);                                             // C++0X
69*700637cbSDimitry Andric long       labs(     long j);
70*700637cbSDimitry Andric long long llabs(long long j);                                             // C99
71*700637cbSDimitry Andric div_t     div(      int numer,       int denom);
72*700637cbSDimitry Andric ldiv_t    div(     long numer,      long denom);
73*700637cbSDimitry Andric lldiv_t   div(long long numer, long long denom);                          // C++0X
74*700637cbSDimitry Andric ldiv_t   ldiv(     long numer,      long denom);
75*700637cbSDimitry Andric lldiv_t lldiv(long long numer, long long denom);                          // C99
76*700637cbSDimitry Andric int mblen(const char* s, size_t n);
77*700637cbSDimitry Andric int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);
78*700637cbSDimitry Andric int wctomb(char* s, wchar_t wchar);
79*700637cbSDimitry Andric size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);
80*700637cbSDimitry Andric size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);
81*700637cbSDimitry Andric int at_quick_exit(void (*func)(void))                                     // C++11
82*700637cbSDimitry Andric void quick_exit(int status);                                              // C++11
83*700637cbSDimitry Andric void *aligned_alloc(size_t alignment, size_t size);                       // C11
84*700637cbSDimitry Andric 
85*700637cbSDimitry Andric */
86*700637cbSDimitry Andric 
87*700637cbSDimitry Andric #  include <__cxx03/__config>
88*700637cbSDimitry Andric 
89*700637cbSDimitry Andric #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
90*700637cbSDimitry Andric #    pragma GCC system_header
91*700637cbSDimitry Andric #  endif
92*700637cbSDimitry Andric 
93*700637cbSDimitry Andric #  if __has_include_next(<stdlib.h>)
94*700637cbSDimitry Andric #    include_next <stdlib.h>
95*700637cbSDimitry Andric #  endif
96*700637cbSDimitry Andric 
97*700637cbSDimitry Andric #  ifdef __cplusplus
98*700637cbSDimitry Andric extern "C++" {
99*700637cbSDimitry Andric // abs
100*700637cbSDimitry Andric 
101*700637cbSDimitry Andric #    ifdef abs
102*700637cbSDimitry Andric #      undef abs
103*700637cbSDimitry Andric #    endif
104*700637cbSDimitry Andric #    ifdef labs
105*700637cbSDimitry Andric #      undef labs
106*700637cbSDimitry Andric #    endif
107*700637cbSDimitry Andric #    ifdef llabs
108*700637cbSDimitry Andric #      undef llabs
109*700637cbSDimitry Andric #    endif
110*700637cbSDimitry Andric 
111*700637cbSDimitry Andric // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
112*700637cbSDimitry Andric #    if !defined(_LIBCPP_MSVCRT)
abs(long __x)113*700637cbSDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long abs(long __x) _NOEXCEPT { return __builtin_labs(__x); }
abs(long long __x)114*700637cbSDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long long abs(long long __x) _NOEXCEPT { return __builtin_llabs(__x); }
115*700637cbSDimitry Andric #    endif // !defined(_LIBCPP_MSVCRT)
116*700637cbSDimitry Andric 
abs(float __lcpp_x)117*700637cbSDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float abs(float __lcpp_x) _NOEXCEPT {
118*700637cbSDimitry Andric   return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h
119*700637cbSDimitry Andric }
120*700637cbSDimitry Andric 
abs(double __lcpp_x)121*700637cbSDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double abs(double __lcpp_x) _NOEXCEPT {
122*700637cbSDimitry Andric   return __builtin_fabs(__lcpp_x);
123*700637cbSDimitry Andric }
124*700637cbSDimitry Andric 
abs(long double __lcpp_x)125*700637cbSDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __lcpp_x) _NOEXCEPT {
126*700637cbSDimitry Andric   return __builtin_fabsl(__lcpp_x);
127*700637cbSDimitry Andric }
128*700637cbSDimitry Andric 
129*700637cbSDimitry Andric // div
130*700637cbSDimitry Andric 
131*700637cbSDimitry Andric #    ifdef div
132*700637cbSDimitry Andric #      undef div
133*700637cbSDimitry Andric #    endif
134*700637cbSDimitry Andric #    ifdef ldiv
135*700637cbSDimitry Andric #      undef ldiv
136*700637cbSDimitry Andric #    endif
137*700637cbSDimitry Andric #    ifdef lldiv
138*700637cbSDimitry Andric #      undef lldiv
139*700637cbSDimitry Andric #    endif
140*700637cbSDimitry Andric 
141*700637cbSDimitry Andric // MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
142*700637cbSDimitry Andric #    if !defined(_LIBCPP_MSVCRT)
div(long __x,long __y)143*700637cbSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(__x, __y); }
144*700637cbSDimitry Andric #      if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))
div(long long __x,long long __y)145*700637cbSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(__x, __y); }
146*700637cbSDimitry Andric #      endif
147*700637cbSDimitry Andric #    endif // _LIBCPP_MSVCRT
148*700637cbSDimitry Andric } // extern "C++"
149*700637cbSDimitry Andric #  endif   // __cplusplus
150*700637cbSDimitry Andric 
151*700637cbSDimitry Andric #endif // _LIBCPP___CXX03_STDLIB_H
152