Update.
[glibc.git] / time / sys / time.h
blob83be23fb474e4f520468ccaa68fa9c79a8595cea
1 /* Copyright (C) 1991, 92, 93, 94, 96, 97, 98 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 not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #ifndef _SYS_TIME_H
20 #define _SYS_TIME_H 1
22 #include <features.h>
24 #include <time.h>
25 #include <sys/select.h>
27 #define __need_timeval
28 #include <bits/time.h>
31 __BEGIN_DECLS
33 /* Macros for converting between `struct timeval' and `struct timespec'. */
34 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
35 (ts)->tv_sec = (tv)->tv_sec; \
36 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
38 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
39 (tv)->tv_sec = (ts)->tv_sec; \
40 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
44 /* Structure crudely representing a timezone.
45 This is obsolete and should never be used. */
46 struct timezone
48 int tz_minuteswest; /* Minutes west of GMT. */
49 int tz_dsttime; /* Nonzero if DST is ever in effect. */
52 /* Get the current time of day and timezone information,
53 putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
54 Returns 0 on success, -1 on errors.
55 NOTE: This form of timezone information is obsolete.
56 Use the functions and variables declared in <time.h> instead. */
57 extern int gettimeofday __P ((struct timeval *__tv,
58 struct timezone *__tz));
60 /* Set the current time of day and timezone information.
61 This call is restricted to the super-user. */
62 extern int settimeofday __P ((__const struct timeval *__tv,
63 __const struct timezone *__tz));
65 /* Adjust the current time of day by the amount in DELTA.
66 If OLDDELTA is not NULL, it is filled in with the amount
67 of time adjustment remaining to be done from the last `adjtime' call.
68 This call is restricted to the super-user. */
69 extern int adjtime __P ((__const struct timeval *__delta,
70 struct timeval *__olddelta));
73 /* Values for the first argument to `getitimer' and `setitimer'. */
74 enum __itimer_which
76 /* Timers run in real time. */
77 ITIMER_REAL = 0,
78 #define ITIMER_REAL ITIMER_REAL
79 /* Timers run only when the process is executing. */
80 ITIMER_VIRTUAL = 1,
81 #define ITIMER_VIRTUAL ITIMER_VIRTUAL
82 /* Timers run when the process is executing and when
83 the system is executing on behalf of the process. */
84 ITIMER_PROF = 2
85 #define ITIMER_PROF ITIMER_PROF
88 /* Type of the second argument to `getitimer' and
89 the second and third arguments `setitimer'. */
90 struct itimerval
92 /* Value to put into `it_value' when the timer expires. */
93 struct timeval it_interval;
94 /* Time to the next timer expiration. */
95 struct timeval it_value;
98 /* Set *VALUE to the current setting of timer WHICH.
99 Return 0 on success, -1 on errors. */
100 extern int getitimer __P ((enum __itimer_which __which,
101 struct itimerval *__value));
103 /* Set the timer WHICH to *NEW. If OLD is not NULL,
104 set *OLD to the old value of timer WHICH.
105 Returns 0 on success, -1 on errors. */
106 extern int setitimer __P ((enum __itimer_which __which,
107 __const struct itimerval *__new,
108 struct itimerval *__old));
110 /* Change the access time of FILE to TVP[0] and
111 the modification time of FILE to TVP[1]. */
112 extern int utimes __P ((__const char *__file, struct timeval __tvp[2]));
115 /* Convenience macros for operations on timevals.
116 NOTE: `timercmp' does not work for >= or <=. */
117 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
118 #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
119 #define timercmp(a, b, CMP) \
120 (((a)->tv_sec == (b)->tv_sec) ? \
121 ((a)->tv_usec CMP (b)->tv_usec) : \
122 ((a)->tv_sec CMP (b)->tv_sec))
123 #define timeradd(a, b, result) \
124 do { \
125 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
126 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
127 if ((result)->tv_usec >= 1000000) \
129 ++(result)->tv_sec; \
130 (result)->tv_usec -= 1000000; \
132 } while (0)
133 #define timersub(a, b, result) \
134 do { \
135 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
136 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
137 if ((result)->tv_usec < 0) { \
138 --(result)->tv_sec; \
139 (result)->tv_usec += 1000000; \
141 } while (0)
143 __END_DECLS
145 #endif /* sys/time.h */