xref: /netbsd-src/include/time.h (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: time.h,v 1.33 2003/12/21 23:19:02 kleink Exp $	*/
2 
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  *	@(#)time.h	8.3 (Berkeley) 1/21/94
37  */
38 
39 #ifndef _TIME_H_
40 #define	_TIME_H_
41 
42 #include <sys/cdefs.h>
43 #include <sys/featuretest.h>
44 #include <machine/ansi.h>
45 
46 #include <sys/null.h>
47 
48 #ifdef	_BSD_CLOCK_T_
49 typedef	_BSD_CLOCK_T_	clock_t;
50 #undef	_BSD_CLOCK_T_
51 #endif
52 
53 #ifdef	_BSD_TIME_T_
54 typedef	_BSD_TIME_T_	time_t;
55 #undef	_BSD_TIME_T_
56 #endif
57 
58 #ifdef	_BSD_SIZE_T_
59 typedef	_BSD_SIZE_T_	size_t;
60 #undef	_BSD_SIZE_T_
61 #endif
62 
63 #ifdef	_BSD_CLOCKID_T_
64 typedef	_BSD_CLOCKID_T_	clockid_t;
65 #undef	_BSD_CLOCKID_T_
66 #endif
67 
68 #ifdef	_BSD_TIMER_T_
69 typedef	_BSD_TIMER_T_	timer_t;
70 #undef	_BSD_TIMER_T_
71 #endif
72 
73 #define CLOCKS_PER_SEC	100
74 
75 struct tm {
76 	int	tm_sec;		/* seconds after the minute [0-61] */
77 	int	tm_min;		/* minutes after the hour [0-59] */
78 	int	tm_hour;	/* hours since midnight [0-23] */
79 	int	tm_mday;	/* day of the month [1-31] */
80 	int	tm_mon;		/* months since January [0-11] */
81 	int	tm_year;	/* years since 1900 */
82 	int	tm_wday;	/* days since Sunday [0-6] */
83 	int	tm_yday;	/* days since January 1 [0-365] */
84 	int	tm_isdst;	/* Daylight Savings Time flag */
85 	long	tm_gmtoff;	/* offset from UTC in seconds */
86 	__aconst char *tm_zone;	/* timezone abbreviation */
87 };
88 
89 __BEGIN_DECLS
90 char *asctime __P((const struct tm *));
91 clock_t clock __P((void));
92 char *ctime __P((const time_t *));
93 double difftime __P((time_t, time_t));
94 struct tm *gmtime __P((const time_t *));
95 struct tm *localtime __P((const time_t *));
96 time_t mktime __P((struct tm *));
97 size_t strftime __P((char * __restrict, size_t, const char * __restrict,
98     const struct tm * __restrict));
99 time_t time __P((time_t *));
100 
101 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
102     defined(_NETBSD_SOURCE)
103 
104 #ifdef __LIBC12_SOURCE__
105 #define CLK_TCK 100
106 #else
107 
108 /*
109  * CLK_TCK uses libc's internal __sysconf() to retrieve the machine's
110  * HZ. The value of _SC_CLK_TCK is 39 -- we hard code it so we do not
111  * need to include unistd.h
112  */
113 long __sysconf __P((int));
114 #define CLK_TCK		(__sysconf(39))
115 
116 #endif
117 
118 extern __aconst char *tzname[2];
119 void tzset __P((void));
120 
121 /*
122  * X/Open Portability Guide >= Issue 4
123  */
124 #if (_XOPEN_SOURCE - 0) >= 4 || defined(_NETBSD_SOURCE)
125 extern int daylight;
126 #ifndef __LIBC12_SOURCE__
127 extern long int timezone __RENAME(__timezone13);
128 #endif
129 char *strptime __P((const char * __restrict, const char * __restrict,
130     struct tm * __restrict));
131 #endif
132 
133 #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \
134     defined(_NETBSD_SOURCE)
135 #include <sys/time.h>		/* XXX for struct timespec */
136 struct sigevent;
137 struct itimerspec;
138 int clock_getres __P((clockid_t, struct timespec *));
139 int clock_gettime __P((clockid_t, struct timespec *));
140 int clock_settime __P((clockid_t, const struct timespec *));
141 int nanosleep __P((const struct timespec *, struct timespec *));
142 int timer_create __P((clockid_t, struct sigevent * __restrict,
143     timer_t * __restrict));
144 int timer_delete __P((timer_t));
145 int timer_getoverrun __P((timer_t));
146 int timer_gettime __P((timer_t, struct itimerspec *));
147 int timer_settime __P((timer_t, int, const struct itimerspec * __restrict,
148     struct itimerspec * __restrict));
149 #endif /* _POSIX_C_SOURCE >= 199309 || _XOPEN_SOURCE >= 500 || ... */
150 
151 #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
152     defined(_REENTRANT) || defined(_NETBSD_SOURCE)
153 char *asctime_r __P((const struct tm * __restrict, char * __restrict));
154 char *ctime_r __P((const time_t *, char *));
155 struct tm *gmtime_r __P((const time_t * __restrict, struct tm * __restrict));
156 struct tm *localtime_r __P((const time_t * __restrict, struct tm * __restrict));
157 #endif
158 
159 #if defined(_NETBSD_SOURCE)
160 time_t time2posix __P((time_t));
161 time_t posix2time __P((time_t));
162 time_t timegm __P((struct tm *));
163 time_t timeoff __P((struct tm *, long));
164 time_t timelocal __P((struct tm *));
165 #ifdef __LIBC12_SOURCE__
166 char *timezone __P((int, int));
167 #endif
168 void tzsetwall __P((void));
169 struct tm *offtime __P((const time_t *, long));
170 #endif /* _NETBSD_SOURCE */
171 
172 #endif /* !_ANSI_SOURCE */
173 __END_DECLS
174 
175 #endif /* !_TIME_H_ */
176