std_cstdlib.h revision 302408
10Sduke// -*- C++ -*- forwarding header. 213005Sgtriantafill 30Sduke// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 40Sduke// Free Software Foundation, Inc. 50Sduke// 60Sduke// This file is part of the GNU ISO C++ Library. This library is free 70Sduke// software; you can redistribute it and/or modify it under the 80Sduke// terms of the GNU General Public License as published by the 90Sduke// Free Software Foundation; either version 2, or (at your option) 100Sduke// any later version. 110Sduke 120Sduke// This library is distributed in the hope that it will be useful, 130Sduke// but WITHOUT ANY WARRANTY; without even the implied warranty of 140Sduke// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 150Sduke// GNU General Public License for more details. 160Sduke 170Sduke// You should have received a copy of the GNU General Public License along 180Sduke// with this library; see the file COPYING. If not, write to the Free 191472Strims// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 201472Strims// USA. 211472Strims 220Sduke// As a special exception, you may use this file as part of a free software 230Sduke// library without restriction. Specifically, if other files instantiate 240Sduke// templates or use macros or inline functions from this file, or you compile 251879Sstefank// this file and link it with other files to produce an executable, this 261879Sstefank// file does not by itself cause the resulting executable to be covered by 271879Sstefank// the GNU General Public License. This exception does not however 280Sduke// invalidate any other reasons why the executable file might be covered by 290Sduke// the GNU General Public License. 300Sduke 310Sduke/** @file include/cstdlib 320Sduke * This is a Standard C++ Library file. You should @c #include this file 330Sduke * in your programs, rather than any of the "*.h" implementation files. 340Sduke * 350Sduke * This is the C++ version of the Standard C Library header @c stdlib.h, 360Sduke * and its contents are (mostly) the same as that header, but are all 370Sduke * contained in the namespace @c std (except for names which are defined 380Sduke * as macros in C). 390Sduke */ 400Sduke 410Sduke// 420Sduke// ISO C++ 14882: 20.4.6 C library 430Sduke// 440Sduke 450Sduke#ifndef _GLIBCXX_CSTDLIB 460Sduke#define _GLIBCXX_CSTDLIB 1 470Sduke 480Sduke#pragma GCC system_header 490Sduke 500Sduke#include <bits/c++config.h> 510Sduke#include <cstddef> 520Sduke 530Sduke#if !_GLIBCXX_HOSTED 540Sduke// The C standard does not require a freestanding implementation to 550Sduke// provide <stdlib.h>. However, the C++ standard does still require 560Sduke// <cstdlib> -- but only the functionality mentioned in 570Sduke// [lib.support.start.term]. 580Sduke 590Sduke#define EXIT_SUCCESS 0 600Sduke#define EXIT_FAILURE 1 610Sduke 620Sduke_GLIBCXX_BEGIN_NAMESPACE(std) 630Sduke 640Sduke extern "C" void abort(void); 650Sduke extern "C" int atexit(void (*)()); 660Sduke extern "C" void exit(int); 670Sduke 680Sduke_GLIBCXX_END_NAMESPACE 690Sduke 700Sduke#else 710Sduke 720Sduke#include <stdlib.h> 730Sduke 740Sduke// Get rid of those macros defined in <stdlib.h> in lieu of real functions. 750Sduke#undef abort 760Sduke#undef abs 770Sduke#undef atexit 780Sduke#undef atof 790Sduke#undef atoi 800Sduke#undef atol 810Sduke#undef bsearch 820Sduke#undef calloc 830Sduke#undef div 840Sduke#undef exit 852771Skvn#undef free 862771Skvn#undef getenv 872771Skvn#undef labs 882771Skvn#undef ldiv 892771Skvn#undef malloc 902771Skvn#undef mblen 912771Skvn#undef mbstowcs 922771Skvn#undef mbtowc 932771Skvn#undef qsort 942771Skvn#undef rand 952771Skvn#undef realloc 962771Skvn#undef srand 972771Skvn#undef strtod 980Sduke#undef strtol 990Sduke#undef strtoul 1000Sduke#undef system 1012771Skvn#undef wcstombs 1022771Skvn#undef wctomb 1032771Skvn 1042771Skvn_GLIBCXX_BEGIN_NAMESPACE(std) 1052771Skvn 1062771Skvn using ::div_t; 1072771Skvn using ::ldiv_t; 1082771Skvn 1092771Skvn using ::abort; 1102771Skvn using ::abs; 1112771Skvn using ::atexit; 1122771Skvn using ::atof; 1132771Skvn using ::atoi; 1140Sduke using ::atol; 1150Sduke using ::bsearch; 1160Sduke using ::calloc; 1170Sduke using ::div; 1180Sduke using ::exit; 1190Sduke using ::free; 1200Sduke using ::getenv; 1210Sduke using ::labs; 1220Sduke using ::ldiv; 1230Sduke using ::malloc; 1240Sduke#ifdef _GLIBCXX_HAVE_MBSTATE_T 1250Sduke using ::mblen; 1260Sduke using ::mbstowcs; 1270Sduke using ::mbtowc; 1280Sduke#endif // _GLIBCXX_HAVE_MBSTATE_T 1290Sduke using ::qsort; 1300Sduke using ::rand; 1310Sduke using ::realloc; 1320Sduke using ::srand; 1330Sduke using ::strtod; 1340Sduke using ::strtol; 1350Sduke using ::strtoul; 1360Sduke using ::system; 1370Sduke#ifdef _GLIBCXX_USE_WCHAR_T 1380Sduke using ::wcstombs; 1390Sduke using ::wctomb; 1400Sduke#endif // _GLIBCXX_USE_WCHAR_T 1410Sduke 1420Sduke inline long 1430Sduke abs(long __i) { return labs(__i); } 1440Sduke 1450Sduke inline ldiv_t 1460Sduke div(long __i, long __j) { return ldiv(__i, __j); } 1470Sduke 1480Sduke_GLIBCXX_END_NAMESPACE 1490Sduke 1500Sduke#if _GLIBCXX_USE_C99 1510Sduke 1520Sduke#undef _Exit 1530Sduke#undef llabs 1540Sduke#undef lldiv 1550Sduke#undef atoll 1560Sduke#undef strtoll 1570Sduke#undef strtoull 1580Sduke#undef strtof 159113Scoleenp#undef strtold 160113Scoleenp 161113Scoleenp_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 162113Scoleenp 163113Scoleenp#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 164113Scoleenp using ::lldiv_t; 165113Scoleenp#endif 1660Sduke#if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC 1670Sduke extern "C" void (_Exit)(int); 1682657Skvn#endif 1692657Skvn#if !_GLIBCXX_USE_C99_DYNAMIC 17010159Scoleenp using ::_Exit; 17110159Scoleenp#endif 17210159Scoleenp 1730Sduke inline long long 1741491Skvn abs(long long __x) { return __x >= 0 ? __x : -__x; } 1750Sduke 1762657Skvn#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 1776498Smikael using ::llabs; 1782657Skvn 1792657Skvn inline lldiv_t 1802657Skvn div(long long __n, long long __d) 1810Sduke { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; } 1820Sduke 1830Sduke using ::lldiv; 1840Sduke#endif 1850Sduke 1860Sduke#if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 1871491Skvn extern "C" long long int (atoll)(const char *); 1880Sduke extern "C" long long int 1890Sduke (strtoll)(const char * restrict, char ** restrict, int); 1900Sduke extern "C" unsigned long long int 1910Sduke (strtoull)(const char * restrict, char ** restrict, int); 1920Sduke#endif 1930Sduke#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 1940Sduke using ::atoll; 1950Sduke using ::strtoll; 1960Sduke using ::strtoull; 1970Sduke#endif 1982657Skvn using ::strtof; 1990Sduke using ::strtold; 2000Sduke 2010Sduke_GLIBCXX_END_NAMESPACE 2020Sduke 2030Sduke_GLIBCXX_BEGIN_NAMESPACE(std) 2040Sduke 2050Sduke#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 2060Sduke using ::__gnu_cxx::lldiv_t; 2070Sduke#endif 2080Sduke using ::__gnu_cxx::_Exit; 2090Sduke using ::__gnu_cxx::abs; 2100Sduke#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC 2110Sduke using ::__gnu_cxx::llabs; 2121879Sstefank using ::__gnu_cxx::div; 2131879Sstefank using ::__gnu_cxx::lldiv; 214#endif 215 using ::__gnu_cxx::atoll; 216 using ::__gnu_cxx::strtof; 217 using ::__gnu_cxx::strtoll; 218 using ::__gnu_cxx::strtoull; 219 using ::__gnu_cxx::strtold; 220 221_GLIBCXX_END_NAMESPACE 222 223#endif // _GLIBCXX_USE_C99 224 225#endif // !_GLIBCXX_HOSTED 226 227#endif 228