Mercurial > hg > xemacs-beta
comparison src/systime.h @ 428:3ecd8885ac67 r21-2-22
Import from CVS: tag r21-2-22
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:28:15 +0200 |
parents | |
children | 8de8e3f6228a |
comparison
equal
deleted
inserted
replaced
427:0a0253eac470 | 428:3ecd8885ac67 |
---|---|
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 | |
23 #ifndef _XEMACS_SYSTIME_H_ | |
24 #define _XEMACS_SYSTIME_H_ | |
25 | |
26 #ifdef TIME_WITH_SYS_TIME | |
27 #include <sys/time.h> | |
28 #include <time.h> | |
29 #else | |
30 #ifdef HAVE_SYS_TIME_H | |
31 #include <sys/time.h> | |
32 #else | |
33 #include <time.h> | |
34 #endif | |
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 | |
44 #if defined(WINDOWSNT) && defined(HAVE_X_WINDOWS) | |
45 /* Provides gettimeofday etc */ | |
46 #include <X11/Xw32defs.h> | |
47 #include <X11/Xos.h> | |
48 #endif | |
49 | |
50 #ifdef HAVE_UTIME_H | |
51 # include <utime.h> | |
52 #endif | |
53 | |
54 #ifdef HAVE_TZNAME | |
55 #ifndef tzname /* For SGI. */ | |
56 extern char *tzname[]; /* RS6000 and others want it this way. */ | |
57 #endif | |
58 #endif | |
59 | |
60 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h | |
61 disagree about the name of the guard symbol. */ | |
62 #ifdef HPUX | |
63 #ifdef _STRUCT_TIMEVAL | |
64 #ifndef __TIMEVAL__ | |
65 #define __TIMEVAL__ | |
66 #endif | |
67 #endif | |
68 #endif | |
69 | |
70 /* EMACS_TIME is the type to use to represent temporal intervals. | |
71 At one point this was 'struct timeval' on some systems, int on others. | |
72 But this is stupid. Other things than select() code like to | |
73 manipulate time values, and so microsecond precision should be | |
74 maintained. Separate typedefs and conversion functions are provided | |
75 for select(). | |
76 | |
77 EMACS_SECS (TIME) is an rvalue for the seconds component of TIME. | |
78 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS. | |
79 | |
80 EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME. | |
81 EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS. | |
82 | |
83 Note that all times are returned in "normalized" format (i.e. the | |
84 usecs value is in the range 0 <= value < 1000000) and are assumed | |
85 to be passed in in this format. | |
86 | |
87 EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME. | |
88 | |
89 EMACS_GET_TIME (TIME) stores the current system time in TIME, which | |
90 should be an lvalue. | |
91 | |
92 set_file_times (PATH, ATIME, MTIME) changes the last-access and | |
93 last-modification times of the file named PATH to ATIME and | |
94 MTIME, which are EMACS_TIMEs. | |
95 | |
96 EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format. | |
97 | |
98 EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the | |
99 result in DEST. Either or both may be negative. | |
100 | |
101 EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and | |
102 stores the result in DEST. Either or both may be negative. | |
103 | |
104 EMACS_TIME_NEG_P (TIME) is true iff TIME is negative. | |
105 | |
106 EMACS_TIME_EQUAL (TIME1, TIME2) is true iff TIME1 is the same as TIME2. | |
107 EMACS_TIME_GREATER (TIME1, TIME2) is true iff TIME1 is greater than | |
108 TIME2. | |
109 EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is | |
110 greater than or equal to TIME2. | |
111 | |
112 */ | |
113 | |
114 #ifdef HAVE_TIMEVAL | |
115 | |
116 #define EMACS_SELECT_TIME struct timeval | |
117 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time)) | |
118 | |
119 #else /* not HAVE_TIMEVAL */ | |
120 | |
121 struct timeval | |
122 { | |
123 long tv_sec; /* seconds */ | |
124 long tv_usec; /* microseconds */ | |
125 }; | |
126 | |
127 #define EMACS_SELECT_TIME int | |
128 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \ | |
129 EMACS_TIME_TO_INT (time, select_time) | |
130 | |
131 #endif /* not HAVE_TIMEVAL */ | |
132 | |
133 #define EMACS_TIME_TO_INT(time, intvar) \ | |
134 do { \ | |
135 EMACS_TIME tmptime = time; \ | |
136 \ | |
137 if (tmptime.tv_usec > 0) \ | |
138 (intvar) = tmptime.tv_sec + 1; \ | |
139 else \ | |
140 (intvar) = tmptime.tv_sec; \ | |
141 } while (0) | |
142 | |
143 #define EMACS_TIME struct timeval | |
144 #define EMACS_SECS(time) ((time).tv_sec + 0) | |
145 #define EMACS_USECS(time) ((time).tv_usec + 0) | |
146 #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds)) | |
147 #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds)) | |
148 | |
149 #if !defined (HAVE_GETTIMEOFDAY) | |
150 struct timezone; | |
151 int gettimeofday (struct timeval *, struct timezone *); | |
152 #endif | |
153 | |
154 /* On SVR4, the compiler may complain if given this extra BSD arg. */ | |
155 #ifdef GETTIMEOFDAY_ONE_ARGUMENT | |
156 # ifdef SOLARIS2 | |
157 /* Solaris (at least) omits this prototype. IRIX5 has it and chokes if we | |
158 declare it here. */ | |
159 int gettimeofday (struct timeval *); | |
160 # endif | |
161 /* According to the Xt sources, some NTP daemons on some systems may | |
162 return non-normalized values. */ | |
163 #define EMACS_GET_TIME(time) \ | |
164 do { \ | |
165 gettimeofday (&(time)); \ | |
166 EMACS_NORMALIZE_TIME (time); \ | |
167 } while (0) | |
168 #else /* not GETTIMEOFDAY_ONE_ARGUMENT */ | |
169 # ifdef SOLARIS2 | |
170 /* Solaris doesn't provide any prototype of this unless a bunch of | |
171 crap we don't define are defined. */ | |
172 int gettimeofday (struct timeval *, void *dummy); | |
173 # endif | |
174 #define EMACS_GET_TIME(time) \ | |
175 do { \ | |
176 struct timezone dummy; \ | |
177 gettimeofday (&(time), &dummy); \ | |
178 EMACS_NORMALIZE_TIME (time); \ | |
179 } while (0) | |
180 #endif /* not GETTIMEOFDAY_ONE_ARGUMENT */ | |
181 | |
182 #define EMACS_NORMALIZE_TIME(time) \ | |
183 do { \ | |
184 while ((time).tv_usec >= 1000000) \ | |
185 { \ | |
186 (time).tv_usec -= 1000000; \ | |
187 (time).tv_sec++; \ | |
188 } \ | |
189 while ((time).tv_usec < 0) \ | |
190 { \ | |
191 (time).tv_usec += 1000000; \ | |
192 (time).tv_sec--; \ | |
193 } \ | |
194 } while (0) | |
195 | |
196 #define EMACS_ADD_TIME(dest, src1, src2) \ | |
197 do { \ | |
198 (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \ | |
199 (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \ | |
200 EMACS_NORMALIZE_TIME (dest); \ | |
201 } while (0) | |
202 | |
203 #define EMACS_SUB_TIME(dest, src1, src2) \ | |
204 do { \ | |
205 (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \ | |
206 (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \ | |
207 EMACS_NORMALIZE_TIME (dest); \ | |
208 } while (0) | |
209 | |
210 #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0) | |
211 | |
212 #define EMACS_TIME_EQUAL(time1, time2) \ | |
213 ((time1).tv_sec == (time2).tv_sec && \ | |
214 (time1).tv_usec == (time2).tv_usec) | |
215 | |
216 #define EMACS_TIME_GREATER(time1, time2) \ | |
217 ((time1).tv_sec > (time2).tv_sec || \ | |
218 ((time1).tv_sec == (time2).tv_sec && \ | |
219 (time1).tv_usec > (time2).tv_usec)) | |
220 | |
221 #define EMACS_TIME_EQUAL_OR_GREATER(time1, time2) \ | |
222 ((time1).tv_sec > (time2).tv_sec || \ | |
223 ((time1).tv_sec == (time2).tv_sec && \ | |
224 (time1).tv_usec >= (time2).tv_usec)) | |
225 | |
226 #define EMACS_SET_SECS_USECS(time, secs, usecs) \ | |
227 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs)) | |
228 | |
229 int set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime); | |
230 | |
231 void get_process_times (double *user_time, double *system_time, | |
232 double *real_time); | |
233 | |
234 #if defined(WINDOWSNT) || defined(BROKEN_CYGWIN) || defined(__MINGW32__) | |
235 | |
236 /* setitimer emulation for Win32 (see nt.c) */ | |
237 | |
238 struct itimerval | |
239 { | |
240 struct timeval it_value; | |
241 struct timeval it_interval; | |
242 }; | |
243 | |
244 int setitimer (int kind, const struct itimerval* itnew, | |
245 struct itimerval* itold); | |
246 | |
247 #define ITIMER_REAL 1 | |
248 #define ITIMER_PROF 2 | |
249 | |
250 #endif /* WINDOWSNT */ | |
251 | |
252 #endif /* _XEMACS_SYSTIME_H_ */ |