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
|
592
|
66 /* struct utimbuf */
|
|
67
|
460
|
68 #ifdef HAVE_UTIME
|
428
|
69 # include <utime.h>
|
|
70 #endif
|
|
71
|
592
|
72 #ifdef WIN32_NATIVE
|
|
73 # include <sys/utime.h>
|
|
74 #endif
|
|
75
|
442
|
76 #if defined(HAVE_TZNAME) && !defined(WIN32_NATIVE) && !defined(CYGWIN)
|
428
|
77 #ifndef tzname /* For SGI. */
|
|
78 extern char *tzname[]; /* RS6000 and others want it this way. */
|
|
79 #endif
|
|
80 #endif
|
|
81
|
|
82 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
|
|
83 disagree about the name of the guard symbol. */
|
|
84 #ifdef HPUX
|
|
85 #ifdef _STRUCT_TIMEVAL
|
|
86 #ifndef __TIMEVAL__
|
|
87 #define __TIMEVAL__
|
|
88 #endif
|
|
89 #endif
|
|
90 #endif
|
|
91
|
|
92 /* EMACS_TIME is the type to use to represent temporal intervals.
|
|
93 At one point this was 'struct timeval' on some systems, int on others.
|
|
94 But this is stupid. Other things than select() code like to
|
|
95 manipulate time values, and so microsecond precision should be
|
|
96 maintained. Separate typedefs and conversion functions are provided
|
|
97 for select().
|
|
98
|
|
99 EMACS_SECS (TIME) is an rvalue for the seconds component of TIME.
|
|
100 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS.
|
|
101
|
|
102 EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME.
|
|
103 EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS.
|
|
104
|
|
105 Note that all times are returned in "normalized" format (i.e. the
|
|
106 usecs value is in the range 0 <= value < 1000000) and are assumed
|
|
107 to be passed in in this format.
|
|
108
|
|
109 EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME.
|
|
110
|
|
111 EMACS_GET_TIME (TIME) stores the current system time in TIME, which
|
|
112 should be an lvalue.
|
|
113
|
|
114 set_file_times (PATH, ATIME, MTIME) changes the last-access and
|
|
115 last-modification times of the file named PATH to ATIME and
|
|
116 MTIME, which are EMACS_TIMEs.
|
|
117
|
|
118 EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format.
|
|
119
|
|
120 EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the
|
|
121 result in DEST. Either or both may be negative.
|
|
122
|
|
123 EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and
|
|
124 stores the result in DEST. Either or both may be negative.
|
|
125
|
|
126 EMACS_TIME_NEG_P (TIME) is true iff TIME is negative.
|
|
127
|
|
128 EMACS_TIME_EQUAL (TIME1, TIME2) is true iff TIME1 is the same as TIME2.
|
|
129 EMACS_TIME_GREATER (TIME1, TIME2) is true iff TIME1 is greater than
|
|
130 TIME2.
|
|
131 EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is
|
|
132 greater than or equal to TIME2.
|
|
133
|
|
134 */
|
|
135
|
|
136 #ifdef HAVE_TIMEVAL
|
|
137
|
|
138 #define EMACS_SELECT_TIME struct timeval
|
|
139 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time))
|
|
140
|
|
141 #else /* not HAVE_TIMEVAL */
|
|
142
|
|
143 struct timeval
|
|
144 {
|
|
145 long tv_sec; /* seconds */
|
|
146 long tv_usec; /* microseconds */
|
|
147 };
|
|
148
|
|
149 #define EMACS_SELECT_TIME int
|
|
150 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \
|
|
151 EMACS_TIME_TO_INT (time, select_time)
|
|
152
|
|
153 #endif /* not HAVE_TIMEVAL */
|
|
154
|
|
155 #define EMACS_TIME_TO_INT(time, intvar) \
|
|
156 do { \
|
|
157 EMACS_TIME tmptime = time; \
|
|
158 \
|
|
159 if (tmptime.tv_usec > 0) \
|
|
160 (intvar) = tmptime.tv_sec + 1; \
|
|
161 else \
|
|
162 (intvar) = tmptime.tv_sec; \
|
|
163 } while (0)
|
|
164
|
|
165 #define EMACS_TIME struct timeval
|
|
166 #define EMACS_SECS(time) ((time).tv_sec + 0)
|
|
167 #define EMACS_USECS(time) ((time).tv_usec + 0)
|
|
168 #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds))
|
|
169 #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds))
|
|
170
|
|
171 #if !defined (HAVE_GETTIMEOFDAY)
|
442
|
172 int gettimeofday (struct timeval *, void *);
|
428
|
173 #endif
|
|
174
|
|
175 /* On SVR4, the compiler may complain if given this extra BSD arg. */
|
|
176 #ifdef GETTIMEOFDAY_ONE_ARGUMENT
|
442
|
177 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time)
|
|
178 #else
|
|
179 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time,0)
|
|
180 #endif
|
|
181
|
428
|
182 /* According to the Xt sources, some NTP daemons on some systems may
|
|
183 return non-normalized values. */
|
|
184 #define EMACS_GET_TIME(time) \
|
|
185 do { \
|
442
|
186 EMACS_GETTIMEOFDAY (&(time)); \
|
428
|
187 EMACS_NORMALIZE_TIME (time); \
|
|
188 } while (0)
|
|
189
|
|
190 #define EMACS_NORMALIZE_TIME(time) \
|
|
191 do { \
|
|
192 while ((time).tv_usec >= 1000000) \
|
|
193 { \
|
|
194 (time).tv_usec -= 1000000; \
|
|
195 (time).tv_sec++; \
|
|
196 } \
|
|
197 while ((time).tv_usec < 0) \
|
|
198 { \
|
|
199 (time).tv_usec += 1000000; \
|
|
200 (time).tv_sec--; \
|
|
201 } \
|
|
202 } while (0)
|
|
203
|
|
204 #define EMACS_ADD_TIME(dest, src1, src2) \
|
|
205 do { \
|
|
206 (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
|
|
207 (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \
|
|
208 EMACS_NORMALIZE_TIME (dest); \
|
|
209 } while (0)
|
|
210
|
|
211 #define EMACS_SUB_TIME(dest, src1, src2) \
|
|
212 do { \
|
|
213 (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
|
|
214 (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \
|
|
215 EMACS_NORMALIZE_TIME (dest); \
|
|
216 } while (0)
|
|
217
|
|
218 #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0)
|
|
219
|
|
220 #define EMACS_TIME_EQUAL(time1, time2) \
|
|
221 ((time1).tv_sec == (time2).tv_sec && \
|
|
222 (time1).tv_usec == (time2).tv_usec)
|
|
223
|
|
224 #define EMACS_TIME_GREATER(time1, time2) \
|
|
225 ((time1).tv_sec > (time2).tv_sec || \
|
|
226 ((time1).tv_sec == (time2).tv_sec && \
|
|
227 (time1).tv_usec > (time2).tv_usec))
|
|
228
|
|
229 #define EMACS_TIME_EQUAL_OR_GREATER(time1, time2) \
|
|
230 ((time1).tv_sec > (time2).tv_sec || \
|
|
231 ((time1).tv_sec == (time2).tv_sec && \
|
|
232 (time1).tv_usec >= (time2).tv_usec))
|
|
233
|
|
234 #define EMACS_SET_SECS_USECS(time, secs, usecs) \
|
|
235 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
|
|
236
|
592
|
237 #ifdef emacs
|
|
238 int set_file_times (Lisp_Object path, EMACS_TIME atime, EMACS_TIME mtime);
|
|
239 #endif
|
428
|
240
|
|
241 void get_process_times (double *user_time, double *system_time,
|
|
242 double *real_time);
|
|
243
|
611
|
244 #ifdef WIN32_NATIVE
|
428
|
245
|
611
|
246 /* setitimer emulation for Win32 (see win32.c) */
|
428
|
247
|
|
248 struct itimerval
|
|
249 {
|
|
250 struct timeval it_value;
|
|
251 struct timeval it_interval;
|
|
252 };
|
|
253
|
|
254 #define ITIMER_REAL 1
|
|
255 #define ITIMER_PROF 2
|
|
256
|
442
|
257 #endif /* WIN32_NATIVE */
|
428
|
258
|
611
|
259 #if defined (WIN32_NATIVE) || defined (CYGWIN)
|
|
260
|
|
261 int mswindows_setitimer (int kind, const struct itimerval *itnew,
|
|
262 struct itimerval *itold);
|
|
263
|
|
264 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN) */
|
|
265
|
|
266 /* #### Move this comment elsewhere when we figure out the place.
|
|
267
|
|
268 "qxe" is a unique prefix used to identify encapsulations of standard
|
|
269 library functions. We used to play pre-processing games but in
|
|
270 general this leads to nothing but trouble because someone first
|
|
271 encountering the code will have no idea that what appears to be a
|
|
272 call to a library function has actually been redefined to be a call
|
|
273 somewhere else. This is doubly true when the redefinition occurs
|
|
274 in out-of-the way s+m files and only on certainly systems.
|
|
275
|
617
|
276 The name "qxe" was chosen because it is a unique string that is not
|
|
277 going to be found anywhere else in the sources (unlike, for example,
|
|
278 the prefixes "xemacs" or "sys") and is easy to type. Alternative
|
|
279 names are certainly possible, and suggestions are welcome.
|
|
280
|
611
|
281 By making the encapsulation explicit we might be making the code
|
|
282 that uses is slightly less pretty, but this is more than compensated
|
|
283 for by the huge increase in clarity.
|
|
284
|
|
285 "Standard library function" can refer to any function in any
|
|
286 standard library. If we are explicitly changing the semantics
|
|
287 (e.g. Mule-encapsulating), we should use an extended version of
|
|
288 the prefix, e.g. perhaps "qxe_xlat_" for functions that Mule-
|
|
289 encapsulate, or "qxe_retry_" for functions that automatically
|
|
290 retry a system call interrupted by EINTR. In general, if there
|
|
291 is no prefix extension, it means the function is trying to
|
|
292 provide (more or less) the same semantics as the standard library
|
|
293 function; but be aware that the reimplementation may be incomplete
|
|
294 or differ in important respects. This is especially the case
|
|
295 when attempts are made to implement Unix functions on MS Windows.
|
617
|
296
|
|
297 (The comment on the particular encapsulation should describe what
|
|
298 standard function is being emulated, if this is not obvious, and
|
|
299 what the differences, if any, from that standard function are.)
|
|
300
|
|
301 An example of this is the qxe_setitimer() function. This attempts
|
|
302 to emulate the POSIX (Unix98?) standard setitimer(), as found on
|
|
303 all modern versions of Unix. Normally, we just call the system-
|
|
304 provided setitimer() function. When emulated on MS Windows and
|
|
305 Cygwin, however, the ITNEW and ITOLD values cannot be different
|
|
306 from each other if both are non-zero, due to limitations in the
|
|
307 underlying multimedia-timer API. By simply using setitimer() with
|
|
308 preprocessor tricks, a programmer would almost have to be a
|
|
309 mind-reader to figure this out. With the explicit encapsulation, a
|
|
310 programmer need only look at the definition of qxe_setitimer() to
|
|
311 see what its semantics are.
|
611
|
312 */
|
|
313
|
|
314 int qxe_setitimer (int kind, const struct itimerval *itnew,
|
|
315 struct itimerval *itold);
|
|
316
|
440
|
317 #endif /* INCLUDED_systime_h_ */
|