lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Copyright (C) 1991-1994,1996-2003,2005,2006,2009 |
| 2 | Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, write to the Free |
| 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 18 | 02111-1307 USA. */ |
| 19 | |
| 20 | #ifndef _SYS_TIME_H |
| 21 | #define _SYS_TIME_H 1 |
| 22 | |
| 23 | #include <features.h> |
| 24 | |
| 25 | #include <bits/types.h> |
| 26 | #define __need_time_t |
| 27 | #include <time.h> |
| 28 | #define __need_timeval |
| 29 | #include <bits/time.h> |
| 30 | |
| 31 | #include <sys/select.h> |
| 32 | |
| 33 | #ifndef __suseconds_t_defined |
| 34 | typedef __suseconds_t suseconds_t; |
| 35 | # define __suseconds_t_defined |
| 36 | #endif |
| 37 | |
| 38 | |
| 39 | __BEGIN_DECLS |
| 40 | |
| 41 | #ifdef __USE_GNU |
| 42 | /* Macros for converting between `struct timeval' and `struct timespec'. */ |
| 43 | # define TIMEVAL_TO_TIMESPEC(tv, ts) { \ |
| 44 | (ts)->tv_sec = (tv)->tv_sec; \ |
| 45 | (ts)->tv_nsec = (tv)->tv_usec * 1000; \ |
| 46 | } |
| 47 | # define TIMESPEC_TO_TIMEVAL(tv, ts) { \ |
| 48 | (tv)->tv_sec = (ts)->tv_sec; \ |
| 49 | (tv)->tv_usec = (ts)->tv_nsec / 1000; \ |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | |
| 54 | #ifdef __USE_BSD |
| 55 | /* Structure crudely representing a timezone. |
| 56 | This is obsolete and should never be used. */ |
| 57 | struct timezone |
| 58 | { |
| 59 | int tz_minuteswest; /* Minutes west of GMT. */ |
| 60 | int tz_dsttime; /* Nonzero if DST is ever in effect. */ |
| 61 | }; |
| 62 | |
| 63 | typedef struct timezone *__restrict __timezone_ptr_t; |
| 64 | #else |
| 65 | typedef void *__restrict __timezone_ptr_t; |
| 66 | #endif |
| 67 | |
| 68 | /* Get the current time of day and timezone information, |
| 69 | putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled. |
| 70 | Returns 0 on success, -1 on errors. |
| 71 | NOTE: This form of timezone information is obsolete. |
| 72 | Use the functions and variables declared in <time.h> instead. */ |
| 73 | extern int gettimeofday (struct timeval *__restrict __tv, |
| 74 | __timezone_ptr_t __tz) __THROW __nonnull ((1)); |
| 75 | libc_hidden_proto(gettimeofday) |
| 76 | |
| 77 | #ifdef __USE_BSD |
| 78 | /* Set the current time of day and timezone information. |
| 79 | This call is restricted to the super-user. */ |
| 80 | extern int settimeofday (__const struct timeval *__tv, |
| 81 | __const struct timezone *__tz) |
| 82 | __THROW __nonnull ((1)); |
| 83 | libc_hidden_proto(settimeofday) |
| 84 | |
| 85 | /* Adjust the current time of day by the amount in DELTA. |
| 86 | If OLDDELTA is not NULL, it is filled in with the amount |
| 87 | of time adjustment remaining to be done from the last `adjtime' call. |
| 88 | This call is restricted to the super-user. */ |
| 89 | extern int adjtime (__const struct timeval *__delta, |
| 90 | struct timeval *__olddelta) __THROW; |
| 91 | #endif |
| 92 | |
| 93 | |
| 94 | /* Values for the first argument to `getitimer' and `setitimer'. */ |
| 95 | enum __itimer_which |
| 96 | { |
| 97 | /* Timers run in real time. */ |
| 98 | ITIMER_REAL = 0, |
| 99 | #define ITIMER_REAL ITIMER_REAL |
| 100 | /* Timers run only when the process is executing. */ |
| 101 | ITIMER_VIRTUAL = 1, |
| 102 | #define ITIMER_VIRTUAL ITIMER_VIRTUAL |
| 103 | /* Timers run when the process is executing and when |
| 104 | the system is executing on behalf of the process. */ |
| 105 | ITIMER_PROF = 2 |
| 106 | #define ITIMER_PROF ITIMER_PROF |
| 107 | }; |
| 108 | |
| 109 | /* Type of the second argument to `getitimer' and |
| 110 | the second and third arguments `setitimer'. */ |
| 111 | struct itimerval |
| 112 | { |
| 113 | /* Value to put into `it_value' when the timer expires. */ |
| 114 | struct timeval it_interval; |
| 115 | /* Time to the next timer expiration. */ |
| 116 | struct timeval it_value; |
| 117 | }; |
| 118 | |
| 119 | #if defined __USE_GNU && !defined __cplusplus |
| 120 | /* Use the nicer parameter type only in GNU mode and not for C++ since the |
| 121 | strict C++ rules prevent the automatic promotion. */ |
| 122 | typedef enum __itimer_which __itimer_which_t; |
| 123 | #else |
| 124 | typedef int __itimer_which_t; |
| 125 | #endif |
| 126 | |
| 127 | /* Set *VALUE to the current setting of timer WHICH. |
| 128 | Return 0 on success, -1 on errors. */ |
| 129 | extern int getitimer (__itimer_which_t __which, |
| 130 | struct itimerval *__value) __THROW; |
| 131 | |
| 132 | /* Set the timer WHICH to *NEW. If OLD is not NULL, |
| 133 | set *OLD to the old value of timer WHICH. |
| 134 | Returns 0 on success, -1 on errors. */ |
| 135 | extern int setitimer (__itimer_which_t __which, |
| 136 | __const struct itimerval *__restrict __new, |
| 137 | struct itimerval *__restrict __old) __THROW; |
| 138 | libc_hidden_proto(setitimer) |
| 139 | |
| 140 | /* Change the access time of FILE to TVP[0] and the modification time of |
| 141 | FILE to TVP[1]. If TVP is a null pointer, use the current time instead. |
| 142 | Returns 0 on success, -1 on errors. */ |
| 143 | extern int utimes (__const char *__file, __const struct timeval __tvp[2]) |
| 144 | __THROW __nonnull ((1)); |
| 145 | libc_hidden_proto(utimes) |
| 146 | |
| 147 | #ifdef __USE_BSD |
| 148 | /* Same as `utimes', but does not follow symbolic links. */ |
| 149 | extern int lutimes (__const char *__file, __const struct timeval __tvp[2]) |
| 150 | __THROW __nonnull ((1)); |
| 151 | |
| 152 | #if 0 |
| 153 | /* Same as `utimes', but takes an open file descriptor instead of a name. */ |
| 154 | extern int futimes (int __fd, __const struct timeval __tvp[2]) __THROW; |
| 155 | #endif |
| 156 | #endif |
| 157 | |
| 158 | #ifdef __USE_GNU |
| 159 | /* Change the access time of FILE relative to FD to TVP[0] and the |
| 160 | modification time of FILE to TVP[1]. If TVP is a null pointer, use |
| 161 | the current time instead. Returns 0 on success, -1 on errors. */ |
| 162 | extern int futimesat (int __fd, __const char *__file, |
| 163 | __const struct timeval __tvp[2]) __THROW; |
| 164 | #endif |
| 165 | |
| 166 | |
| 167 | #ifdef __USE_BSD |
| 168 | /* Convenience macros for operations on timevals. |
| 169 | NOTE: `timercmp' does not work for >= or <=. */ |
| 170 | # define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) |
| 171 | # define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) |
| 172 | # define timercmp(a, b, CMP) \ |
| 173 | (((a)->tv_sec == (b)->tv_sec) ? \ |
| 174 | ((a)->tv_usec CMP (b)->tv_usec) : \ |
| 175 | ((a)->tv_sec CMP (b)->tv_sec)) |
| 176 | # define timeradd(a, b, result) \ |
| 177 | do { \ |
| 178 | (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ |
| 179 | (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ |
| 180 | if ((result)->tv_usec >= 1000000) \ |
| 181 | { \ |
| 182 | ++(result)->tv_sec; \ |
| 183 | (result)->tv_usec -= 1000000; \ |
| 184 | } \ |
| 185 | } while (0) |
| 186 | # define timersub(a, b, result) \ |
| 187 | do { \ |
| 188 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ |
| 189 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ |
| 190 | if ((result)->tv_usec < 0) { \ |
| 191 | --(result)->tv_sec; \ |
| 192 | (result)->tv_usec += 1000000; \ |
| 193 | } \ |
| 194 | } while (0) |
| 195 | #endif /* BSD */ |
| 196 | |
| 197 | __END_DECLS |
| 198 | |
| 199 | #endif /* sys/time.h */ |