Minor cleanups
[lightOS.git] / trunk / lib / libc / include / time.h
blob8917e3bafa07eae190435089e1b3f2bb54f9f7d5
1 /*
2 lightOS libc
3 Copyright (C) 2006-2008 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef LIGHTOS_LIBC_TIME_H
20 #define LIGHTOS_LIBC_TIME_H
24 * Standard includes
26 #include <stddef.h>
29 * Internal includes
31 #include <libc/types.h> // NOTE: _LIBC_time_t, _LIBC_clock_t
34 /*! \addtogroup libc libc */
35 /*@{*/
36 /*! \addtogroup libc_time ISO/IEC 9899:1999 - 7.23 - time.h
37 * ISO/IEC 9899:1999 7.23 Date and time */
38 /*@{*/
42 * Defines
43 * ISO/IEC 9899:1999 7.19.1
46 /** Defines to 1000000 according to [XSI] */
47 #define CLOCKS_PER_SEC 1000000
50 * Types
51 * ISO/IEC 9899:1999 7.23.1
54 /** Arithmetic types capable of representing times */
55 typedef _LIBC_time_t time_t;
57 /** Arithmetic types capable of representing times */
58 typedef _LIBC_clock_t clock_t;
60 /** holds the components of a calendar time, called the broken-down time. */
61 struct tm
63 /** seconds after the minute — [0, 60] */
64 int tm_sec;
65 /** minutes after the hour — [0, 59] */
66 int tm_min;
67 /** hours since midnight — [0, 23] */
68 int tm_hour;
69 /** hours since midnight — [0, day of the month — [1, 31] */
70 int tm_mday;
71 /** months since January — [0, 11] */
72 int tm_mon;
73 /** years since 1900 */
74 int tm_year;
75 /** days since Sunday — [0, 6] */
76 int tm_wday;
77 /** days since January 1 — [0, 365] */
78 int tm_yday;
79 /** Daylight Saving Time flag */
80 int tm_isdst;
85 * Functions
88 #ifdef __cplusplus
89 extern "C"
92 #define restrict
93 #endif
97 * ISO/IEC 9899:1999 7.23.2 Time manipulation functions
100 /** ISO/IEC 9899:1999 7.23.2.1
102 * The clock function determines the processor time used.
104 * [CX] http://www.opengroup.org/onlinepubs/000095399/functions/clock.html
105 *\todo implement
106 *\return The clock function returns the implementation’s best approximation to the processor
107 * time used by the program since the beginning of an implementation-defined era related
108 * only to the program invocation. To determine the time in seconds, the value returned by
109 * the clock function should be divided by the value of the macro CLOCKS_PER_SEC. If
110 * the processor time used is not available or its value cannot be represented, the function
111 * returns the value (clock_t)(-1). */
112 clock_t clock(void);
114 /** ISO/IEC 9899:1999 7.23.2.2
116 * The difftime function computes the difference between two calendar times: time1 -
117 * time0.
119 * [CX] http://www.opengroup.org/onlinepubs/000095399/functions/difftime.html
120 *\param[in] time1 first time
121 *\param[in] time0 second time
122 *\return The difftime function returns the difference expressed in seconds as a double. */
123 double difftime(time_t time1, time_t time0);
125 /** ISO/IEC 9899:1999 7.23.2.3
127 * The mktime function converts the broken-down time, expressed as local time, in the
128 * structure pointed to by timeptr into a calendar time value with the same encoding as
129 * that of the values returned by the time function. The original values of the tm_wday
130 * and tm_yday components of the structure are ignored, and the original values of the
131 * other components are not restricted to the ranges indicated above. On successful
132 * completion, the values of the tm_wday and tm_yday components of the structure are
133 * set appropriately, and the other components are set to represent the specified calendar
134 * time, but with their values forced to the ranges indicated above; the final value of
135 * tm_mday is not set until tm_mon and tm_year are determined.
137 * [CX] http://www.opengroup.org/onlinepubs/000095399/functions/mktime.html and
138 * http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap04.html#tag_04_14
139 *\param[in] timeptr
140 *\todo implement fully
141 *\return The mktime function returns the specified calendar time encoded as a value of type
142 * time_t. If the calendar time cannot be represented, the function returns the value
143 * (time_t)(-1) and [CX] and may set errno to indicate the error (EOVERFLOW). */
144 time_t mktime(struct tm *timeptr);
146 /** ISO/IEC 9899:1999 7.23.2.4
148 * The time function determines the current calendar time. The encoding of the value is
149 * unspecified.
151 * [CX] http://www.opengroup.org/onlinepubs/000095399/functions/time.html
152 *\param[in,out] tloc
153 *\return The time function returns the implementation’s best approximation to the current
154 * calendar time. The value (time_t)(-1) is returned if the calendar time is not
155 * available. If timer is not a null pointer, the return value is also assigned to the object it
156 * points to. */
157 time_t time(time_t *tloc);
161 * ISO/IEC 9899:1999 7.23.3 Time conversion functions
164 /** ISO/IEC 9899:1999 7.23.3.1
166 * The asctime function converts the broken-down time in the structure pointed to by
167 * timeptr into a string in the form
169 * Sun Sep 16 01:03:52 1973\n\0
171 * [CX] http://www.opengroup.org/onlinepubs/000095399/functions/asctime.html
172 *\param[in] timeptr the broken-down time
173 *\return The asctime function returns a pointer to the string.
174 * [CX] If the function is unsuccessful, it shall return NULL. */
175 char *asctime(const struct tm *timeptr);
177 /** ISO/IEC 9899:1999 7.23.3.2
179 * The ctime function converts the calendar time pointed to by timer to local time in the
180 * form of a string. It is equivalent to
181 * asctime(localtime(timer))
183 * [CX] http://www.opengroup.org/onlinepubs/000095399/functions/ctime.html
184 *\param[in] timer the time since epoch
185 *\return The ctime function returns the pointer returned by the asctime function with that
186 * broken-down time as argument. */
187 char *ctime(const time_t *timer);
189 /** ISO/IEC 9899:1999 7.23.3.3
191 * The gmtime function converts the calendar time pointed to by timer into a broken-
192 * down time, expressed as UTC.
194 * [CX] http://www.opengroup.org/onlinepubs/000095399/functions/gmtime.html
195 *\param[in] timer the time since epoch
196 *\todo incomplete implementation
197 *\return The gmtime function returns a pointer to the broken-down time, or a null pointer if the
198 * specified time cannot be converted to UTC and [CX] set errno to indicate the error (EOVERFLOW). */
199 struct tm *gmtime(const time_t *timer);
201 /** ISO/IEC 9899:1999 7.23.3.4
203 * The localtime function converts the calendar time pointed to by timer into a
204 * broken-down time, expressed as local time.
205 * [CX] Local timezone information is used as though localtime() calls tzset().
207 * [CX] http://www.opengroup.org/onlinepubs/000095399/functions/localtime.html
208 *\param[in] timer time since epoch
209 *\todo incomplete implementation
210 *\return The localtime function returns a pointer to the broken-down time, or a null pointer if
211 * the specified time cannot be converted to local time and [CX] set errno to indicate the error
212 * (EOVERFLOW). */
213 struct tm *localtime(const time_t *timer);
215 /** ISO/IEC 9899:1999 7.23.3.5
217 * The strftime function places characters into the array pointed to by s as controlled by
218 * the string pointed to by format. The format shall be a multibyte character sequence,
219 * beginning and ending in its initial shift state. The format string consists of zero or
220 * more conversion specifiers and ordinary multibyte characters. A conversion specifier
221 * consists of a % character, possibly followed by an E or O modifier character (described
222 * in the link below), followed by a character that determines the behavior of the conversion specifier.
223 * All ordinary multibyte characters (including the terminating null character) are copied
224 * unchanged into the array. If copying takes place between objects that overlap, the
225 * behavior is undefined. No more than maxsize characters are placed into the array.
227 * [CX] http://www.opengroup.org/onlinepubs/000095399/functions/strftime.html
228 *\param[in] s
229 *\param[in] maxsize
230 *\param[in] format
231 *\param[in] timeptr
232 *\todo incomplete implementation
233 *\return If the total number of resulting characters including the terminating null character is not
234 * more than maxsize, the strftime function returns the number of characters placed
235 * into the array pointed to by s not including the terminating null character. Otherwise,
236 * zero is returned and the contents of the array are indeterminate. */
237 size_t strftime(char * restrict s,
238 size_t maxsize,
239 const char * restrict format,
240 const struct tm * restrict timeptr);
242 #ifdef __cplusplus
245 #undef restrict
246 #endif
250 * libunix includes
253 #ifdef _LIGHTOS_LIBUNIX
254 #include <_LIBUNIX_time.h>
255 #endif
258 /*@}*/
259 /*@}*/
261 #endif