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