1 /* Copyright (C) 1991-2014 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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
23 #include <bits/types.h>
26 #define __need_timeval
27 #include <bits/time.h>
29 #include <sys/select.h>
31 #ifndef __suseconds_t_defined
32 typedef __suseconds_t suseconds_t
;
33 # define __suseconds_t_defined
40 /* Macros for converting between `struct timeval' and `struct timespec'. */
41 # define TIMEVAL_TO_TIMESPEC(tv, ts) { \
42 (ts)->tv_sec = (tv)->tv_sec; \
43 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
45 # define TIMESPEC_TO_TIMEVAL(tv, ts) { \
46 (tv)->tv_sec = (ts)->tv_sec; \
47 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
53 /* Structure crudely representing a timezone.
54 This is obsolete and should never be used. */
57 int tz_minuteswest
; /* Minutes west of GMT. */
58 int tz_dsttime
; /* Nonzero if DST is ever in effect. */
61 typedef struct timezone
*__restrict __timezone_ptr_t
;
63 typedef void *__restrict __timezone_ptr_t
;
66 /* Get the current time of day and timezone information,
67 putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
68 Returns 0 on success, -1 on errors.
69 NOTE: This form of timezone information is obsolete.
70 Use the functions and variables declared in <time.h> instead. */
71 extern int gettimeofday (struct timeval
*__restrict __tv
,
72 __timezone_ptr_t __tz
) __THROW
__nonnull ((1));
75 /* Set the current time of day and timezone information.
76 This call is restricted to the super-user. */
77 extern int settimeofday (const struct timeval
*__tv
,
78 const struct timezone
*__tz
)
81 /* Adjust the current time of day by the amount in DELTA.
82 If OLDDELTA is not NULL, it is filled in with the amount
83 of time adjustment remaining to be done from the last `adjtime' call.
84 This call is restricted to the super-user. */
85 extern int adjtime (const struct timeval
*__delta
,
86 struct timeval
*__olddelta
) __THROW
;
90 /* Values for the first argument to `getitimer' and `setitimer'. */
93 /* Timers run in real time. */
95 #define ITIMER_REAL ITIMER_REAL
96 /* Timers run only when the process is executing. */
98 #define ITIMER_VIRTUAL ITIMER_VIRTUAL
99 /* Timers run when the process is executing and when
100 the system is executing on behalf of the process. */
102 #define ITIMER_PROF ITIMER_PROF
105 /* Type of the second argument to `getitimer' and
106 the second and third arguments `setitimer'. */
109 /* Value to put into `it_value' when the timer expires. */
110 struct timeval it_interval
;
111 /* Time to the next timer expiration. */
112 struct timeval it_value
;
115 #if defined __USE_GNU && !defined __cplusplus
116 /* Use the nicer parameter type only in GNU mode and not for C++ since the
117 strict C++ rules prevent the automatic promotion. */
118 typedef enum __itimer_which __itimer_which_t
;
120 typedef int __itimer_which_t
;
123 /* Set *VALUE to the current setting of timer WHICH.
124 Return 0 on success, -1 on errors. */
125 extern int getitimer (__itimer_which_t __which
,
126 struct itimerval
*__value
) __THROW
;
128 /* Set the timer WHICH to *NEW. If OLD is not NULL,
129 set *OLD to the old value of timer WHICH.
130 Returns 0 on success, -1 on errors. */
131 extern int setitimer (__itimer_which_t __which
,
132 const struct itimerval
*__restrict __new
,
133 struct itimerval
*__restrict __old
) __THROW
;
135 /* Change the access time of FILE to TVP[0] and the modification time of
136 FILE to TVP[1]. If TVP is a null pointer, use the current time instead.
137 Returns 0 on success, -1 on errors. */
138 extern int utimes (const char *__file
, const struct timeval __tvp
[2])
139 __THROW
__nonnull ((1));
142 /* Same as `utimes', but does not follow symbolic links. */
143 extern int lutimes (const char *__file
, const struct timeval __tvp
[2])
144 __THROW
__nonnull ((1));
146 /* Same as `utimes', but takes an open file descriptor instead of a name. */
147 extern int futimes (int __fd
, const struct timeval __tvp
[2]) __THROW
;
151 /* Change the access time of FILE relative to FD to TVP[0] and the
152 modification time of FILE to TVP[1]. If TVP is a null pointer, use
153 the current time instead. Returns 0 on success, -1 on errors. */
154 extern int futimesat (int __fd
, const char *__file
,
155 const struct timeval __tvp
[2]) __THROW
;
160 /* Convenience macros for operations on timevals.
161 NOTE: `timercmp' does not work for >= or <=. */
162 # define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
163 # define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
164 # define timercmp(a, b, CMP) \
165 (((a)->tv_sec == (b)->tv_sec) ? \
166 ((a)->tv_usec CMP (b)->tv_usec) : \
167 ((a)->tv_sec CMP (b)->tv_sec))
168 # define timeradd(a, b, result) \
170 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
171 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
172 if ((result)->tv_usec >= 1000000) \
174 ++(result)->tv_sec; \
175 (result)->tv_usec -= 1000000; \
178 # define timersub(a, b, result) \
180 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
181 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
182 if ((result)->tv_usec < 0) { \
183 --(result)->tv_sec; \
184 (result)->tv_usec += 1000000; \
191 #endif /* sys/time.h */