]> git.ipfire.org Git - thirdparty/glibc.git/blob - time/sys/time.h
Update.
[thirdparty/glibc.git] / time / sys / time.h
1 /* Copyright (C) 1991,92,93,94,96,97,98,99,2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
18
19 #ifndef _SYS_TIME_H
20 #define _SYS_TIME_H 1
21
22 #include <features.h>
23
24 #include <time.h>
25 #include <sys/select.h>
26
27 #define __need_timeval
28 #include <bits/time.h>
29
30 #ifndef __suseconds_t_defined
31 typedef __suseconds_t suseconds_t;
32 # define __suseconds_t_defined
33 #endif
34
35
36 __BEGIN_DECLS
37
38 /* Macros for converting between `struct timeval' and `struct timespec'. */
39 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
40 (ts)->tv_sec = (tv)->tv_sec; \
41 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
42 }
43 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
44 (tv)->tv_sec = (ts)->tv_sec; \
45 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
46 }
47
48
49 /* Structure crudely representing a timezone.
50 This is obsolete and should never be used. */
51 struct timezone
52 {
53 int tz_minuteswest; /* Minutes west of GMT. */
54 int tz_dsttime; /* Nonzero if DST is ever in effect. */
55 };
56
57 #if defined __USE_GNU || defined __USE_BSD
58 typedef struct timezone *__timezone_ptr_t;
59 #else
60 typedef void *__timezone_ptr_t;
61 #endif
62
63 /* Get the current time of day and timezone information,
64 putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
65 Returns 0 on success, -1 on errors.
66 NOTE: This form of timezone information is obsolete.
67 Use the functions and variables declared in <time.h> instead. */
68 extern int gettimeofday (struct timeval *__tv, __timezone_ptr_t __tz) __THROW;
69
70 /* Set the current time of day and timezone information.
71 This call is restricted to the super-user. */
72 extern int settimeofday (__const struct timeval *__tv,
73 __const struct timezone *__tz) __THROW;
74
75 /* Adjust the current time of day by the amount in DELTA.
76 If OLDDELTA is not NULL, it is filled in with the amount
77 of time adjustment remaining to be done from the last `adjtime' call.
78 This call is restricted to the super-user. */
79 extern int adjtime (__const struct timeval *__delta,
80 struct timeval *__olddelta) __THROW;
81
82
83 /* Values for the first argument to `getitimer' and `setitimer'. */
84 enum __itimer_which
85 {
86 /* Timers run in real time. */
87 ITIMER_REAL = 0,
88 #define ITIMER_REAL ITIMER_REAL
89 /* Timers run only when the process is executing. */
90 ITIMER_VIRTUAL = 1,
91 #define ITIMER_VIRTUAL ITIMER_VIRTUAL
92 /* Timers run when the process is executing and when
93 the system is executing on behalf of the process. */
94 ITIMER_PROF = 2
95 #define ITIMER_PROF ITIMER_PROF
96 };
97
98 /* Type of the second argument to `getitimer' and
99 the second and third arguments `setitimer'. */
100 struct itimerval
101 {
102 /* Value to put into `it_value' when the timer expires. */
103 struct timeval it_interval;
104 /* Time to the next timer expiration. */
105 struct timeval it_value;
106 };
107
108 #ifdef __USE_GNU
109 typedef enum __itimer_which __itimer_which_t;
110 #else
111 typedef int __itimer_which_t;
112 #endif
113
114 /* Set *VALUE to the current setting of timer WHICH.
115 Return 0 on success, -1 on errors. */
116 extern int getitimer (__itimer_which_t __which,
117 struct itimerval *__value) __THROW;
118
119 /* Set the timer WHICH to *NEW. If OLD is not NULL,
120 set *OLD to the old value of timer WHICH.
121 Returns 0 on success, -1 on errors. */
122 extern int setitimer (__itimer_which_t __which,
123 __const struct itimerval *__new,
124 struct itimerval *__old) __THROW;
125
126 /* Change the access time of FILE to TVP[0] and
127 the modification time of FILE to TVP[1]. */
128 extern int utimes (__const char *__file, __const struct timeval __tvp[2])
129 __THROW;
130
131
132 /* Convenience macros for operations on timevals.
133 NOTE: `timercmp' does not work for >= or <=. */
134 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
135 #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
136 #define timercmp(a, b, CMP) \
137 (((a)->tv_sec == (b)->tv_sec) ? \
138 ((a)->tv_usec CMP (b)->tv_usec) : \
139 ((a)->tv_sec CMP (b)->tv_sec))
140 #define timeradd(a, b, result) \
141 do { \
142 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
143 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
144 if ((result)->tv_usec >= 1000000) \
145 { \
146 ++(result)->tv_sec; \
147 (result)->tv_usec -= 1000000; \
148 } \
149 } while (0)
150 #define timersub(a, b, result) \
151 do { \
152 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
153 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
154 if ((result)->tv_usec < 0) { \
155 --(result)->tv_sec; \
156 (result)->tv_usec += 1000000; \
157 } \
158 } while (0)
159
160 __END_DECLS
161
162 #endif /* sys/time.h */