1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/* ****************************************************************************
* time.h -- Time utilities.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of the 'all/core' module in libcarrot, an experimental
* modular libc project.
*
* This file is governed by the CeCILL-C license under French law and abiding
* by the rules of distribution of free software. You can use, modify and or
* redistribute it under the terms of the CeCILL-C license as circulated by
* CEA, CNRS and INRIA at the following URL: http://www.cecill.info
*
* As a counterpart to the access to the source code and rights to copy, modify
* and redistribute granted by the license, users are provided only with a
* limited warranty and the software's author, the holder of the economic
* rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with
* loading, using, modifying and/or developing and reproducing the software by
* the user in light of its specific status of free software, that may mean
* that it is complicated to manipulate, and that also therefore means that it
* is reserved for developers and experienced professionals having in-depth
* computer knowledge. Users are therefore encouraged to load and test the
* software's suitability as regards their requirements in conditions enabling
* the security of their systems and/or data to be ensured and, more generally,
* to use and operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means you have had knowledge of
* the CeCILL-C license and that you accept its terms.
* ************************************************************************* */
#include <cdefs.h>
#include <stddef.h>
#include_bits <time.h>
#define CLOCKS_PER_SEC __CLOCKS_PER_SEC
/* ************************************************************************* */
/* Time types */
/* ************************************************************************* */
/* This type contains the processor time, i.e. the number of ticks (where
* `CLOCK_PER_SEC` represents the number of ticks that form a second). */
typedef __uint32_t clock_t;
/* This type contains UNIX timestamps, i.e. the number of seconds since the
* Epoch.
*
* FIXME: Y2038 problem, should find a way to use 64-bit integer in
* pre-C99. */
typedef __uint32_t time_t;
/* This structure holds the broken-down time (components of a
* calendar time). */
struct tm {
int tm_sec; /* seconds after the minute [0, 60] */
int tm_min; /* minutes after the hour [0, 59] */
int tm_hour; /* hours since midnight [0, 23] */
int tm_mday; /* day of the month [0, 31] */
int tm_mon; /* months since january [0, 11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since sunday [0, 6] */
int tm_yday; /* days since january 1 [0, 365] */
int tm_isdst; /* daylight saving time flag */
};
/* ************************************************************************* */
/* Main functions */
/* ************************************************************************* */
/* This function to get the processor time.
* Divide the return value by `CLOCKS_PER_SEC` to get the number of seconds. */
extern __wur clock_t clock _OF((void)) __THROW;
/* Compute the difference between two calendar times.
* The returned value is the difference expressed in seconds. */
extern __pure double difftime _OF((time_t __time1, time_t __time0)) __THROW;
/* Correct a broken-down time, and calculate the timestamp out of it. */
extern __wur time_t mktime _OF((struct tm *__timep)) __THROW;
/* Get the current timestamp. */
extern time_t time _OF((time_t *__timep)) __THROW;
/* Get static strings out of broken-down time or timestamps. */
extern __wur char *asctime _OF((const struct tm *__timep)) __THROW;
extern __wur char *ctime _OF((const time_t *__timer)) __THROW;
/* Get the broken-down time out of a timestamp, using the GMT or local time. */
extern __wur struct tm *gmtime _OF((const time_t *__timer)) __THROW;
extern __wur struct tm *localtime _OF((const time_t *__timer)) __THROW;
/* Get a custom-format date string. */
extern size_t strftime _OF((char *__restrict __s,
size_t __maxsize, const char *__restrict __format,
const struct tm *__restrict __timep)) __THROW;
|