xref: /netbsd-src/external/gpl3/gcc/dist/libstdc++-v3/include/c_std/cstdlib (revision b1e838363e3c6fc78a55519254d99869742dd33c)
14fee23f9Smrg// -*- C++ -*- forwarding header.
24fee23f9Smrg
3*b1e83836Smrg// Copyright (C) 1997-2022 Free Software Foundation, Inc.
44fee23f9Smrg//
54fee23f9Smrg// This file is part of the GNU ISO C++ Library.  This library is free
64fee23f9Smrg// software; you can redistribute it and/or modify it under the
74fee23f9Smrg// terms of the GNU General Public License as published by the
84fee23f9Smrg// Free Software Foundation; either version 3, or (at your option)
94fee23f9Smrg// any later version.
104fee23f9Smrg
114fee23f9Smrg// This library is distributed in the hope that it will be useful,
124fee23f9Smrg// but WITHOUT ANY WARRANTY; without even the implied warranty of
134fee23f9Smrg// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
144fee23f9Smrg// GNU General Public License for more details.
154fee23f9Smrg
164fee23f9Smrg// Under Section 7 of GPL version 3, you are granted additional
174fee23f9Smrg// permissions described in the GCC Runtime Library Exception, version
184fee23f9Smrg// 3.1, as published by the Free Software Foundation.
194fee23f9Smrg
204fee23f9Smrg// You should have received a copy of the GNU General Public License and
214fee23f9Smrg// a copy of the GCC Runtime Library Exception along with this program;
224fee23f9Smrg// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
234fee23f9Smrg// <http://www.gnu.org/licenses/>.
244fee23f9Smrg
254fee23f9Smrg/** @file include/cstdlib
264fee23f9Smrg *  This is a Standard C++ Library file.  You should @c #include this file
274fee23f9Smrg *  in your programs, rather than any of the @a *.h implementation files.
284fee23f9Smrg *
294fee23f9Smrg *  This is the C++ version of the Standard C Library header @c stdlib.h,
304fee23f9Smrg *  and its contents are (mostly) the same as that header, but are all
314fee23f9Smrg *  contained in the namespace @c std (except for names which are defined
324fee23f9Smrg *  as macros in C).
334fee23f9Smrg */
344fee23f9Smrg
354fee23f9Smrg//
364fee23f9Smrg// ISO C++ 14882: 20.4.6  C library
374fee23f9Smrg//
384fee23f9Smrg
394fee23f9Smrg#ifndef _GLIBCXX_CSTDLIB
404fee23f9Smrg#define _GLIBCXX_CSTDLIB 1
414fee23f9Smrg
424fee23f9Smrg#pragma GCC system_header
434fee23f9Smrg
444fee23f9Smrg#include <bits/c++config.h>
454fee23f9Smrg
464fee23f9Smrg#if !_GLIBCXX_HOSTED
474fee23f9Smrg// The C standard does not require a freestanding implementation to
484fee23f9Smrg// provide <stdlib.h>.  However, the C++ standard does still require
494fee23f9Smrg// <cstdlib> -- but only the functionality mentioned in
504fee23f9Smrg// [lib.support.start.term].
514fee23f9Smrg
524fee23f9Smrg#define EXIT_SUCCESS 0
534fee23f9Smrg#define EXIT_FAILURE 1
544fee23f9Smrg
5548fb7bfaSmrgnamespace std
5648fb7bfaSmrg{
574fee23f9Smrg  extern "C" void abort(void) throw () _GLIBCXX_NORETURN;
584d5abbe8Smrg  extern "C" int atexit(void (*)(void)) throw ();
594fee23f9Smrg  extern "C" void exit(int) throw () _GLIBCXX_NORETURN;
6048fb7bfaSmrg#if __cplusplus >= 201103L
6148fb7bfaSmrg# ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
624d5abbe8Smrg  extern "C" int at_quick_exit(void (*)(void)) throw ();
6348fb7bfaSmrg# endif
6448fb7bfaSmrg# ifdef _GLIBCXX_HAVE_QUICK_EXIT
6548fb7bfaSmrg  extern "C" void quick_exit(int) throw() _GLIBCXX_NORETURN;
6648fb7bfaSmrg# endif
6748fb7bfaSmrg#endif
6848fb7bfaSmrg} // namespace
694fee23f9Smrg
704fee23f9Smrg#else
714fee23f9Smrg
724fee23f9Smrg#include <stdlib.h>
734fee23f9Smrg
744fee23f9Smrg// Get rid of those macros defined in <stdlib.h> in lieu of real functions.
754fee23f9Smrg#undef abort
764fee23f9Smrg#undef abs
774fee23f9Smrg#undef atexit
7848fb7bfaSmrg#if __cplusplus >= 201103L
7948fb7bfaSmrg# ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
8048fb7bfaSmrg#  undef at_quick_exit
8148fb7bfaSmrg# endif
8248fb7bfaSmrg#endif
834fee23f9Smrg#undef atof
844fee23f9Smrg#undef atoi
854fee23f9Smrg#undef atol
864fee23f9Smrg#undef bsearch
874fee23f9Smrg#undef calloc
884fee23f9Smrg#undef div
894fee23f9Smrg#undef exit
904fee23f9Smrg#undef free
914fee23f9Smrg#undef getenv
924fee23f9Smrg#undef labs
934fee23f9Smrg#undef ldiv
944fee23f9Smrg#undef malloc
954fee23f9Smrg#undef mblen
964fee23f9Smrg#undef mbstowcs
974fee23f9Smrg#undef mbtowc
984fee23f9Smrg#undef qsort
9948fb7bfaSmrg#if __cplusplus >= 201103L
10048fb7bfaSmrg# ifdef _GLIBCXX_HAVE_QUICK_EXIT
10148fb7bfaSmrg#  undef quick_exit
10248fb7bfaSmrg# endif
10348fb7bfaSmrg#endif
1044fee23f9Smrg#undef rand
1054fee23f9Smrg#undef realloc
1064fee23f9Smrg#undef srand
1074fee23f9Smrg#undef strtod
1084fee23f9Smrg#undef strtol
1094fee23f9Smrg#undef strtoul
1104fee23f9Smrg#undef system
1114fee23f9Smrg#undef wcstombs
1124fee23f9Smrg#undef wctomb
1134fee23f9Smrg
11448fb7bfaSmrgnamespace std _GLIBCXX_VISIBILITY(default)
11548fb7bfaSmrg{
11648fb7bfaSmrg_GLIBCXX_BEGIN_NAMESPACE_VERSION
1174fee23f9Smrg
1184fee23f9Smrg  using ::div_t;
1194fee23f9Smrg  using ::ldiv_t;
1204fee23f9Smrg
1214fee23f9Smrg  using ::abort;
1224fee23f9Smrg  using ::abs;
1234fee23f9Smrg  using ::atexit;
12448fb7bfaSmrg#if __cplusplus >= 201103L
12548fb7bfaSmrg# ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
12648fb7bfaSmrg  using ::at_quick_exit;
12748fb7bfaSmrg# endif
12848fb7bfaSmrg#endif
1294fee23f9Smrg  using ::atof;
1304fee23f9Smrg  using ::atoi;
1314fee23f9Smrg  using ::atol;
1324fee23f9Smrg  using ::bsearch;
1334fee23f9Smrg  using ::calloc;
1344fee23f9Smrg  using ::div;
1354fee23f9Smrg  using ::exit;
1364fee23f9Smrg  using ::free;
1374fee23f9Smrg  using ::getenv;
1384fee23f9Smrg  using ::labs;
1394fee23f9Smrg  using ::ldiv;
1404fee23f9Smrg  using ::malloc;
1414fee23f9Smrg#ifdef _GLIBCXX_HAVE_MBSTATE_T
1424fee23f9Smrg  using ::mblen;
1434fee23f9Smrg  using ::mbstowcs;
1444fee23f9Smrg  using ::mbtowc;
1454fee23f9Smrg#endif // _GLIBCXX_HAVE_MBSTATE_T
1464fee23f9Smrg  using ::qsort;
14748fb7bfaSmrg#if __cplusplus >= 201103L
14848fb7bfaSmrg# ifdef _GLIBCXX_HAVE_QUICK_EXIT
14948fb7bfaSmrg  using ::quick_exit;
15048fb7bfaSmrg# endif
15148fb7bfaSmrg#endif
1524fee23f9Smrg  using ::rand;
1534fee23f9Smrg  using ::realloc;
1544fee23f9Smrg  using ::srand;
1554fee23f9Smrg  using ::strtod;
1564fee23f9Smrg  using ::strtol;
1574fee23f9Smrg  using ::strtoul;
1584fee23f9Smrg  using ::system;
1594fee23f9Smrg#ifdef _GLIBCXX_USE_WCHAR_T
1604fee23f9Smrg  using ::wcstombs;
1614fee23f9Smrg  using ::wctomb;
1624fee23f9Smrg#endif // _GLIBCXX_USE_WCHAR_T
1634fee23f9Smrg
1644fee23f9Smrg  inline long
16548fb7bfaSmrg  abs(long __i) { return __builtin_labs(__i); }
16648fb7bfaSmrg
16748fb7bfaSmrg#ifdef _GLIBCXX_USE_LONG_LONG
16848fb7bfaSmrg  inline long long
16948fb7bfaSmrg  abs(long long __x) { return __builtin_llabs (__x); }
17048fb7bfaSmrg#endif
17148fb7bfaSmrg
1724d5abbe8Smrg#if defined(__GLIBCXX_TYPE_INT_N_0)
1734d5abbe8Smrg  inline __GLIBCXX_TYPE_INT_N_0
1744d5abbe8Smrg  abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
1754d5abbe8Smrg#endif
1764d5abbe8Smrg#if defined(__GLIBCXX_TYPE_INT_N_1)
1774d5abbe8Smrg  inline __GLIBCXX_TYPE_INT_N_1
1784d5abbe8Smrg  abs(__GLIBCXX_TYPE_INT_N_1 __x) { return __x >= 0 ? __x : -__x; }
1794d5abbe8Smrg#endif
1804d5abbe8Smrg#if defined(__GLIBCXX_TYPE_INT_N_2)
1814d5abbe8Smrg  inline __GLIBCXX_TYPE_INT_N_2
1824d5abbe8Smrg  abs(__GLIBCXX_TYPE_INT_N_2 __x) { return __x >= 0 ? __x : -__x; }
1834d5abbe8Smrg#endif
1844d5abbe8Smrg#if defined(__GLIBCXX_TYPE_INT_N_3)
1854d5abbe8Smrg  inline __GLIBCXX_TYPE_INT_N_3
1864d5abbe8Smrg  abs(__GLIBCXX_TYPE_INT_N_3 __x) { return __x >= 0 ? __x : -__x; }
18748fb7bfaSmrg#endif
1884fee23f9Smrg
1894fee23f9Smrg  inline ldiv_t
1904fee23f9Smrg  div(long __i, long __j) { return ldiv(__i, __j); }
1914fee23f9Smrg
19248fb7bfaSmrg_GLIBCXX_END_NAMESPACE_VERSION
19348fb7bfaSmrg} // namespace
1944fee23f9Smrg
195f9a78e0eSmrg#if _GLIBCXX_USE_C99_STDLIB
1964fee23f9Smrg
1974fee23f9Smrg#undef _Exit
1984fee23f9Smrg#undef llabs
1994fee23f9Smrg#undef lldiv
2004fee23f9Smrg#undef atoll
2014fee23f9Smrg#undef strtoll
2024fee23f9Smrg#undef strtoull
2034fee23f9Smrg#undef strtof
2044fee23f9Smrg#undef strtold
2054fee23f9Smrg
20648fb7bfaSmrgnamespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
20748fb7bfaSmrg{
20848fb7bfaSmrg_GLIBCXX_BEGIN_NAMESPACE_VERSION
2094fee23f9Smrg
2104fee23f9Smrg#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
2114fee23f9Smrg  using ::lldiv_t;
2124fee23f9Smrg#endif
2134fee23f9Smrg#if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
2144fee23f9Smrg  extern "C" void (_Exit)(int) throw () _GLIBCXX_NORETURN;
2154fee23f9Smrg#endif
2164fee23f9Smrg#if !_GLIBCXX_USE_C99_DYNAMIC
2174fee23f9Smrg  using ::_Exit;
2184fee23f9Smrg#endif
2194fee23f9Smrg
2204fee23f9Smrg#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
2214fee23f9Smrg  using ::llabs;
2224fee23f9Smrg
2234fee23f9Smrg  inline lldiv_t
2244fee23f9Smrg  div(long long __n, long long __d)
2254fee23f9Smrg  { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
2264fee23f9Smrg
2274fee23f9Smrg  using ::lldiv;
2284fee23f9Smrg#endif
2294fee23f9Smrg
2304fee23f9Smrg#if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
2314fee23f9Smrg  extern "C" long long int (atoll)(const char *) throw ();
2324fee23f9Smrg  extern "C" long long int
23348fb7bfaSmrg    (strtoll)(const char * __restrict, char ** __restrict, int) throw ();
2344fee23f9Smrg  extern "C" unsigned long long int
23548fb7bfaSmrg    (strtoull)(const char * __restrict, char ** __restrict, int) throw ();
2364fee23f9Smrg#endif
2374fee23f9Smrg#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
2384fee23f9Smrg  using ::atoll;
2394fee23f9Smrg  using ::strtoll;
2404fee23f9Smrg  using ::strtoull;
2414fee23f9Smrg#endif
2424fee23f9Smrg  using ::strtof;
2434fee23f9Smrg  using ::strtold;
2444fee23f9Smrg
24548fb7bfaSmrg_GLIBCXX_END_NAMESPACE_VERSION
24648fb7bfaSmrg} // namespace __gnu_cxx
2474fee23f9Smrg
24848fb7bfaSmrgnamespace std
24948fb7bfaSmrg{
2504fee23f9Smrg#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
2514fee23f9Smrg  using ::__gnu_cxx::lldiv_t;
2524fee23f9Smrg#endif
2534fee23f9Smrg  using ::__gnu_cxx::_Exit;
2544fee23f9Smrg#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
2554fee23f9Smrg  using ::__gnu_cxx::llabs;
2564fee23f9Smrg  using ::__gnu_cxx::div;
2574fee23f9Smrg  using ::__gnu_cxx::lldiv;
2584fee23f9Smrg#endif
2594fee23f9Smrg  using ::__gnu_cxx::atoll;
2604fee23f9Smrg  using ::__gnu_cxx::strtof;
2614fee23f9Smrg  using ::__gnu_cxx::strtoll;
2624fee23f9Smrg  using ::__gnu_cxx::strtoull;
2634fee23f9Smrg  using ::__gnu_cxx::strtold;
26448fb7bfaSmrg} // namespace std
2654fee23f9Smrg
266f9a78e0eSmrg#endif // _GLIBCXX_USE_C99_STDLIB
2674fee23f9Smrg
2684fee23f9Smrg#endif // !_GLIBCXX_HOSTED
2694fee23f9Smrg
2704fee23f9Smrg#endif
271