]> sourceware.org Git - glibc.git/blame - time/sys/time.h
Update.
[glibc.git] / time / sys / time.h
CommitLineData
0ed99ce4 1/* Copyright (C) 1991,92,93,94,96,97,98,99,2000 Free Software Foundation, Inc.
b5791037 2 This file is part of the GNU C Library.
28f540f4 3
b5791037
UD
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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
12 Library General Public License for more details.
28f540f4 13
b5791037
UD
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
28f540f4
RM
18
19#ifndef _SYS_TIME_H
28f540f4 20#define _SYS_TIME_H 1
5107cf1d 21
28f540f4
RM
22#include <features.h>
23
24#include <time.h>
df4ef2ab 25#include <sys/select.h>
28f540f4 26
f0e44959 27#define __need_timeval
5107cf1d 28#include <bits/time.h>
28f540f4 29
0ed99ce4
UD
30#ifndef __suseconds_t_defined
31typedef __suseconds_t suseconds_t;
32# define __suseconds_t_defined
33#endif
34
f0e44959
UD
35
36__BEGIN_DECLS
28f540f4 37
28f540f4
RM
38/* Macros for converting between `struct timeval' and `struct timespec'. */
39#define TIMEVAL_TO_TIMESPEC(tv, ts) { \
dbe31b9a
RM
40 (ts)->tv_sec = (tv)->tv_sec; \
41 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
28f540f4
RM
42}
43#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
dbe31b9a
RM
44 (tv)->tv_sec = (ts)->tv_sec; \
45 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
28f540f4
RM
46}
47
48
49/* Structure crudely representing a timezone.
50 This is obsolete and should never be used. */
51struct timezone
52 {
53 int tz_minuteswest; /* Minutes west of GMT. */
54 int tz_dsttime; /* Nonzero if DST is ever in effect. */
55 };
56
0ed99ce4
UD
57#if defined __USE_GNU || defined __USE_BSD
58typedef struct timezone *__timezone_ptr_t;
59#else
60typedef void *__timezone_ptr_t;
61#endif
62
28f540f4
RM
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. */
0ed99ce4 68extern int gettimeofday (struct timeval *__tv, __timezone_ptr_t __tz) __THROW;
28f540f4
RM
69
70/* Set the current time of day and timezone information.
71 This call is restricted to the super-user. */
c1422e5b
UD
72extern int settimeofday (__const struct timeval *__tv,
73 __const struct timezone *__tz) __THROW;
28f540f4
RM
74
75/* Adjust the current time of day by the amount in DELTA.
76 If OLDDELTA is not NULL, it is filled in with the amount
77 of time adjustment remaining to be done from the last `adjtime' call.
78 This call is restricted to the super-user. */
c1422e5b
UD
79extern int adjtime (__const struct timeval *__delta,
80 struct timeval *__olddelta) __THROW;
28f540f4
RM
81
82
83/* Values for the first argument to `getitimer' and `setitimer'. */
84enum __itimer_which
85 {
86 /* Timers run in real time. */
87 ITIMER_REAL = 0,
bc9f6000 88#define ITIMER_REAL ITIMER_REAL
28f540f4
RM
89 /* Timers run only when the process is executing. */
90 ITIMER_VIRTUAL = 1,
bc9f6000 91#define ITIMER_VIRTUAL ITIMER_VIRTUAL
28f540f4
RM
92 /* Timers run when the process is executing and when
93 the system is executing on behalf of the process. */
94 ITIMER_PROF = 2
bc9f6000 95#define ITIMER_PROF ITIMER_PROF
28f540f4
RM
96 };
97
98/* Type of the second argument to `getitimer' and
99 the second and third arguments `setitimer'. */
100struct itimerval
101 {
102 /* Value to put into `it_value' when the timer expires. */
103 struct timeval it_interval;
104 /* Time to the next timer expiration. */
105 struct timeval it_value;
106 };
107
0ed99ce4
UD
108#ifdef __USE_GNU
109typedef enum __itimer_which __itimer_which_t;
110#else
111typedef int __itimer_which_t;
112#endif
113
28f540f4
RM
114/* Set *VALUE to the current setting of timer WHICH.
115 Return 0 on success, -1 on errors. */
0ed99ce4 116extern int getitimer (__itimer_which_t __which,
c1422e5b 117 struct itimerval *__value) __THROW;
28f540f4
RM
118
119/* Set the timer WHICH to *NEW. If OLD is not NULL,
120 set *OLD to the old value of timer WHICH.
121 Returns 0 on success, -1 on errors. */
0ed99ce4 122extern int setitimer (__itimer_which_t __which,
c1422e5b
UD
123 __const struct itimerval *__new,
124 struct itimerval *__old) __THROW;
28f540f4
RM
125
126/* Change the access time of FILE to TVP[0] and
127 the modification time of FILE to TVP[1]. */
0ed99ce4
UD
128extern int utimes (__const char *__file, __const struct timeval __tvp[2])
129 __THROW;
28f540f4
RM
130
131
132/* Convenience macros for operations on timevals.
133 NOTE: `timercmp' does not work for >= or <=. */
134#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
28f540f4 135#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
92777700
RM
136#define timercmp(a, b, CMP) \
137 (((a)->tv_sec == (b)->tv_sec) ? \
138 ((a)->tv_usec CMP (b)->tv_usec) : \
139 ((a)->tv_sec CMP (b)->tv_sec))
140#define timeradd(a, b, result) \
141 do { \
142 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
143 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
144 if ((result)->tv_usec >= 1000000) \
145 { \
146 ++(result)->tv_sec; \
147 (result)->tv_usec -= 1000000; \
148 } \
149 } while (0)
150#define timersub(a, b, result) \
151 do { \
152 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
153 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
154 if ((result)->tv_usec < 0) { \
155 --(result)->tv_sec; \
156 (result)->tv_usec += 1000000; \
157 } \
158 } while (0)
28f540f4 159
28f540f4
RM
160__END_DECLS
161
162#endif /* sys/time.h */
This page took 0.140753 seconds and 5 git commands to generate.