1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37/*
38 */
39
40#ifndef _TIME_H_
41#define _TIME_H_
42
43#include <sys/cdefs.h>
44#include <sys/_null.h>
45#include <sys/_types.h>
46#include <sys/_clock_id.h>
47
48#if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE
49/*
50 * Frequency of the clock ticks reported by times(). Deprecated - use
51 * sysconf(_SC_CLK_TCK) instead. (Removed in 1003.1-2001.)
52 */
53#define CLK_TCK 128
54#endif
55
56/* Frequency of the clock ticks reported by clock(). */
57#define CLOCKS_PER_SEC 128
58
59#ifndef _CLOCK_T_DECLARED
60typedef __clock_t clock_t;
61#define _CLOCK_T_DECLARED
62#endif
63
64#ifndef _TIME_T_DECLARED
65typedef __time_t time_t;
66#define _TIME_T_DECLARED
67#endif
68
69#ifndef _SIZE_T_DECLARED
70typedef __size_t size_t;
71#define _SIZE_T_DECLARED
72#endif
73
74#if __POSIX_VISIBLE >= 199309
75/*
76 * New in POSIX 1003.1b-1993.
77 */
78#ifndef _CLOCKID_T_DECLARED
79typedef __clockid_t clockid_t;
80#define _CLOCKID_T_DECLARED
81#endif
82
83#ifndef _TIMER_T_DECLARED
84typedef __timer_t timer_t;
85#define _TIMER_T_DECLARED
86#endif
87
88#include <sys/timespec.h>
89#endif /* __POSIX_VISIBLE >= 199309 */
90
91#if __POSIX_VISIBLE >= 200112
92#ifndef _PID_T_DECLARED
93typedef __pid_t pid_t;
94#define _PID_T_DECLARED
95#endif
96#endif
97
98struct tm {
99 int tm_sec; /* seconds after the minute [0-60] */
100 int tm_min; /* minutes after the hour [0-59] */
101 int tm_hour; /* hours since midnight [0-23] */
102 int tm_mday; /* day of the month [1-31] */
103 int tm_mon; /* months since January [0-11] */
104 int tm_year; /* years since 1900 */
105 int tm_wday; /* days since Sunday [0-6] */
106 int tm_yday; /* days since January 1 [0-365] */
107 int tm_isdst; /* Daylight Savings Time flag */
108 long tm_gmtoff; /* offset from UTC in seconds */
109 char *tm_zone; /* timezone abbreviation */
110};
111
112#if __POSIX_VISIBLE
113extern char *tzname[];
114#endif
115
116__BEGIN_DECLS
117char *asctime(const struct tm *);
118clock_t clock(void);
119char *ctime(const time_t *);
120#ifndef _STANDALONE
121double difftime(time_t, time_t);
122#endif
123/* XXX missing: getdate() */
124struct tm *gmtime(const time_t *);
125struct tm *localtime(const time_t *);
126time_t mktime(struct tm *);
127size_t strftime(char * __restrict, size_t, const char * __restrict,
128 const struct tm * __restrict);
129time_t time(time_t *);
130#if __POSIX_VISIBLE >= 200112
131struct sigevent;
132int timer_create(clockid_t, struct sigevent *__restrict, timer_t *__restrict);
133int timer_delete(timer_t);
134int timer_gettime(timer_t, struct itimerspec *);
135int timer_getoverrun(timer_t);
136int timer_settime(timer_t, int, const struct itimerspec *__restrict,
137 struct itimerspec *__restrict);
138#endif
139#if __POSIX_VISIBLE
140void tzset(void);
141#endif
142
143#if __POSIX_VISIBLE >= 199309
144int clock_getres(clockid_t, struct timespec *);
145int clock_gettime(clockid_t, struct timespec *);
146int clock_settime(clockid_t, const struct timespec *);
147int nanosleep(const struct timespec *, struct timespec *);
148#endif /* __POSIX_VISIBLE >= 199309 */
149
150#if __POSIX_VISIBLE >= 200112
151int clock_getcpuclockid(pid_t, clockid_t *);
152int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
153#endif
154
155#if __POSIX_VISIBLE >= 199506
156char *asctime_r(const struct tm *, char *);
157char *ctime_r(const time_t *, char *);
158#endif
159#if __POSIX_VISIBLE >= 199506 || __ISO_C_VISIBLE >= 2023
160struct tm *gmtime_r(const time_t *, struct tm *);
161struct tm *localtime_r(const time_t *, struct tm *);
162#endif
163
164#if __XSI_VISIBLE
165char *strptime(const char * __restrict, const char * __restrict,
166 struct tm * __restrict);
167extern long timezone;
168extern int daylight;
169#endif
170
171#if __BSD_VISIBLE
172time_t timelocal(struct tm * const);
173time_t timegm(struct tm * const);
174int timer_oshandle_np(timer_t timerid);
175time_t time2posix(time_t t);
176time_t posix2time(time_t t);
177struct tm *offtime(const time_t *, long);
178struct tm *offtime_r(const time_t *__restrict, long, struct tm *__restrict);
179#endif /* __BSD_VISIBLE */
180
181#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
182#include <xlocale/_time.h>
183#endif
184
185#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 2011 || \
186 (defined(__cplusplus) && __cplusplus >= 201703)
187#include <sys/_timespec.h>
188/* ISO/IEC 9899:2011 7.27.2.5 The timespec_get function */
189#define TIME_UTC 1 /* time elapsed since epoch */
190int timespec_get(struct timespec *ts, int base);
191#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 2023
192/* ISO/IEC 9899:2024 7.29.1 Components of time */
193#define TIME_MONOTONIC 2 /* monotonic time */
194/* ISO/IEC 9899:2024 7.29.2.7 The timespec_getres function */
195int timespec_getres(struct timespec *, int);
196#endif
197#endif
198
199__END_DECLS
200
201#endif /* !_TIME_H_ */