Home | History | Annotate | Download | only in include
      1 // -*- C++ -*- forwarding header.
      2 
      3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
      4 // 2006, 2007, 2008, 2009
      5 // Free Software Foundation, Inc.
      6 //
      7 // This file is part of the GNU ISO C++ Library.  This library is free
      8 // software; you can redistribute it and/or modify it under the
      9 // terms of the GNU General Public License as published by the
     10 // Free Software Foundation; either version 3, or (at your option)
     11 // any later version.
     12 
     13 // This library is distributed in the hope that it will be useful,
     14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 // GNU General Public License for more details.
     17 
     18 // Under Section 7 of GPL version 3, you are granted additional
     19 // permissions described in the GCC Runtime Library Exception, version
     20 // 3.1, as published by the Free Software Foundation.
     21 
     22 // You should have received a copy of the GNU General Public License and
     23 // a copy of the GCC Runtime Library Exception along with this program;
     24 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     25 // <http://www.gnu.org/licenses/>.
     26 
     27 /** @file include/cstdlib
     28  *  This is a Standard C++ Library file.  You should @c #include this file
     29  *  in your programs, rather than any of the "*.h" implementation files.
     30  *
     31  *  This is the C++ version of the Standard C Library header @c stdlib.h,
     32  *  and its contents are (mostly) the same as that header, but are all
     33  *  contained in the namespace @c std (except for names which are defined
     34  *  as macros in C).
     35  */
     36 
     37 //
     38 // ISO C++ 14882: 20.4.6  C library
     39 //
     40 
     41 #pragma GCC system_header
     42 
     43 #include <bits/c++config.h>
     44 #include <cstddef>
     45 
     46 #ifndef _GLIBCXX_CSTDLIB
     47 #define _GLIBCXX_CSTDLIB 1
     48 
     49 #if !_GLIBCXX_HOSTED
     50 // The C standard does not require a freestanding implementation to
     51 // provide <stdlib.h>.  However, the C++ standard does still require
     52 // <cstdlib> -- but only the functionality mentioned in
     53 // [lib.support.start.term].
     54 
     55 #define EXIT_SUCCESS 0
     56 #define EXIT_FAILURE 1
     57 
     58 _GLIBCXX_BEGIN_NAMESPACE(std)
     59 
     60   extern "C" void abort(void);
     61   extern "C" int atexit(void (*)());
     62   extern "C" void exit(int);
     63 
     64 _GLIBCXX_END_NAMESPACE
     65 
     66 #else
     67 
     68 #include <stdlib.h>
     69 
     70 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
     71 #undef abort
     72 #undef abs
     73 #undef atexit
     74 #undef atof
     75 #undef atoi
     76 #undef atol
     77 #undef bsearch
     78 #undef calloc
     79 #undef div
     80 #undef exit
     81 #undef free
     82 #undef getenv
     83 #undef labs
     84 #undef ldiv
     85 #undef malloc
     86 #undef mblen
     87 #undef mbstowcs
     88 #undef mbtowc
     89 #undef qsort
     90 #undef rand
     91 #undef realloc
     92 #undef srand
     93 #undef strtod
     94 #undef strtol
     95 #undef strtoul
     96 #undef system
     97 #undef wcstombs
     98 #undef wctomb
     99 
    100 _GLIBCXX_BEGIN_NAMESPACE(std)
    101 
    102   using ::div_t;
    103   using ::ldiv_t;
    104 
    105   using ::abort;
    106   using ::abs;
    107   using ::atexit;
    108   using ::atof;
    109   using ::atoi;
    110   using ::atol;
    111   using ::bsearch;
    112   using ::calloc;
    113   using ::div;
    114   using ::exit;
    115   using ::free;
    116   using ::getenv;
    117   using ::labs;
    118   using ::ldiv;
    119   using ::malloc;
    120 #ifdef _GLIBCXX_HAVE_MBSTATE_T
    121   using ::mblen;
    122   using ::mbstowcs;
    123   using ::mbtowc;
    124 #endif // _GLIBCXX_HAVE_MBSTATE_T
    125   using ::qsort;
    126   using ::rand;
    127   using ::realloc;
    128   using ::srand;
    129   using ::strtod;
    130   using ::strtol;
    131   using ::strtoul;
    132   using ::system;
    133 #ifdef _GLIBCXX_USE_WCHAR_T
    134   using ::wcstombs;
    135   using ::wctomb;
    136 #endif // _GLIBCXX_USE_WCHAR_T
    137 
    138   inline long
    139   abs(long __i) { return labs(__i); }
    140 
    141   inline ldiv_t
    142   div(long __i, long __j) { return ldiv(__i, __j); }
    143 
    144 _GLIBCXX_END_NAMESPACE
    145 
    146 #if _GLIBCXX_USE_C99
    147 
    148 #undef _Exit
    149 #undef llabs
    150 #undef lldiv
    151 #undef atoll
    152 #undef strtoll
    153 #undef strtoull
    154 #undef strtof
    155 #undef strtold
    156 
    157 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
    158 
    159 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    160   using ::lldiv_t;
    161 #endif
    162 #if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
    163   extern "C" void (_Exit)(int);
    164 #endif
    165 #if !_GLIBCXX_USE_C99_DYNAMIC
    166   using ::_Exit;
    167 #endif
    168 
    169   inline long long
    170   abs(long long __x) { return __x >= 0 ? __x : -__x; }
    171 
    172 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    173   using ::llabs;
    174 
    175   inline lldiv_t
    176   div(long long __n, long long __d)
    177   { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
    178 
    179   using ::lldiv;
    180 #endif
    181 
    182 #if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    183   extern "C" long long int (atoll)(const char *);
    184   extern "C" long long int
    185     (strtoll)(const char * restrict, char ** restrict, int);
    186   extern "C" unsigned long long int
    187     (strtoull)(const char * restrict, char ** restrict, int);
    188 #endif
    189 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    190   using ::atoll;
    191   using ::strtoll;
    192   using ::strtoull;
    193 #endif
    194   using ::strtof;
    195   using ::strtold;
    196 
    197 _GLIBCXX_END_NAMESPACE
    198 
    199 _GLIBCXX_BEGIN_NAMESPACE(std)
    200 
    201 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    202   using ::__gnu_cxx::lldiv_t;
    203 #endif
    204   using ::__gnu_cxx::_Exit;
    205   using ::__gnu_cxx::abs;
    206 #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
    207   using ::__gnu_cxx::llabs;
    208   using ::__gnu_cxx::div;
    209   using ::__gnu_cxx::lldiv;
    210 #endif
    211   using ::__gnu_cxx::atoll;
    212   using ::__gnu_cxx::strtof;
    213   using ::__gnu_cxx::strtoll;
    214   using ::__gnu_cxx::strtoull;
    215   using ::__gnu_cxx::strtold;
    216 
    217 _GLIBCXX_END_NAMESPACE
    218 
    219 #endif // _GLIBCXX_USE_C99
    220 
    221 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    222 #  if defined(_GLIBCXX_INCLUDE_AS_TR1)
    223 #    error C++0x header cannot be included from TR1 header
    224 #  endif
    225 #  if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
    226 #    include <tr1_impl/cstdlib>
    227 #  else
    228 #    define _GLIBCXX_INCLUDE_AS_CXX0X
    229 #    define _GLIBCXX_BEGIN_NAMESPACE_TR1
    230 #    define _GLIBCXX_END_NAMESPACE_TR1
    231 #    define _GLIBCXX_TR1
    232 #    include <tr1_impl/cstdlib>
    233 #    undef _GLIBCXX_TR1
    234 #    undef _GLIBCXX_END_NAMESPACE_TR1
    235 #    undef _GLIBCXX_BEGIN_NAMESPACE_TR1
    236 #    undef _GLIBCXX_INCLUDE_AS_CXX0X
    237 #  endif
    238 #endif
    239 
    240 #endif // !_GLIBCXX_HOSTED
    241 
    242 #endif
    243