xref: /openbsd/include/time.h (revision 3d0c28f3)
1*3d0c28f3Smillert /*	$OpenBSD: time.h,v 1.32 2022/10/25 16:30:30 millert Exp $	*/
2df930be7Sderaadt /*	$NetBSD: time.h,v 1.9 1994/10/26 00:56:35 cgd Exp $	*/
3df930be7Sderaadt 
4df930be7Sderaadt /*
5df930be7Sderaadt  * Copyright (c) 1989 The Regents of the University of California.
6df930be7Sderaadt  * All rights reserved.
7df930be7Sderaadt  *
8df930be7Sderaadt  * (c) UNIX System Laboratories, Inc.
9df930be7Sderaadt  * All or some portions of this file are derived from material licensed
10df930be7Sderaadt  * to the University of California by American Telephone and Telegraph
11df930be7Sderaadt  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
12df930be7Sderaadt  * the permission of UNIX System Laboratories, Inc.
13df930be7Sderaadt  *
14df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
15df930be7Sderaadt  * modification, are permitted provided that the following conditions
16df930be7Sderaadt  * are met:
17df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
18df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
19df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
20df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
21df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
22e33d3bd3Smillert  * 3. Neither the name of the University nor the names of its contributors
23df930be7Sderaadt  *    may be used to endorse or promote products derived from this software
24df930be7Sderaadt  *    without specific prior written permission.
25df930be7Sderaadt  *
26df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27df930be7Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28df930be7Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29df930be7Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30df930be7Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31df930be7Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32df930be7Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33df930be7Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34df930be7Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35df930be7Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36df930be7Sderaadt  * SUCH DAMAGE.
37df930be7Sderaadt  *
38df930be7Sderaadt  *	@(#)time.h	5.12 (Berkeley) 3/9/91
39df930be7Sderaadt  */
40df930be7Sderaadt 
41df930be7Sderaadt #ifndef _TIME_H_
42df930be7Sderaadt #define	_TIME_H_
43df930be7Sderaadt 
4452a0e603Smillert #include <sys/cdefs.h>
456ecde746Smillert #include <sys/_null.h>
461ec1251eSguenther #include <sys/_types.h>
47*3d0c28f3Smillert #include <sys/_time.h>
48df930be7Sderaadt 
49c916d948Smillert #ifndef	_CLOCK_T_DEFINED_
50c916d948Smillert #define	_CLOCK_T_DEFINED_
51c916d948Smillert typedef	__clock_t	clock_t;
52df930be7Sderaadt #endif
53df930be7Sderaadt 
54c916d948Smillert #ifndef	_TIME_T_DEFINED_
55c916d948Smillert #define	_TIME_T_DEFINED_
56c916d948Smillert typedef	__time_t	time_t;
57df930be7Sderaadt #endif
58df930be7Sderaadt 
59c916d948Smillert #ifndef	_SIZE_T_DEFINED_
60c916d948Smillert #define	_SIZE_T_DEFINED_
61c916d948Smillert typedef	__size_t	size_t;
62df930be7Sderaadt #endif
63df930be7Sderaadt 
6452a0e603Smillert #if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE
6552a0e603Smillert /*
6652a0e603Smillert  * Frequency of the clock ticks reported by times().  Deprecated - use
6752a0e603Smillert  * sysconf(_SC_CLK_TCK) instead.  (Removed in 1003.1-2001.)
6852a0e603Smillert  */
6952a0e603Smillert #define CLK_TCK		100
7052a0e603Smillert #endif
7152a0e603Smillert 
726151004eSguenther #if __POSIX_VISIBLE >= 199309
73c7280c70Skettenis #ifndef	_CLOCKID_T_DEFINED_
74c7280c70Skettenis #define	_CLOCKID_T_DEFINED_
75c7280c70Skettenis typedef	__clockid_t	clockid_t;
76c7280c70Skettenis #endif
77c7280c70Skettenis 
78c7280c70Skettenis #ifndef	_TIMER_T_DEFINED_
79c7280c70Skettenis #define	_TIMER_T_DEFINED_
80c7280c70Skettenis typedef	__timer_t	timer_t;
81c7280c70Skettenis #endif
82c7280c70Skettenis #endif
83c7280c70Skettenis 
847b36c281Sguenther #if __POSIX_VISIBLE >= 200112
857b36c281Sguenther #ifndef	_PID_T_DEFINED_
867b36c281Sguenther #define	_PID_T_DEFINED_
877b36c281Sguenther typedef	__pid_t		pid_t;
887b36c281Sguenther #endif
897b36c281Sguenther #endif
907b36c281Sguenther 
913a628b46Sschwarze #if __POSIX_VISIBLE >= 200809
923a628b46Sschwarze #ifndef	_LOCALE_T_DEFINED_
933a628b46Sschwarze #define	_LOCALE_T_DEFINED_
943a628b46Sschwarze typedef void	*locale_t;
953a628b46Sschwarze #endif
963a628b46Sschwarze #endif
973a628b46Sschwarze 
98df930be7Sderaadt struct tm {
99df930be7Sderaadt 	int	tm_sec;		/* seconds after the minute [0-60] */
100df930be7Sderaadt 	int	tm_min;		/* minutes after the hour [0-59] */
101df930be7Sderaadt 	int	tm_hour;	/* hours since midnight [0-23] */
102df930be7Sderaadt 	int	tm_mday;	/* day of the month [1-31] */
103df930be7Sderaadt 	int	tm_mon;		/* months since January [0-11] */
104df930be7Sderaadt 	int	tm_year;	/* years since 1900 */
105df930be7Sderaadt 	int	tm_wday;	/* days since Sunday [0-6] */
106df930be7Sderaadt 	int	tm_yday;	/* days since January 1 [0-365] */
10786eac110Spjanzen 	int	tm_isdst;	/* Daylight Saving Time flag */
108d39cbccfSaaron 	long	tm_gmtoff;	/* offset from UTC in seconds */
109df930be7Sderaadt 	char	*tm_zone;	/* timezone abbreviation */
110df930be7Sderaadt };
111df930be7Sderaadt 
112df930be7Sderaadt __BEGIN_DECLS
113c72b5b24Smillert char *asctime(const struct tm *);
114c72b5b24Smillert clock_t clock(void);
115c72b5b24Smillert char *ctime(const time_t *);
116c72b5b24Smillert double difftime(time_t, time_t);
117c72b5b24Smillert struct tm *gmtime(const time_t *);
118c72b5b24Smillert struct tm *localtime(const time_t *);
119c72b5b24Smillert time_t mktime(struct tm *);
1202c79e7ccSguenther size_t strftime(char *__restrict, size_t, const char *__restrict,
1212c79e7ccSguenther 		const struct tm *__restrict)
12289b95c1cSavsm 		__attribute__ ((__bounded__(__string__,1,2)));
123c72b5b24Smillert time_t time(time_t *);
124329a58afSkettenis 
125c9da469aSmillert #if __XPG_VISIBLE >= 300
126c9da469aSmillert extern int daylight;
127c9da469aSmillert extern long timezone;
128c9da469aSmillert #endif
129329a58afSkettenis #if __XPG_VISIBLE >= 400
1302c79e7ccSguenther char *strptime(const char *__restrict, const char *__restrict,
1312c79e7ccSguenther 		struct tm *__restrict);
132329a58afSkettenis #endif
133329a58afSkettenis 
134329a58afSkettenis #if __POSIX_VISIBLE >= 199506
1352c79e7ccSguenther char *asctime_r(const struct tm *__restrict, char *__restrict)
13689b95c1cSavsm 		__attribute__ ((__bounded__(__minbytes__,2,26)));
13789b95c1cSavsm char *ctime_r(const time_t *, char *)
13889b95c1cSavsm 		__attribute__ ((__bounded__(__minbytes__,2,26)));
1392c79e7ccSguenther struct tm *gmtime_r(const time_t *__restrict, struct tm *__restrict);
1402c79e7ccSguenther struct tm *localtime_r(const time_t *__restrict, struct tm *__restrict);
141329a58afSkettenis #endif
142df930be7Sderaadt 
14352a0e603Smillert #if __POSIX_VISIBLE
144df930be7Sderaadt extern char *tzname[2];
145c72b5b24Smillert void tzset(void);
14652a0e603Smillert #endif
147df930be7Sderaadt 
148329a58afSkettenis #if __POSIX_VISIBLE >= 199309
149c7280c70Skettenis int clock_getres(clockid_t, struct timespec *);
150c7280c70Skettenis int clock_gettime(clockid_t, struct timespec *);
151c7280c70Skettenis int clock_settime(clockid_t, const struct timespec *);
152329a58afSkettenis int nanosleep(const struct timespec *, struct timespec *);
153c7280c70Skettenis #endif
154c7280c70Skettenis 
1557b36c281Sguenther #if __POSIX_VISIBLE >= 200112
1567b36c281Sguenther int clock_getcpuclockid(pid_t, clockid_t *);
1577b36c281Sguenther #endif
1587b36c281Sguenther 
1593a628b46Sschwarze #if __POSIX_VISIBLE >= 200809
1603a628b46Sschwarze size_t strftime_l(char *__restrict, size_t, const char *__restrict,
1613a628b46Sschwarze 		const struct tm *__restrict, locale_t)
1623a628b46Sschwarze 		__attribute__ ((__bounded__(__string__,1,2)));
1633a628b46Sschwarze #endif
1643a628b46Sschwarze 
1656151004eSguenther #if __ISO_C_VISIBLE >= 2011
1666151004eSguenther #define TIME_UTC	1	/* time elapsed since epoch */
1676151004eSguenther int timespec_get(struct timespec *_ts, int _base);
1686151004eSguenther #endif
1696151004eSguenther 
17052a0e603Smillert #if __BSD_VISIBLE
171c72b5b24Smillert void tzsetwall(void);
172c72b5b24Smillert time_t timelocal(struct tm *);
173c72b5b24Smillert time_t timegm(struct tm *);
174c72b5b24Smillert time_t timeoff(struct tm *, const long);
17552a0e603Smillert #endif
176df930be7Sderaadt __END_DECLS
177df930be7Sderaadt 
178df930be7Sderaadt #endif /* !_TIME_H_ */
179