]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/c_std/bits/std_ctime.h
configopts.html: Edit.
[thirdparty/gcc.git] / libstdc++-v3 / include / c_std / bits / std_ctime.h
1 // -*- C++ -*- header wrapper.
2
3 // Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 //
31 // ISO C++ 14882: 20.5 Date and time
32 //
33
34 #ifndef _CPP_CTIME
35 #define _CPP_CTIME 1
36
37 # ifdef _IN_C_LEGACY_ /* sub-included by a C header */
38 // get out of the "legacy"
39 } // close extern "C"
40 } // close namespace _C_legacy::
41 # undef _IN_C_LEGACY_
42 # define _TIME_NEED_C_LEGACY_
43 # endif
44
45 # include <bits/std_cstddef.h>
46
47 namespace _C_legacy {
48 extern "C" {
49 # define _IN_C_LEGACY_
50 # pragma GCC system_header
51
52 // XXX
53 // glibc 2.1.x time.h is on crack
54 # undef __need_time_t
55 # undef __need_clock_t
56 # undef __need_timespec
57
58 # include_next <time.h>
59 }
60
61 typedef clock_t _CPP_clock_t_capture;
62 typedef time_t _CPP_time_t_capture;
63 typedef tm _CPP_tm_capture;
64
65 } // namespace _C_legacy
66
67 # undef clock_t
68 # undef time_t
69 # undef tm
70 # undef clock
71 # undef difftime
72 # undef mktime
73 # undef time
74 # undef asctime
75 # undef ctime
76 # undef gmtime
77 # undef localtime
78 # undef strftime
79
80 namespace std {
81
82 // Adopt C names into std::
83 typedef _C_legacy::_CPP_clock_t_capture clock_t;
84 typedef _C_legacy::_CPP_time_t_capture time_t;
85 struct tm : _C_legacy::_CPP_tm_capture { };
86
87 using _C_legacy::clock;
88 using _C_legacy::difftime;
89 using _C_legacy::mktime;
90 using _C_legacy::time;
91 using _C_legacy::ctime;
92
93 inline char*
94 asctime(const tm* __t)
95 { return _C_legacy::asctime(static_cast<_C_legacy::_CPP_tm_capture const*>(__t)); }
96
97 inline tm*
98 gmtime(time_t const* __tp)
99 { return reinterpret_cast<tm*>(_C_legacy::gmtime(__tp)); }
100
101 inline tm*
102 localtime(const time_t* __tp)
103 { return reinterpret_cast<tm*>(_C_legacy::localtime(__tp)); }
104
105 inline size_t
106 strftime(char* __buf, size_t __maxsz, char const* __fmt, tm const* __tp)
107 { return _C_legacy::strftime(__buf, __maxsz, __fmt,
108 static_cast<_C_legacy::_CPP_tm_capture const*>(__tp)); }
109
110 } // namespace std
111
112 # undef _IN_C_LEGACY_
113
114 // Expose global C names, including non-standard ones, but shadow
115 // some names and types with the std:: C++ version.
116 using std::clock_t;
117 using std::time_t;
118 using std::tm;
119
120 using std::clock;
121 using std::difftime;
122 using std::mktime;
123 using std::time;
124 using std::asctime;
125 using std::ctime;
126 using std::gmtime;
127 using std::localtime;
128 using std::strftime;
129
130 # ifdef _TIME_NEED_C_LEGACY_
131 // dive back into the "swamp"
132 namespace _C_legacy {
133 extern "C" {
134 # define _IN_C_LEGACY_
135 # undef _TIME_NEED_C_LEGACY_
136 # endif /* _TIME_NEED_C_LEGACY_ */
137
138 #endif /*_CPP_CTIME*/
139
140