# cstdlib

Go to the documentation of this file.

    00001 // -*- C++ -*- forwarding header.
    00002
    00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
    00004 // Free Software Foundation, Inc.
    00005 //
    00006 // This file is part of the GNU ISO C++ Library.  This library is free
    00007 // software; you can redistribute it and/or modify it under the
    00008 // terms of the GNU General Public License as published by the
    00009 // Free Software Foundation; either version 2, or (at your option)
    00010 // any later version.
    00011
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00015 // GNU General Public License for more details.
    00016
    00017 // You should have received a copy of the GNU General Public License along
    00018 // with this library; see the file COPYING.  If not, write to the Free
    00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    00020 // USA.
    00021
    00022 // As a special exception, you may use this file as part of a free software
    00023 // library without restriction.  Specifically, if other files instantiate
    00024 // templates or use macros or inline functions from this file, or you compile
    00025 // this file and link it with other files to produce an executable, this
    00026 // file does not by itself cause the resulting executable to be covered by
    00027 // the GNU General Public License.  This exception does not however
    00028 // invalidate any other reasons why the executable file might be covered by
    00029 // the GNU General Public License.
    00030
    00031 /** @file include/cstdlib
    00032  *  This is a Standard C++ Library file.  You should @c #include this file
    00033  *  in your programs, rather than any of the "*.h" implementation files.
    00034  *
    00035  *  This is the C++ version of the Standard C Library header @c stdlib.h,
    00036  *  and its contents are (mostly) the same as that header, but are all
    00037  *  contained in the namespace @c std (except for names which are defined
    00038  *  as macros in C).
    00039  */
    00040
    00041 //
    00042 // ISO C++ 14882: 20.4.6  C library
    00043 //
    00044
    00045 #ifndef _GLIBCXX_CSTDLIB
    00046 #define _GLIBCXX_CSTDLIB 1
    00047
    00048 #pragma GCC system_header
    00049
    00050 #include <bits/c++config.h>
    00051 #include <cstddef>
    00052
    00053 #if !_GLIBCXX_HOSTED
    00054 // The C standard does not require a freestanding implementation to
    00055 // provide <stdlib.h>.  However, the C++ standard does still require
    00056 // <cstdlib> -- but only the functionality mentioned in
    00057 // [lib.support.start.term].
    00058
    00059 #define EXIT_SUCCESS 0
    00060 #define EXIT_FAILURE 1
    00061
    00062 _GLIBCXX_BEGIN_NAMESPACE(std)
    00063
    00064   extern "C" void abort(void);
    00065   extern "C" int atexit(void (*)());
    00066   extern "C" void exit(int);
    00067
    00068 _GLIBCXX_END_NAMESPACE
    00069
    00070 #else
    00071
    00072 #include <stdlib.h>
    00073
    00074 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
    00075 #undef abort
    00076 #undef abs
    00077 #undef atexit
    00078 #undef atof
    00079 #undef atoi
    00080 #undef atol
    00081 #undef bsearch
    00082 #undef calloc
    00083 #undef div
    00084 #undef exit
    00085 #undef free
    00086 #undef getenv
    00087 #undef labs
    00088 #undef ldiv
    00089 #undef malloc
    00090 #undef mblen
    00091 #undef mbstowcs
    00092 #undef mbtowc
    00093 #undef qsort
    00094 #undef rand
    00095 #undef realloc
    00096 #undef srand
    00097 #undef strtod
    00098 #undef strtol
    00099 #undef strtoul
    00100 #undef system
    00101 #undef wcstombs
    00102 #undef wctomb
    00103
    00104 _GLIBCXX_BEGIN_NAMESPACE(std)
    00105
    00106   using ::div_t;
    00107   using ::ldiv_t;
    00108
    00109   using ::abort;
    00110   using ::abs;
    00111   using ::atexit;
    00112   using ::atof;
    00113   using ::atoi;
    00114   using ::atol;
    00115   using ::bsearch;
    00116   using ::calloc;
    00117   using ::div;
    00118   using ::exit;
    00119   using ::free;
    00120   using ::getenv;
    00121   using ::labs;
    00122   using ::ldiv;
    00123   using ::malloc;
    00124 #ifdef _GLIBCXX_HAVE_MBSTATE_T
    00125   using ::mblen;
    00126   using ::mbstowcs;
    00127   using ::mbtowc;
    00128 #endif // _GLIBCXX_HAVE_MBSTATE_T
    00129   using ::qsort;
    00130   using ::rand;
    00131   using ::realloc;
    00132   using ::srand;
    00133   using ::strtod;
    00134   using ::strtol;
    00135   using ::strtoul;
    00136   using ::system;
    00137 #ifdef _GLIBCXX_USE_WCHAR_T
    00138   using ::wcstombs;
    00139   using ::wctomb;
    00140 #endif // _GLIBCXX_USE_WCHAR_T
    00141
    00142   inline long
    00143   abs(long __i) { return labs(__i); }
    00144
    00145   inline ldiv_t
    00146   div(long __i, long __j) { return ldiv(__i, __j); }
    00147
    00148 _GLIBCXX_END_NAMESPACE
    00149
    00150 #if _GLIBCXX_USE_C99
    00151
    00152 #undef _Exit
    00153 #undef llabs
    00154 #undef lldiv
    00155 #undef atoll
    00156 #undef strtoll
    00157 #undef strtoull
    00158 #undef strtof
    00159 #undef strtold
    00160
    00161 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
    00162
    00163 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    00164   using ::lldiv_t;
    00165 #endif
    00166 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
    00167   extern "C" void (_Exit)(int);
    00168 #endif
    00169 #if !_GLIBCXX_USE_C99_DYNAMIC
    00170   using ::_Exit;
    00171 #endif
    00172
    00173   inline long long
    00174   abs(long long __x) { return __x >= 0 ? __x : -__x; }
    00175
    00176 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    00177   using ::llabs;
    00178
    00179   inline lldiv_t
    00180   div(long long __n, long long __d)
    00181   { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
    00182
    00183   using ::lldiv;
    00184 #endif
    00185
    00186 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    00187   extern "C" long long int (atoll)(const char *);
    00188   extern "C" long long int
    00189     (strtoll)(const char * restrict, char ** restrict, int);
    00190   extern "C" unsigned long long int
    00191     (strtoull)(const char * restrict, char ** restrict, int);
    00192 #endif
    00193 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    00194   using ::atoll;
    00195   using ::strtoll;
    00196   using ::strtoull;
    00197 #endif
    00198   using ::strtof;
    00199   using ::strtold;
    00200
    00201 _GLIBCXX_END_NAMESPACE
    00202
    00203 _GLIBCXX_BEGIN_NAMESPACE(std)
    00204
    00205 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    00206   using ::__gnu_cxx::lldiv_t;
    00207 #endif
    00208   using ::__gnu_cxx::_Exit;
    00209   using ::__gnu_cxx::abs;
    00210 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    00211   using ::__gnu_cxx::llabs;
    00212   using ::__gnu_cxx::div;
    00213   using ::__gnu_cxx::lldiv;
    00214 #endif
    00215   using ::__gnu_cxx::atoll;
    00216   using ::__gnu_cxx::strtof;
    00217   using ::__gnu_cxx::strtoll;
    00218   using ::__gnu_cxx::strtoull;
    00219   using ::__gnu_cxx::strtold;
    00220
    00221 _GLIBCXX_END_NAMESPACE
    00222
    00223 #endif // _GLIBCXX_USE_C99
    00224
    00225 #endif // !_GLIBCXX_HOSTED
    00226
    00227 #endif