xref: /original-bsd/sys/sys/time.h (revision 0f81f0ee)
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.5 (Berkeley) 05/04/95
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 	long	tv_sec;		/* seconds */
21 	long	tv_usec;	/* and microseconds */
22 };
23 
24 /*
25  * Structure defined by POSIX.4 to be like a timeval.
26  */
27 struct timespec {
28 	time_t	ts_sec;		/* seconds */
29 	long	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 #ifdef KERNEL
85 int	itimerfix __P((struct timeval *tv));
86 int	itimerdecr __P((struct itimerval *itp, int usec));
87 void	microtime __P((struct timeval *tv));
88 #else /* !KERNEL */
89 #include <time.h>
90 
91 #ifndef _POSIX_SOURCE
92 #include <sys/cdefs.h>
93 
94 __BEGIN_DECLS
95 int	adjtime __P((const struct timeval *, struct timeval *));
96 int	getitimer __P((int, struct itimerval *));
97 int	gettimeofday __P((struct timeval *, struct timezone *));
98 int	setitimer __P((int, const struct itimerval *, struct itimerval *));
99 int	settimeofday __P((const struct timeval *, const struct timezone *));
100 int	utimes __P((const char *, const struct timeval *));
101 __END_DECLS
102 #endif /* !POSIX */
103 
104 #endif /* !KERNEL */
105 
106 #endif /* !_SYS_TIME_H_ */
107