428
|
1 /* systime.h - System-dependent definitions for time manipulations.
|
|
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: FSF 19.30. */
|
|
22
|
440
|
23 #ifndef INCLUDED_systime_h_
|
|
24 #define INCLUDED_systime_h_
|
428
|
25
|
|
26 #ifdef TIME_WITH_SYS_TIME
|
442
|
27 # include <sys/time.h>
|
|
28 # include <time.h>
|
428
|
29 #else
|
442
|
30 # ifdef HAVE_SYS_TIME_H
|
|
31 # include <sys/time.h>
|
|
32 # else
|
|
33 # include <time.h>
|
|
34 # endif
|
428
|
35 #endif
|
|
36
|
|
37 /* select() is supposed to be (Unix98) defined in sys/time.h,
|
|
38 but FreeBSD and Irix 5 put it in unistd.h instead.
|
|
39 If we have it, including it can't hurt. */
|
|
40 #ifdef HAVE_UNISTD_H
|
|
41 #include <unistd.h>
|
|
42 #endif
|
|
43
|
442
|
44 #ifdef WIN32_NATIVE
|
|
45
|
|
46 /* This defines struct timeval */
|
|
47 #include <winsock.h>
|
|
48
|
|
49 struct timezone
|
|
50 {
|
|
51 int tz_minuteswest; /* minutes west of Greenwich */
|
|
52 int tz_dsttime; /* type of dst correction */
|
|
53 };
|
|
54
|
|
55 #ifdef HAVE_X_WINDOWS
|
428
|
56 /* Provides gettimeofday etc */
|
|
57 #include <X11/Xw32defs.h>
|
|
58 #include <X11/Xos.h>
|
442
|
59 #else
|
|
60 /* X11R6 on NT provides the single parameter version of this command */
|
|
61 void gettimeofday (struct timeval *, struct timezone *);
|
|
62 #endif /* HAVE_X_WINDOWS */
|
|
63
|
|
64 #endif /* WIN32_NATIVE */
|
428
|
65
|
460
|
66 #ifdef HAVE_UTIME
|
428
|
67 # include <utime.h>
|
|
68 #endif
|
|
69
|
442
|
70 #if defined(HAVE_TZNAME) && !defined(WIN32_NATIVE) && !defined(CYGWIN)
|
428
|
71 #ifndef tzname /* For SGI. */
|
|
72 extern char *tzname[]; /* RS6000 and others want it this way. */
|
|
73 #endif
|
|
74 #endif
|
|
75
|
|
76 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
|
|
77 disagree about the name of the guard symbol. */
|
|
78 #ifdef HPUX
|
|
79 #ifdef _STRUCT_TIMEVAL
|
|
80 #ifndef __TIMEVAL__
|
|
81 #define __TIMEVAL__
|
|
82 #endif
|
|
83 #endif
|
|
84 #endif
|
|
85
|
|
86 /* EMACS_TIME is the type to use to represent temporal intervals.
|
|
87 At one point this was 'struct timeval' on some systems, int on others.
|
|
88 But this is stupid. Other things than select() code like to
|
|
89 manipulate time values, and so microsecond precision should be
|
|
90 maintained. Separate typedefs and conversion functions are provided
|
|
91 for select().
|
|
92
|
|
93 EMACS_SECS (TIME) is an rvalue for the seconds component of TIME.
|
|
94 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS.
|
|
95
|
|
96 EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME.
|
|
97 EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS.
|
|
98
|
|
99 Note that all times are returned in "normalized" format (i.e. the
|
|
100 usecs value is in the range 0 <= value < 1000000) and are assumed
|
|
101 to be passed in in this format.
|
|
102
|
|
103 EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME.
|
|
104
|
|
105 EMACS_GET_TIME (TIME) stores the current system time in TIME, which
|
|
106 should be an lvalue.
|
|
107
|
|
108 set_file_times (PATH, ATIME, MTIME) changes the last-access and
|
|
109 last-modification times of the file named PATH to ATIME and
|
|
110 MTIME, which are EMACS_TIMEs.
|
|
111
|
|
112 EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format.
|
|
113
|
|
114 EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the
|
|
115 result in DEST. Either or both may be negative.
|
|
116
|
|
117 EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and
|
|
118 stores the result in DEST. Either or both may be negative.
|
|
119
|
|
120 EMACS_TIME_NEG_P (TIME) is true iff TIME is negative.
|
|
121
|
|
122 EMACS_TIME_EQUAL (TIME1, TIME2) is true iff TIME1 is the same as TIME2.
|
|
123 EMACS_TIME_GREATER (TIME1, TIME2) is true iff TIME1 is greater than
|
|
124 TIME2.
|
|
125 EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is
|
|
126 greater than or equal to TIME2.
|
|
127
|
|
128 */
|
|
129
|
|
130 #ifdef HAVE_TIMEVAL
|
|
131
|
|
132 #define EMACS_SELECT_TIME struct timeval
|
|
133 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time))
|
|
134
|
|
135 #else /* not HAVE_TIMEVAL */
|
|
136
|
|
137 struct timeval
|
|
138 {
|
|
139 long tv_sec; /* seconds */
|
|
140 long tv_usec; /* microseconds */
|
|
141 };
|
|
142
|
|
143 #define EMACS_SELECT_TIME int
|
|
144 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \
|
|
145 EMACS_TIME_TO_INT (time, select_time)
|
|
146
|
|
147 #endif /* not HAVE_TIMEVAL */
|
|
148
|
|
149 #define EMACS_TIME_TO_INT(time, intvar) \
|
|
150 do { \
|
|
151 EMACS_TIME tmptime = time; \
|
|
152 \
|
|
153 if (tmptime.tv_usec > 0) \
|
|
154 (intvar) = tmptime.tv_sec + 1; \
|
|
155 else \
|
|
156 (intvar) = tmptime.tv_sec; \
|
|
157 } while (0)
|
|
158
|
|
159 #define EMACS_TIME struct timeval
|
|
160 #define EMACS_SECS(time) ((time).tv_sec + 0)
|
|
161 #define EMACS_USECS(time) ((time).tv_usec + 0)
|
|
162 #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds))
|
|
163 #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds))
|
|
164
|
|
165 #if !defined (HAVE_GETTIMEOFDAY)
|
442
|
166 int gettimeofday (struct timeval *, void *);
|
428
|
167 #endif
|
|
168
|
|
169 /* On SVR4, the compiler may complain if given this extra BSD arg. */
|
|
170 #ifdef GETTIMEOFDAY_ONE_ARGUMENT
|
442
|
171 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time)
|
|
172 #else
|
|
173 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time,0)
|
|
174 #endif
|
|
175
|
428
|
176 /* According to the Xt sources, some NTP daemons on some systems may
|
|
177 return non-normalized values. */
|
|
178 #define EMACS_GET_TIME(time) \
|
|
179 do { \
|
442
|
180 EMACS_GETTIMEOFDAY (&(time)); \
|
428
|
181 EMACS_NORMALIZE_TIME (time); \
|
|
182 } while (0)
|
|
183
|
|
184 #define EMACS_NORMALIZE_TIME(time) \
|
|
185 do { \
|
|
186 while ((time).tv_usec >= 1000000) \
|
|
187 { \
|
|
188 (time).tv_usec -= 1000000; \
|
|
189 (time).tv_sec++; \
|
|
190 } \
|
|
191 while ((time).tv_usec < 0) \
|
|
192 { \
|
|
193 (time).tv_usec += 1000000; \
|
|
194 (time).tv_sec--; \
|
|
195 } \
|
|
196 } while (0)
|
|
197
|
|
198 #define EMACS_ADD_TIME(dest, src1, src2) \
|
|
199 do { \
|
|
200 (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
|
|
201 (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \
|
|
202 EMACS_NORMALIZE_TIME (dest); \
|
|
203 } while (0)
|
|
204
|
|
205 #define EMACS_SUB_TIME(dest, src1, src2) \
|
|
206 do { \
|
|
207 (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
|
|
208 (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \
|
|
209 EMACS_NORMALIZE_TIME (dest); \
|
|
210 } while (0)
|
|
211
|
|
212 #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0)
|
|
213
|
|
214 #define EMACS_TIME_EQUAL(time1, time2) \
|
|
215 ((time1).tv_sec == (time2).tv_sec && \
|
|
216 (time1).tv_usec == (time2).tv_usec)
|
|
217
|
|
218 #define EMACS_TIME_GREATER(time1, time2) \
|
|
219 ((time1).tv_sec > (time2).tv_sec || \
|
|
220 ((time1).tv_sec == (time2).tv_sec && \
|
|
221 (time1).tv_usec > (time2).tv_usec))
|
|
222
|
|
223 #define EMACS_TIME_EQUAL_OR_GREATER(time1, time2) \
|
|
224 ((time1).tv_sec > (time2).tv_sec || \
|
|
225 ((time1).tv_sec == (time2).tv_sec && \
|
|
226 (time1).tv_usec >= (time2).tv_usec))
|
|
227
|
|
228 #define EMACS_SET_SECS_USECS(time, secs, usecs) \
|
|
229 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
|
|
230
|
|
231 int set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime);
|
|
232
|
|
233 void get_process_times (double *user_time, double *system_time,
|
|
234 double *real_time);
|
|
235
|
442
|
236 #if defined(WIN32_NATIVE) || defined(BROKEN_CYGWIN)
|
428
|
237
|
|
238 /* setitimer emulation for Win32 (see nt.c) */
|
|
239
|
|
240 struct itimerval
|
|
241 {
|
|
242 struct timeval it_value;
|
|
243 struct timeval it_interval;
|
|
244 };
|
|
245
|
|
246 int setitimer (int kind, const struct itimerval* itnew,
|
|
247 struct itimerval* itold);
|
|
248
|
|
249 #define ITIMER_REAL 1
|
|
250 #define ITIMER_PROF 2
|
|
251
|
442
|
252 #endif /* WIN32_NATIVE */
|
428
|
253
|
440
|
254 #endif /* INCLUDED_systime_h_ */
|