]> git.ipfire.org Git - thirdparty/glibc.git/blame - time/sys/time.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / time / sys / time.h
CommitLineData
2b778ceb 1/* Copyright (C) 1991-2021 Free Software Foundation, Inc.
b5791037 2 This file is part of the GNU C Library.
28f540f4 3
b5791037 4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4 8
b5791037
UD
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
41bdb6e2 12 Lesser General Public License for more details.
28f540f4 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
28f540f4
RM
17
18#ifndef _SYS_TIME_H
28f540f4 19#define _SYS_TIME_H 1
5107cf1d 20
28f540f4
RM
21#include <features.h>
22
8be918b7 23#include <bits/types.h>
05b68e14
ZW
24#include <bits/types/time_t.h>
25#include <bits/types/struct_timeval.h>
2ff458eb 26
0ed99ce4
UD
27#ifndef __suseconds_t_defined
28typedef __suseconds_t suseconds_t;
29# define __suseconds_t_defined
30#endif
31
05b68e14 32#include <sys/select.h>
f0e44959
UD
33
34__BEGIN_DECLS
28f540f4 35
8be918b7 36#ifdef __USE_GNU
28f540f4 37/* Macros for converting between `struct timeval' and `struct timespec'. */
8be918b7 38# define TIMEVAL_TO_TIMESPEC(tv, ts) { \
a784e502
UD
39 (ts)->tv_sec = (tv)->tv_sec; \
40 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
28f540f4 41}
8be918b7 42# define TIMESPEC_TO_TIMEVAL(tv, ts) { \
a784e502
UD
43 (tv)->tv_sec = (ts)->tv_sec; \
44 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
28f540f4 45}
8be918b7 46#endif
28f540f4
RM
47
48
498afc54 49#ifdef __USE_MISC
28f540f4
RM
50/* Structure crudely representing a timezone.
51 This is obsolete and should never be used. */
52struct timezone
53 {
54 int tz_minuteswest; /* Minutes west of GMT. */
55 int tz_dsttime; /* Nonzero if DST is ever in effect. */
56 };
0ed99ce4
UD
57#endif
58
2f2c76e1
ZW
59/* Get the current time of day, putting it into *TV.
60 If TZ is not null, *TZ must be a struct timezone, and both fields
61 will be set to zero.
62 Calling this function with a non-null TZ is obsolete;
63 use localtime etc. instead.
64 This function itself is semi-obsolete;
65 most callers should use time or clock_gettime instead. */
98cbe360 66extern int gettimeofday (struct timeval *__restrict __tv,
2f2c76e1 67 void *__restrict __tz) __THROW __nonnull ((1));
28f540f4 68
498afc54 69#ifdef __USE_MISC
28f540f4 70/* Set the current time of day and timezone information.
2f2c76e1
ZW
71 This call is restricted to the super-user.
72 Setting the timezone in this way is obsolete, but we don't yet
73 warn about it because it still has some uses for which there is
74 no alternative. */
a784e502
UD
75extern int settimeofday (const struct timeval *__tv,
76 const struct timezone *__tz)
4b7634a5 77 __THROW;
28f540f4
RM
78
79/* Adjust the current time of day by the amount in DELTA.
80 If OLDDELTA is not NULL, it is filled in with the amount
81 of time adjustment remaining to be done from the last `adjtime' call.
82 This call is restricted to the super-user. */
a784e502 83extern int adjtime (const struct timeval *__delta,
c1422e5b 84 struct timeval *__olddelta) __THROW;
8be918b7 85#endif
28f540f4
RM
86
87
88/* Values for the first argument to `getitimer' and `setitimer'. */
89enum __itimer_which
90 {
91 /* Timers run in real time. */
92 ITIMER_REAL = 0,
bc9f6000 93#define ITIMER_REAL ITIMER_REAL
28f540f4
RM
94 /* Timers run only when the process is executing. */
95 ITIMER_VIRTUAL = 1,
bc9f6000 96#define ITIMER_VIRTUAL ITIMER_VIRTUAL
28f540f4
RM
97 /* Timers run when the process is executing and when
98 the system is executing on behalf of the process. */
99 ITIMER_PROF = 2
bc9f6000 100#define ITIMER_PROF ITIMER_PROF
28f540f4
RM
101 };
102
103/* Type of the second argument to `getitimer' and
104 the second and third arguments `setitimer'. */
105struct itimerval
106 {
107 /* Value to put into `it_value' when the timer expires. */
108 struct timeval it_interval;
109 /* Time to the next timer expiration. */
110 struct timeval it_value;
111 };
112
d002205f
UD
113#if defined __USE_GNU && !defined __cplusplus
114/* Use the nicer parameter type only in GNU mode and not for C++ since the
115 strict C++ rules prevent the automatic promotion. */
0ed99ce4
UD
116typedef enum __itimer_which __itimer_which_t;
117#else
118typedef int __itimer_which_t;
119#endif
120
28f540f4
RM
121/* Set *VALUE to the current setting of timer WHICH.
122 Return 0 on success, -1 on errors. */
0ed99ce4 123extern int getitimer (__itimer_which_t __which,
c1422e5b 124 struct itimerval *__value) __THROW;
28f540f4
RM
125
126/* Set the timer WHICH to *NEW. If OLD is not NULL,
127 set *OLD to the old value of timer WHICH.
128 Returns 0 on success, -1 on errors. */
0ed99ce4 129extern int setitimer (__itimer_which_t __which,
a784e502 130 const struct itimerval *__restrict __new,
98cbe360 131 struct itimerval *__restrict __old) __THROW;
28f540f4 132
20acbc25
RM
133/* Change the access time of FILE to TVP[0] and the modification time of
134 FILE to TVP[1]. If TVP is a null pointer, use the current time instead.
135 Returns 0 on success, -1 on errors. */
a784e502 136extern int utimes (const char *__file, const struct timeval __tvp[2])
26cec518 137 __THROW __nonnull ((1));
28f540f4 138
498afc54 139#ifdef __USE_MISC
20acbc25 140/* Same as `utimes', but does not follow symbolic links. */
a784e502 141extern int lutimes (const char *__file, const struct timeval __tvp[2])
26cec518 142 __THROW __nonnull ((1));
20acbc25
RM
143
144/* Same as `utimes', but takes an open file descriptor instead of a name. */
a784e502 145extern int futimes (int __fd, const struct timeval __tvp[2]) __THROW;
20acbc25
RM
146#endif
147
3e6b0a28 148#ifdef __USE_GNU
26cec518
UD
149/* Change the access time of FILE relative to FD to TVP[0] and the
150 modification time of FILE to TVP[1]. If TVP is a null pointer, use
151 the current time instead. Returns 0 on success, -1 on errors. */
a784e502
UD
152extern int futimesat (int __fd, const char *__file,
153 const struct timeval __tvp[2]) __THROW;
26cec518
UD
154#endif
155
28f540f4 156
498afc54 157#ifdef __USE_MISC
28f540f4
RM
158/* Convenience macros for operations on timevals.
159 NOTE: `timercmp' does not work for >= or <=. */
8be918b7
UD
160# define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
161# define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
162# define timercmp(a, b, CMP) \
34a5a146
JM
163 (((a)->tv_sec == (b)->tv_sec) \
164 ? ((a)->tv_usec CMP (b)->tv_usec) \
165 : ((a)->tv_sec CMP (b)->tv_sec))
8be918b7 166# define timeradd(a, b, result) \
92777700
RM
167 do { \
168 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
169 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
170 if ((result)->tv_usec >= 1000000) \
171 { \
172 ++(result)->tv_sec; \
173 (result)->tv_usec -= 1000000; \
174 } \
175 } while (0)
8be918b7 176# define timersub(a, b, result) \
92777700
RM
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 < 0) { \
181 --(result)->tv_sec; \
182 (result)->tv_usec += 1000000; \
183 } \
184 } while (0)
acd7f096 185#endif /* Misc. */
28f540f4 186
28f540f4
RM
187__END_DECLS
188
189#endif /* sys/time.h */