1 |
1325 |
phoenix |
/* Copyright (C) 1991-1994,96,97,98,99,2000,2001 Free Software Foundation, Inc.
|
2 |
|
|
This file is part of the GNU C Library.
|
3 |
|
|
|
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.
|
8 |
|
|
|
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.
|
13 |
|
|
|
14 |
|
|
You should have received a copy of the GNU Lesser General Public
|
15 |
|
|
License along with the GNU C Library; if not, write to the Free
|
16 |
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
17 |
|
|
02111-1307 USA. */
|
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;
|
74 |
|
|
|
75 |
|
|
#ifdef __USE_BSD
|
76 |
|
|
/* Set the current time of day and timezone information.
|
77 |
|
|
This call is restricted to the super-user. */
|
78 |
|
|
extern int settimeofday (__const struct timeval *__tv,
|
79 |
|
|
__const struct timezone *__tz) __THROW;
|
80 |
|
|
|
81 |
|
|
/* Adjust the current time of day by the amount in DELTA.
|
82 |
|
|
If OLDDELTA is not NULL, it is filled in with the amount
|
83 |
|
|
of time adjustment remaining to be done from the last `adjtime' call.
|
84 |
|
|
This call is restricted to the super-user. */
|
85 |
|
|
extern int adjtime (__const struct timeval *__delta,
|
86 |
|
|
struct timeval *__olddelta) __THROW;
|
87 |
|
|
#endif
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
/* Values for the first argument to `getitimer' and `setitimer'. */
|
91 |
|
|
enum __itimer_which
|
92 |
|
|
{
|
93 |
|
|
/* Timers run in real time. */
|
94 |
|
|
ITIMER_REAL = 0,
|
95 |
|
|
#define ITIMER_REAL ITIMER_REAL
|
96 |
|
|
/* Timers run only when the process is executing. */
|
97 |
|
|
ITIMER_VIRTUAL = 1,
|
98 |
|
|
#define ITIMER_VIRTUAL ITIMER_VIRTUAL
|
99 |
|
|
/* Timers run when the process is executing and when
|
100 |
|
|
the system is executing on behalf of the process. */
|
101 |
|
|
ITIMER_PROF = 2
|
102 |
|
|
#define ITIMER_PROF ITIMER_PROF
|
103 |
|
|
};
|
104 |
|
|
|
105 |
|
|
/* Type of the second argument to `getitimer' and
|
106 |
|
|
the second and third arguments `setitimer'. */
|
107 |
|
|
struct itimerval
|
108 |
|
|
{
|
109 |
|
|
/* Value to put into `it_value' when the timer expires. */
|
110 |
|
|
struct timeval it_interval;
|
111 |
|
|
/* Time to the next timer expiration. */
|
112 |
|
|
struct timeval it_value;
|
113 |
|
|
};
|
114 |
|
|
|
115 |
|
|
#if defined __USE_GNU && !defined __cplusplus
|
116 |
|
|
/* Use the nicer parameter type only in GNU mode and not for C++ since the
|
117 |
|
|
strict C++ rules prevent the automatic promotion. */
|
118 |
|
|
typedef enum __itimer_which __itimer_which_t;
|
119 |
|
|
#else
|
120 |
|
|
typedef int __itimer_which_t;
|
121 |
|
|
#endif
|
122 |
|
|
|
123 |
|
|
/* Set *VALUE to the current setting of timer WHICH.
|
124 |
|
|
Return 0 on success, -1 on errors. */
|
125 |
|
|
extern int getitimer (__itimer_which_t __which,
|
126 |
|
|
struct itimerval *__value) __THROW;
|
127 |
|
|
|
128 |
|
|
/* Set the timer WHICH to *NEW. If OLD is not NULL,
|
129 |
|
|
set *OLD to the old value of timer WHICH.
|
130 |
|
|
Returns 0 on success, -1 on errors. */
|
131 |
|
|
extern int setitimer (__itimer_which_t __which,
|
132 |
|
|
__const struct itimerval *__restrict __new,
|
133 |
|
|
struct itimerval *__restrict __old) __THROW;
|
134 |
|
|
|
135 |
|
|
/* Change the access time of FILE to TVP[0] and
|
136 |
|
|
the modification time of FILE to TVP[1]. */
|
137 |
|
|
extern int utimes (__const char *__file, __const struct timeval __tvp[2])
|
138 |
|
|
__THROW;
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
#ifdef __USE_BSD
|
142 |
|
|
/* Convenience macros for operations on timevals.
|
143 |
|
|
NOTE: `timercmp' does not work for >= or <=. */
|
144 |
|
|
# define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
|
145 |
|
|
# define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
|
146 |
|
|
# define timercmp(a, b, CMP) \
|
147 |
|
|
(((a)->tv_sec == (b)->tv_sec) ? \
|
148 |
|
|
((a)->tv_usec CMP (b)->tv_usec) : \
|
149 |
|
|
((a)->tv_sec CMP (b)->tv_sec))
|
150 |
|
|
# define timeradd(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 >= 1000000) \
|
155 |
|
|
{ \
|
156 |
|
|
++(result)->tv_sec; \
|
157 |
|
|
(result)->tv_usec -= 1000000; \
|
158 |
|
|
} \
|
159 |
|
|
} while (0)
|
160 |
|
|
# define timersub(a, b, result) \
|
161 |
|
|
do { \
|
162 |
|
|
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
163 |
|
|
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
164 |
|
|
if ((result)->tv_usec < 0) { \
|
165 |
|
|
--(result)->tv_sec; \
|
166 |
|
|
(result)->tv_usec += 1000000; \
|
167 |
|
|
} \
|
168 |
|
|
} while (0)
|
169 |
|
|
#endif /* BSD */
|
170 |
|
|
|
171 |
|
|
__END_DECLS
|
172 |
|
|
|
173 |
|
|
#endif /* sys/time.h */
|