1 /* Copyright (C) 1991, 92, 93, 94, 96 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
26 #define __need_timeval
32 /* Macros for converting between `struct timeval' and `struct timespec'. */
33 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
34 (ts)->tv_sec = (tv)->tv_sec; \
35 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
37 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
38 (tv)->tv_sec = (ts)->tv_sec; \
39 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
43 /* Structure crudely representing a timezone.
44 This is obsolete and should never be used. */
47 int tz_minuteswest
; /* Minutes west of GMT. */
48 int tz_dsttime
; /* Nonzero if DST is ever in effect. */
51 /* Get the current time of day and timezone information,
52 putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
53 Returns 0 on success, -1 on errors.
54 NOTE: This form of timezone information is obsolete.
55 Use the functions and variables declared in <time.h> instead. */
56 extern int __gettimeofday
__P ((struct timeval
*__tv
,
57 struct timezone
*__tz
));
58 extern int gettimeofday
__P ((struct timeval
*__tv
,
59 struct timezone
*__tz
));
61 /* Set the current time of day and timezone information.
62 This call is restricted to the super-user. */
63 extern int __settimeofday
__P ((__const
struct timeval
*__tv
,
64 __const
struct timezone
*__tz
));
65 extern int settimeofday
__P ((__const
struct timeval
*__tv
,
66 __const
struct timezone
*__tz
));
68 /* Adjust the current time of day by the amount in DELTA.
69 If OLDDELTA is not NULL, it is filled in with the amount
70 of time adjustment remaining to be done from the last `adjtime' call.
71 This call is restricted to the super-user. */
72 extern int __adjtime
__P ((__const
struct timeval
*__delta
,
73 struct timeval
*__olddelta
));
74 extern int adjtime
__P ((__const
struct timeval
*__delta
,
75 struct timeval
*__olddelta
));
78 /* Values for the first argument to `getitimer' and `setitimer'. */
81 /* Timers run in real time. */
83 /* Timers run only when the process is executing. */
85 /* Timers run when the process is executing and when
86 the system is executing on behalf of the process. */
90 /* Type of the second argument to `getitimer' and
91 the second and third arguments `setitimer'. */
94 /* Value to put into `it_value' when the timer expires. */
95 struct timeval it_interval
;
96 /* Time to the next timer expiration. */
97 struct timeval it_value
;
100 /* Set *VALUE to the current setting of timer WHICH.
101 Return 0 on success, -1 on errors. */
102 extern int __getitimer
__P ((enum __itimer_which __which
,
103 struct itimerval
*__value
));
104 extern int getitimer
__P ((enum __itimer_which __which
,
105 struct itimerval
*__value
));
107 /* Set the timer WHICH to *NEW. If OLD is not NULL,
108 set *OLD to the old value of timer WHICH.
109 Returns 0 on success, -1 on errors. */
110 extern int __setitimer
__P ((enum __itimer_which __which
,
111 struct itimerval
*__new
,
112 struct itimerval
*__old
));
113 extern int setitimer
__P ((enum __itimer_which __which
,
114 struct itimerval
*__new
,
115 struct itimerval
*__old
));
117 /* Change the access time of FILE to TVP[0] and
118 the modification time of FILE to TVP[1]. */
119 extern int __utimes
__P ((__const
char *__file
, struct timeval __tvp
[2]));
120 extern int utimes
__P ((__const
char *__file
, struct timeval __tvp
[2]));
123 /* Convenience macros for operations on timevals.
124 NOTE: `timercmp' does not work for >= or <=. */
125 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
126 #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
127 #define timercmp(a, b, CMP) \
128 (((a)->tv_sec == (b)->tv_sec) ? \
129 ((a)->tv_usec CMP (b)->tv_usec) : \
130 ((a)->tv_sec CMP (b)->tv_sec))
131 #define timeradd(a, b, result) \
133 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
134 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
135 if ((result)->tv_usec >= 1000000) \
137 ++(result)->tv_sec; \
138 (result)->tv_usec -= 1000000; \
141 #define timersub(a, b, result) \
143 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
144 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
145 if ((result)->tv_usec < 0) { \
146 --(result)->tv_sec; \
147 (result)->tv_usec += 1000000; \
155 /* Set an alarm to go off (generating a SIGALRM signal) in VALUE
156 microseconds. If INTERVAL is nonzero, when the alarm goes off, the
157 timer is reset to go off every INTERVAL microseconds thereafter.
158 Returns the number of microseconds remaining before the alarm. */
159 extern unsigned int ualarm
__P ((unsigned int __value
,
160 unsigned int __interval
));
163 #endif /* sys/time.h */