Update.
[glibc.git] / time / sys / time.h
blobf5b03f3e9e9f9216ee9cb482832ad13894131837
1 /* Copyright (C) 1991, 92, 93, 94, 96, 97 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));
59 extern int gettimeofday __P ((struct timeval *__tv,
60 struct timezone *__tz));
62 /* Set the current time of day and timezone information.
63 This call is restricted to the super-user. */
64 extern int __settimeofday __P ((__const struct timeval *__tv,
65 __const struct timezone *__tz));
66 extern int settimeofday __P ((__const struct timeval *__tv,
67 __const struct timezone *__tz));
69 /* Adjust the current time of day by the amount in DELTA.
70 If OLDDELTA is not NULL, it is filled in with the amount
71 of time adjustment remaining to be done from the last `adjtime' call.
72 This call is restricted to the super-user. */
73 extern int __adjtime __P ((__const struct timeval *__delta,
74 struct timeval *__olddelta));
75 extern int adjtime __P ((__const struct timeval *__delta,
76 struct timeval *__olddelta));
79 /* Values for the first argument to `getitimer' and `setitimer'. */
80 enum __itimer_which
82 /* Timers run in real time. */
83 ITIMER_REAL = 0,
84 #define ITIMER_REAL ITIMER_REAL
85 /* Timers run only when the process is executing. */
86 ITIMER_VIRTUAL = 1,
87 #define ITIMER_VIRTUAL ITIMER_VIRTUAL
88 /* Timers run when the process is executing and when
89 the system is executing on behalf of the process. */
90 ITIMER_PROF = 2
91 #define ITIMER_PROF ITIMER_PROF
94 /* Type of the second argument to `getitimer' and
95 the second and third arguments `setitimer'. */
96 struct itimerval
98 /* Value to put into `it_value' when the timer expires. */
99 struct timeval it_interval;
100 /* Time to the next timer expiration. */
101 struct timeval it_value;
104 /* Set *VALUE to the current setting of timer WHICH.
105 Return 0 on success, -1 on errors. */
106 extern int __getitimer __P ((enum __itimer_which __which,
107 struct itimerval *__value));
108 extern int getitimer __P ((enum __itimer_which __which,
109 struct itimerval *__value));
111 /* Set the timer WHICH to *NEW. If OLD is not NULL,
112 set *OLD to the old value of timer WHICH.
113 Returns 0 on success, -1 on errors. */
114 extern int __setitimer __P ((enum __itimer_which __which,
115 __const struct itimerval *__new,
116 struct itimerval *__old));
117 extern int setitimer __P ((enum __itimer_which __which,
118 __const struct itimerval *__new,
119 struct itimerval *__old));
121 /* Change the access time of FILE to TVP[0] and
122 the modification time of FILE to TVP[1]. */
123 extern int __utimes __P ((__const char *__file, struct timeval __tvp[2]));
124 extern int utimes __P ((__const char *__file, struct timeval __tvp[2]));
127 /* Convenience macros for operations on timevals.
128 NOTE: `timercmp' does not work for >= or <=. */
129 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
130 #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
131 #define timercmp(a, b, CMP) \
132 (((a)->tv_sec == (b)->tv_sec) ? \
133 ((a)->tv_usec CMP (b)->tv_usec) : \
134 ((a)->tv_sec CMP (b)->tv_sec))
135 #define timeradd(a, b, result) \
136 do { \
137 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
138 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
139 if ((result)->tv_usec >= 1000000) \
141 ++(result)->tv_sec; \
142 (result)->tv_usec -= 1000000; \
144 } while (0)
145 #define timersub(a, b, result) \
146 do { \
147 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
148 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
149 if ((result)->tv_usec < 0) { \
150 --(result)->tv_sec; \
151 (result)->tv_usec += 1000000; \
153 } while (0)
155 __END_DECLS
157 #endif /* sys/time.h */