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