xref: /original-bsd/sys/sys/time.h (revision deff14a8)
1 /*
2  * Copyright (c) 1982, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)time.h	8.2 (Berkeley) 07/10/94
8  */
9 
10 #ifndef _SYS_TIME_H_
11 #define _SYS_TIME_H_
12 
13 #include <sys/types.h>
14 
15 /*
16  * Structure returned by gettimeofday(2) system call,
17  * and used in other calls.
18  */
19 struct timeval {
20 	int32_t	tv_sec;		/* seconds */
21 	int32_t	tv_usec;	/* and microseconds */
22 };
23 
24 /*
25  * Structure defined by POSIX.4 to be like a timeval.
26  */
27 struct timespec {
28 	int32_t	ts_sec;		/* seconds */
29 	int32_t	ts_nsec;	/* and nanoseconds */
30 };
31 
32 #define	TIMEVAL_TO_TIMESPEC(tv, ts) {					\
33 	(ts)->ts_sec = (tv)->tv_sec;					\
34 	(ts)->ts_nsec = (tv)->tv_usec * 1000;				\
35 }
36 #define	TIMESPEC_TO_TIMEVAL(tv, ts) {					\
37 	(tv)->tv_sec = (ts)->ts_sec;					\
38 	(tv)->tv_usec = (ts)->ts_nsec / 1000;				\
39 }
40 
41 struct timezone {
42 	int	tz_minuteswest;	/* minutes west of Greenwich */
43 	int	tz_dsttime;	/* type of dst correction */
44 };
45 #define	DST_NONE	0	/* not on dst */
46 #define	DST_USA		1	/* USA style dst */
47 #define	DST_AUST	2	/* Australian style dst */
48 #define	DST_WET		3	/* Western European dst */
49 #define	DST_MET		4	/* Middle European dst */
50 #define	DST_EET		5	/* Eastern European dst */
51 #define	DST_CAN		6	/* Canada */
52 
53 /* Operations on timevals. */
54 #define	timerclear(tvp)		(tvp)->tv_sec = (tvp)->tv_usec = 0
55 #define	timerisset(tvp)		((tvp)->tv_sec || (tvp)->tv_usec)
56 #define	timercmp(tvp, uvp, cmp)						\
57 	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
58 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
59 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
60 
61 /*
62  * Names of the interval timers, and structure
63  * defining a timer setting.
64  */
65 #define	ITIMER_REAL	0
66 #define	ITIMER_VIRTUAL	1
67 #define	ITIMER_PROF	2
68 
69 struct	itimerval {
70 	struct	timeval it_interval;	/* timer interval */
71 	struct	timeval it_value;	/* current value */
72 };
73 
74 /*
75  * Getkerninfo clock information structure
76  */
77 struct clockinfo {
78 	int	hz;		/* clock frequency */
79 	int	tick;		/* micro-seconds per hz tick */
80 	int	stathz;		/* statistics clock frequency */
81 	int	profhz;		/* profiling clock frequency */
82 };
83 
84 #ifndef KERNEL
85 #include <time.h>
86 
87 #ifndef _POSIX_SOURCE
88 #include <sys/cdefs.h>
89 
90 __BEGIN_DECLS
91 int	adjtime __P((const struct timeval *, struct timeval *));
92 int	getitimer __P((int, struct itimerval *));
93 int	gettimeofday __P((struct timeval *, struct timezone *));
94 int	setitimer __P((int, const struct itimerval *, struct itimerval *));
95 int	settimeofday __P((const struct timeval *, const struct timezone *));
96 int	utimes __P((const char *, const struct timeval *));
97 __END_DECLS
98 #endif /* !POSIX */
99 
100 #endif /* !KERNEL */
101 
102 #endif /* !_SYS_TIME_H_ */
103