1 /* Copyright (C) 1991-2017 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>
24 #include <bits/types/time_t.h>
25 #include <bits/types/struct_timeval.h>
27 #ifndef __suseconds_t_defined
28 typedef __suseconds_t suseconds_t
;
29 # define __suseconds_t_defined
32 #include <sys/select.h>
37 /* Macros for converting between `struct timeval' and `struct timespec'. */
38 # define TIMEVAL_TO_TIMESPEC(tv, ts) { \
39 (ts)->tv_sec = (tv)->tv_sec; \
40 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
42 # define TIMESPEC_TO_TIMEVAL(tv, ts) { \
43 (tv)->tv_sec = (ts)->tv_sec; \
44 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
50 /* Structure crudely representing a timezone.
51 This is obsolete and should never be used. */
54 int tz_minuteswest
; /* Minutes west of GMT. */
55 int tz_dsttime
; /* Nonzero if DST is ever in effect. */
58 typedef struct timezone
*__restrict __timezone_ptr_t
;
60 typedef void *__restrict __timezone_ptr_t
;
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
*__restrict __tv
,
69 __timezone_ptr_t __tz
) __THROW
__nonnull ((1));
72 /* Set the current time of day and timezone information.
73 This call is restricted to the super-user. */
74 extern int settimeofday (const struct timeval
*__tv
,
75 const struct timezone
*__tz
)
78 /* Adjust the current time of day by the amount in DELTA.
79 If OLDDELTA is not NULL, it is filled in with the amount
80 of time adjustment remaining to be done from the last `adjtime' call.
81 This call is restricted to the super-user. */
82 extern int adjtime (const struct timeval
*__delta
,
83 struct timeval
*__olddelta
) __THROW
;
87 /* Values for the first argument to `getitimer' and `setitimer'. */
90 /* Timers run in real time. */
92 #define ITIMER_REAL ITIMER_REAL
93 /* Timers run only when the process is executing. */
95 #define ITIMER_VIRTUAL ITIMER_VIRTUAL
96 /* Timers run when the process is executing and when
97 the system is executing on behalf of the process. */
99 #define ITIMER_PROF ITIMER_PROF
102 /* Type of the second argument to `getitimer' and
103 the second and third arguments `setitimer'. */
106 /* Value to put into `it_value' when the timer expires. */
107 struct timeval it_interval
;
108 /* Time to the next timer expiration. */
109 struct timeval it_value
;
112 #if defined __USE_GNU && !defined __cplusplus
113 /* Use the nicer parameter type only in GNU mode and not for C++ since the
114 strict C++ rules prevent the automatic promotion. */
115 typedef enum __itimer_which __itimer_which_t
;
117 typedef int __itimer_which_t
;
120 /* Set *VALUE to the current setting of timer WHICH.
121 Return 0 on success, -1 on errors. */
122 extern int getitimer (__itimer_which_t __which
,
123 struct itimerval
*__value
) __THROW
;
125 /* Set the timer WHICH to *NEW. If OLD is not NULL,
126 set *OLD to the old value of timer WHICH.
127 Returns 0 on success, -1 on errors. */
128 extern int setitimer (__itimer_which_t __which
,
129 const struct itimerval
*__restrict __new
,
130 struct itimerval
*__restrict __old
) __THROW
;
132 /* Change the access time of FILE to TVP[0] and the modification time of
133 FILE to TVP[1]. If TVP is a null pointer, use the current time instead.
134 Returns 0 on success, -1 on errors. */
135 extern int utimes (const char *__file
, const struct timeval __tvp
[2])
136 __THROW
__nonnull ((1));
139 /* Same as `utimes', but does not follow symbolic links. */
140 extern int lutimes (const char *__file
, const struct timeval __tvp
[2])
141 __THROW
__nonnull ((1));
143 /* Same as `utimes', but takes an open file descriptor instead of a name. */
144 extern int futimes (int __fd
, const struct timeval __tvp
[2]) __THROW
;
148 /* Change the access time of FILE relative to FD to TVP[0] and the
149 modification time of FILE to TVP[1]. If TVP is a null pointer, use
150 the current time instead. Returns 0 on success, -1 on errors. */
151 extern int futimesat (int __fd
, const char *__file
,
152 const struct timeval __tvp
[2]) __THROW
;
157 /* Convenience macros for operations on timevals.
158 NOTE: `timercmp' does not work for >= or <=. */
159 # define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
160 # define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
161 # define timercmp(a, b, CMP) \
162 (((a)->tv_sec == (b)->tv_sec) ? \
163 ((a)->tv_usec CMP (b)->tv_usec) : \
164 ((a)->tv_sec CMP (b)->tv_sec))
165 # define timeradd(a, b, result) \
167 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
168 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
169 if ((result)->tv_usec >= 1000000) \
171 ++(result)->tv_sec; \
172 (result)->tv_usec -= 1000000; \
175 # define timersub(a, b, result) \
177 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
178 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
179 if ((result)->tv_usec < 0) { \
180 --(result)->tv_sec; \
181 (result)->tv_usec += 1000000; \
188 #endif /* sys/time.h */