std_cstdlib.h revision 132720
1// -*- C++ -*- forwarding header.
2
3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
4// Free Software Foundation, Inc.
5//
6// This file is part of the GNU ISO C++ Library.  This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING.  If not, write to the Free
19// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20// USA.
21
22// As a special exception, you may use this file as part of a free software
23// library without restriction.  Specifically, if other files instantiate
24// templates or use macros or inline functions from this file, or you compile
25// this file and link it with other files to produce an executable, this
26// file does not by itself cause the resulting executable to be covered by
27// the GNU General Public License.  This exception does not however
28// invalidate any other reasons why the executable file might be covered by
29// the GNU General Public License.
30
31//
32// ISO C++ 14882: 20.4.6  C library
33//
34
35/** @file cstdlib
36 *  This is a Standard C++ Library file.  You should @c #include this file
37 *  in your programs, rather than any of the "*.h" implementation files.
38 *
39 *  This is the C++ version of the Standard C Library header @c stdlib.h,
40 *  and its contents are (mostly) the same as that header, but are all
41 *  contained in the namespace @c std.
42 */
43
44#ifndef _GLIBCXX_CSTDLIB
45#define _GLIBCXX_CSTDLIB 1
46
47#pragma GCC system_header
48
49#include <bits/c++config.h>
50#include <cstddef>
51
52#include <stdlib.h>
53
54// Get rid of those macros defined in <stdlib.h> in lieu of real functions.
55#undef abort
56#undef abs
57#undef atexit
58#undef atof
59#undef atoi
60#undef atol
61#undef bsearch
62#undef calloc
63#undef div
64#undef exit
65#undef free
66#undef getenv
67#undef labs
68#undef ldiv
69#undef malloc
70#undef mblen
71#undef mbstowcs
72#undef mbtowc
73#undef qsort
74#undef rand
75#undef realloc
76#undef srand
77#undef strtod
78#undef strtol
79#undef strtoul
80#undef system
81#undef wcstombs
82#undef wctomb
83
84namespace std
85{
86  using ::div_t;
87  using ::ldiv_t;
88
89  using ::abort;
90  using ::abs;
91  using ::atexit;
92  using ::atof;
93  using ::atoi;
94  using ::atol;
95  using ::bsearch;
96  using ::calloc;
97  using ::div;
98  using ::exit;
99  using ::free;
100  using ::getenv;
101  using ::labs;
102  using ::ldiv;
103  using ::malloc;
104#ifdef _GLIBCXX_HAVE_MBSTATE_T
105  using ::mblen;
106  using ::mbstowcs;
107  using ::mbtowc;
108#endif // _GLIBCXX_HAVE_MBSTATE_T
109  using ::qsort;
110  using ::rand;
111  using ::realloc;
112  using ::srand;
113  using ::strtod;
114  using ::strtol;
115  using ::strtoul;
116  using ::system;
117#ifdef _GLIBCXX_USE_WCHAR_T
118  using ::wcstombs;
119  using ::wctomb;
120#endif // _GLIBCXX_USE_WCHAR_T
121
122  inline long
123  abs(long __i) { return labs(__i); }
124
125  inline ldiv_t
126  div(long __i, long __j) { return ldiv(__i, __j); }
127}
128
129#if _GLIBCXX_USE_C99
130
131#undef _Exit
132#undef llabs
133#undef lldiv
134#undef atoll
135#undef strtoll
136#undef strtoull
137#undef strtof
138#undef strtold
139
140namespace __gnu_cxx
141{
142#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
143  using ::lldiv_t;
144#endif
145#if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
146  extern "C" void (_Exit)(int);
147#endif
148#if !_GLIBCXX_USE_C99_DYNAMIC
149  using ::_Exit;
150#endif
151
152  inline long long
153  abs(long long __x) { return __x >= 0 ? __x : -__x; }
154
155  inline long long
156  llabs(long long __x) { return __x >= 0 ? __x : -__x; }
157
158#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
159  inline lldiv_t
160  div(long long __n, long long __d)
161  { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
162
163  inline lldiv_t
164  lldiv(long long __n, long long __d)
165  { lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }
166#endif
167
168#if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
169  extern "C" long long int (atoll)(const char *);
170  extern "C" long long int
171    (strtoll)(const char * restrict, char ** restrict, int);
172  extern "C" unsigned long long int
173    (strtoull)(const char * restrict, char ** restrict, int);
174#endif
175#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
176  using ::atoll;
177  using ::strtoll;
178  using ::strtoull;
179#endif
180  using ::strtof;
181  using ::strtold;
182}
183
184namespace std
185{
186#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
187  using __gnu_cxx::lldiv_t;
188#endif
189  using __gnu_cxx::_Exit;
190  using __gnu_cxx::abs;
191  using __gnu_cxx::llabs;
192#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
193  using __gnu_cxx::div;
194  using __gnu_cxx::lldiv;
195#endif
196  using __gnu_cxx::atoll;
197  using __gnu_cxx::strtof;
198  using __gnu_cxx::strtoll;
199  using __gnu_cxx::strtoull;
200  using __gnu_cxx::strtold;
201}
202#endif
203
204#endif
205