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