Mercurial > hg > xemacs-beta
annotate src/systime.h @ 5932:d2c2d83dbb52 cygwin
working with new Xpm.dll
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Wed, 09 Dec 2015 15:50:11 +0000 |
parents | a0d9bfe304de |
children | c1e8f3294298 |
rev | line source |
---|---|
428 | 1 /* systime.h - System-dependent definitions for time manipulations. |
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. | |
777 | 3 Copyright (C) 2001, 2002 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
3025
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
3025
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
3025
diff
changeset
|
10 option) any later version. |
428 | 11 |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
3025
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 19 |
20 /* Synched up with: FSF 19.30. */ | |
21 | |
440 | 22 #ifndef INCLUDED_systime_h_ |
23 #define INCLUDED_systime_h_ | |
428 | 24 |
25 #ifdef TIME_WITH_SYS_TIME | |
442 | 26 # include <sys/time.h> |
27 # include <time.h> | |
428 | 28 #else |
442 | 29 # ifdef HAVE_SYS_TIME_H |
30 # include <sys/time.h> | |
31 # else | |
32 # include <time.h> | |
33 # endif | |
428 | 34 #endif |
35 | |
777 | 36 #ifdef HAVE_SYS_TIMES_H |
37 /* Need this for struct tms */ | |
771 | 38 # include <sys/times.h> |
39 #endif | |
40 | |
428 | 41 /* select() is supposed to be (Unix98) defined in sys/time.h, |
42 but FreeBSD and Irix 5 put it in unistd.h instead. | |
43 If we have it, including it can't hurt. */ | |
44 #ifdef HAVE_UNISTD_H | |
45 #include <unistd.h> | |
46 #endif | |
47 | |
442 | 48 #ifdef WIN32_NATIVE |
49 | |
50 /* This defines struct timeval */ | |
5930
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
51 /* Temporary override -- HST |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
52 #define _TIMEVAL_DEFINED |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
53 |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
54 struct timeval |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
55 { |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
56 time_t tv_sec; |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
57 time_t tv_usec; |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
58 }; |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
59 #ifndef _INC_WINDOWS |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
60 #include <windows.h> |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
61 #endif / * _INC_WINDOWS * / |
a0d9bfe304de
more 64-bit patches for VS, not sure of many of them
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
62 typedef UINT_PTR SOCKET; */ |
442 | 63 #include <winsock.h> |
64 | |
65 struct timezone | |
66 { | |
67 int tz_minuteswest; /* minutes west of Greenwich */ | |
68 int tz_dsttime; /* type of dst correction */ | |
69 }; | |
70 | |
71 #ifdef HAVE_X_WINDOWS | |
428 | 72 /* Provides gettimeofday etc */ |
73 #include <X11/Xw32defs.h> | |
74 #include <X11/Xos.h> | |
442 | 75 #else |
76 /* X11R6 on NT provides the single parameter version of this command */ | |
77 void gettimeofday (struct timeval *, struct timezone *); | |
78 #endif /* HAVE_X_WINDOWS */ | |
79 | |
80 #endif /* WIN32_NATIVE */ | |
428 | 81 |
592 | 82 /* struct utimbuf */ |
83 | |
460 | 84 #ifdef HAVE_UTIME |
428 | 85 # include <utime.h> |
86 #endif | |
87 | |
592 | 88 #ifdef WIN32_NATIVE |
89 # include <sys/utime.h> | |
771 | 90 #ifdef emacs |
91 int mswindows_utime (Lisp_Object path, struct utimbuf *thymes); | |
92 #endif | |
592 | 93 #endif |
94 | |
442 | 95 #if defined(HAVE_TZNAME) && !defined(WIN32_NATIVE) && !defined(CYGWIN) |
428 | 96 #ifndef tzname /* For SGI. */ |
97 extern char *tzname[]; /* RS6000 and others want it this way. */ | |
98 #endif | |
99 #endif | |
100 | |
101 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h | |
102 disagree about the name of the guard symbol. */ | |
103 #ifdef HPUX | |
104 #ifdef _STRUCT_TIMEVAL | |
105 #ifndef __TIMEVAL__ | |
106 #define __TIMEVAL__ | |
107 #endif | |
108 #endif | |
109 #endif | |
110 | |
111 /* EMACS_TIME is the type to use to represent temporal intervals. | |
3025 | 112 At one point this was `struct timeval' on some systems, int on others. |
428 | 113 But this is stupid. Other things than select() code like to |
114 manipulate time values, and so microsecond precision should be | |
115 maintained. Separate typedefs and conversion functions are provided | |
116 for select(). | |
117 | |
118 EMACS_SECS (TIME) is an rvalue for the seconds component of TIME. | |
119 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS. | |
120 | |
121 EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME. | |
122 EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS. | |
123 | |
124 Note that all times are returned in "normalized" format (i.e. the | |
125 usecs value is in the range 0 <= value < 1000000) and are assumed | |
126 to be passed in in this format. | |
127 | |
128 EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME. | |
129 | |
130 EMACS_GET_TIME (TIME) stores the current system time in TIME, which | |
131 should be an lvalue. | |
132 | |
133 set_file_times (PATH, ATIME, MTIME) changes the last-access and | |
134 last-modification times of the file named PATH to ATIME and | |
135 MTIME, which are EMACS_TIMEs. | |
136 | |
137 EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format. | |
138 | |
139 EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the | |
140 result in DEST. Either or both may be negative. | |
141 | |
142 EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and | |
143 stores the result in DEST. Either or both may be negative. | |
144 | |
145 EMACS_TIME_NEG_P (TIME) is true iff TIME is negative. | |
146 | |
147 EMACS_TIME_EQUAL (TIME1, TIME2) is true iff TIME1 is the same as TIME2. | |
148 EMACS_TIME_GREATER (TIME1, TIME2) is true iff TIME1 is greater than | |
149 TIME2. | |
150 EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is | |
151 greater than or equal to TIME2. | |
152 | |
153 */ | |
154 | |
155 #ifdef HAVE_TIMEVAL | |
156 | |
157 #define EMACS_SELECT_TIME struct timeval | |
158 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time)) | |
159 | |
160 #else /* not HAVE_TIMEVAL */ | |
161 | |
162 struct timeval | |
163 { | |
164 long tv_sec; /* seconds */ | |
165 long tv_usec; /* microseconds */ | |
166 }; | |
167 | |
168 #define EMACS_SELECT_TIME int | |
169 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \ | |
170 EMACS_TIME_TO_INT (time, select_time) | |
171 | |
172 #endif /* not HAVE_TIMEVAL */ | |
173 | |
174 #define EMACS_TIME_TO_INT(time, intvar) \ | |
175 do { \ | |
176 EMACS_TIME tmptime = time; \ | |
177 \ | |
178 if (tmptime.tv_usec > 0) \ | |
179 (intvar) = tmptime.tv_sec + 1; \ | |
180 else \ | |
181 (intvar) = tmptime.tv_sec; \ | |
182 } while (0) | |
183 | |
184 #define EMACS_TIME struct timeval | |
185 #define EMACS_SECS(time) ((time).tv_sec + 0) | |
186 #define EMACS_USECS(time) ((time).tv_usec + 0) | |
187 #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds)) | |
188 #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds)) | |
189 | |
190 #if !defined (HAVE_GETTIMEOFDAY) | |
442 | 191 int gettimeofday (struct timeval *, void *); |
428 | 192 #endif |
193 | |
194 /* On SVR4, the compiler may complain if given this extra BSD arg. */ | |
195 #ifdef GETTIMEOFDAY_ONE_ARGUMENT | |
442 | 196 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time) |
197 #else | |
198 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time,0) | |
199 #endif | |
200 | |
428 | 201 /* According to the Xt sources, some NTP daemons on some systems may |
202 return non-normalized values. */ | |
203 #define EMACS_GET_TIME(time) \ | |
204 do { \ | |
442 | 205 EMACS_GETTIMEOFDAY (&(time)); \ |
428 | 206 EMACS_NORMALIZE_TIME (time); \ |
207 } while (0) | |
208 | |
209 #define EMACS_NORMALIZE_TIME(time) \ | |
210 do { \ | |
211 while ((time).tv_usec >= 1000000) \ | |
212 { \ | |
213 (time).tv_usec -= 1000000; \ | |
214 (time).tv_sec++; \ | |
215 } \ | |
216 while ((time).tv_usec < 0) \ | |
217 { \ | |
218 (time).tv_usec += 1000000; \ | |
219 (time).tv_sec--; \ | |
220 } \ | |
221 } while (0) | |
222 | |
223 #define EMACS_ADD_TIME(dest, src1, src2) \ | |
224 do { \ | |
225 (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \ | |
226 (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \ | |
227 EMACS_NORMALIZE_TIME (dest); \ | |
228 } while (0) | |
229 | |
230 #define EMACS_SUB_TIME(dest, src1, src2) \ | |
231 do { \ | |
232 (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \ | |
233 (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \ | |
234 EMACS_NORMALIZE_TIME (dest); \ | |
235 } while (0) | |
236 | |
237 #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0) | |
238 | |
239 #define EMACS_TIME_EQUAL(time1, time2) \ | |
240 ((time1).tv_sec == (time2).tv_sec && \ | |
241 (time1).tv_usec == (time2).tv_usec) | |
242 | |
243 #define EMACS_TIME_GREATER(time1, time2) \ | |
244 ((time1).tv_sec > (time2).tv_sec || \ | |
245 ((time1).tv_sec == (time2).tv_sec && \ | |
246 (time1).tv_usec > (time2).tv_usec)) | |
247 | |
248 #define EMACS_TIME_EQUAL_OR_GREATER(time1, time2) \ | |
249 ((time1).tv_sec > (time2).tv_sec || \ | |
250 ((time1).tv_sec == (time2).tv_sec && \ | |
251 (time1).tv_usec >= (time2).tv_usec)) | |
252 | |
253 #define EMACS_SET_SECS_USECS(time, secs, usecs) \ | |
254 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs)) | |
255 | |
592 | 256 #ifdef emacs |
257 int set_file_times (Lisp_Object path, EMACS_TIME atime, EMACS_TIME mtime); | |
428 | 258 void get_process_times (double *user_time, double *system_time, |
259 double *real_time); | |
867 | 260 Ibyte *qxe_ctime (const time_t *value); |
771 | 261 |
262 #endif | |
428 | 263 |
611 | 264 #ifdef WIN32_NATIVE |
428 | 265 |
611 | 266 /* setitimer emulation for Win32 (see win32.c) */ |
428 | 267 |
268 struct itimerval | |
269 { | |
270 struct timeval it_value; | |
271 struct timeval it_interval; | |
272 }; | |
273 | |
274 #define ITIMER_REAL 1 | |
275 #define ITIMER_PROF 2 | |
276 | |
442 | 277 #endif /* WIN32_NATIVE */ |
428 | 278 |
1315 | 279 #ifdef WIN32_ANY |
611 | 280 |
281 int mswindows_setitimer (int kind, const struct itimerval *itnew, | |
282 struct itimerval *itold); | |
283 | |
1315 | 284 #endif /* WIN32_ANY */ |
611 | 285 |
286 /* #### Move this comment elsewhere when we figure out the place. | |
287 | |
288 "qxe" is a unique prefix used to identify encapsulations of standard | |
289 library functions. We used to play pre-processing games but in | |
290 general this leads to nothing but trouble because someone first | |
291 encountering the code will have no idea that what appears to be a | |
292 call to a library function has actually been redefined to be a call | |
293 somewhere else. This is doubly true when the redefinition occurs | |
294 in out-of-the way s+m files and only on certainly systems. | |
295 | |
617 | 296 The name "qxe" was chosen because it is a unique string that is not |
297 going to be found anywhere else in the sources (unlike, for example, | |
298 the prefixes "xemacs" or "sys") and is easy to type. Alternative | |
299 names are certainly possible, and suggestions are welcome. | |
300 | |
611 | 301 By making the encapsulation explicit we might be making the code |
302 that uses is slightly less pretty, but this is more than compensated | |
303 for by the huge increase in clarity. | |
304 | |
305 "Standard library function" can refer to any function in any | |
306 standard library. If we are explicitly changing the semantics | |
307 (e.g. Mule-encapsulating), we should use an extended version of | |
308 the prefix, e.g. perhaps "qxe_xlat_" for functions that Mule- | |
309 encapsulate, or "qxe_retry_" for functions that automatically | |
310 retry a system call interrupted by EINTR. In general, if there | |
311 is no prefix extension, it means the function is trying to | |
312 provide (more or less) the same semantics as the standard library | |
313 function; but be aware that the reimplementation may be incomplete | |
314 or differ in important respects. This is especially the case | |
315 when attempts are made to implement Unix functions on MS Windows. | |
617 | 316 |
317 (The comment on the particular encapsulation should describe what | |
318 standard function is being emulated, if this is not obvious, and | |
319 what the differences, if any, from that standard function are.) | |
320 | |
321 An example of this is the qxe_setitimer() function. This attempts | |
322 to emulate the POSIX (Unix98?) standard setitimer(), as found on | |
323 all modern versions of Unix. Normally, we just call the system- | |
324 provided setitimer() function. When emulated on MS Windows and | |
325 Cygwin, however, the ITNEW and ITOLD values cannot be different | |
326 from each other if both are non-zero, due to limitations in the | |
327 underlying multimedia-timer API. By simply using setitimer() with | |
328 preprocessor tricks, a programmer would almost have to be a | |
329 mind-reader to figure this out. With the explicit encapsulation, a | |
330 programmer need only look at the definition of qxe_setitimer() to | |
331 see what its semantics are. | |
611 | 332 */ |
333 | |
334 int qxe_setitimer (int kind, const struct itimerval *itnew, | |
335 struct itimerval *itold); | |
336 | |
440 | 337 #endif /* INCLUDED_systime_h_ */ |