1 /* systime.h - System-dependent definitions for time manipulations.
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of XEmacs.
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
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
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. */
21 /* Synched up with: FSF 19.30. */
23 #ifndef INCLUDED_systime_h_
24 #define INCLUDED_systime_h_
26 #ifdef TIME_WITH_SYS_TIME
27 # include <sys/time.h>
30 # ifdef HAVE_SYS_TIME_H
31 # include <sys/time.h>
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. */
46 /* This defines struct timeval */
51 int tz_minuteswest; /* minutes west of Greenwich */
52 int tz_dsttime; /* type of dst correction */
56 /* Provides gettimeofday etc */
57 #include <X11/Xw32defs.h>
60 /* X11R6 on NT provides the single parameter version of this command */
61 void gettimeofday (struct timeval *, struct timezone *);
62 #endif /* HAVE_X_WINDOWS */
64 #endif /* WIN32_NATIVE */
73 # include <sys/utime.h>
76 #if defined(HAVE_TZNAME) && !defined(WIN32_NATIVE) && !defined(CYGWIN)
77 #ifndef tzname /* For SGI. */
78 extern char *tzname[]; /* RS6000 and others want it this way. */
82 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
83 disagree about the name of the guard symbol. */
85 #ifdef _STRUCT_TIMEVAL
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
99 EMACS_SECS (TIME) is an rvalue for the seconds component of TIME.
100 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS.
102 EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME.
103 EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS.
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.
109 EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME.
111 EMACS_GET_TIME (TIME) stores the current system time in TIME, which
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.
118 EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format.
120 EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the
121 result in DEST. Either or both may be negative.
123 EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and
124 stores the result in DEST. Either or both may be negative.
126 EMACS_TIME_NEG_P (TIME) is true iff TIME is negative.
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
131 EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is
132 greater than or equal to TIME2.
138 #define EMACS_SELECT_TIME struct timeval
139 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time))
141 #else /* not HAVE_TIMEVAL */
145 long tv_sec; /* seconds */
146 long tv_usec; /* microseconds */
149 #define EMACS_SELECT_TIME int
150 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \
151 EMACS_TIME_TO_INT (time, select_time)
153 #endif /* not HAVE_TIMEVAL */
155 #define EMACS_TIME_TO_INT(time, intvar) \
157 EMACS_TIME tmptime = time; \
159 if (tmptime.tv_usec > 0) \
160 (intvar) = tmptime.tv_sec + 1; \
162 (intvar) = tmptime.tv_sec; \
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))
171 #if !defined (HAVE_GETTIMEOFDAY)
172 int gettimeofday (struct timeval *, void *);
175 /* On SVR4, the compiler may complain if given this extra BSD arg. */
176 #ifdef GETTIMEOFDAY_ONE_ARGUMENT
177 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time)
179 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time,0)
182 /* According to the Xt sources, some NTP daemons on some systems may
183 return non-normalized values. */
184 #define EMACS_GET_TIME(time) \
186 EMACS_GETTIMEOFDAY (&(time)); \
187 EMACS_NORMALIZE_TIME (time); \
190 #define EMACS_NORMALIZE_TIME(time) \
192 while ((time).tv_usec >= 1000000) \
194 (time).tv_usec -= 1000000; \
197 while ((time).tv_usec < 0) \
199 (time).tv_usec += 1000000; \
204 #define EMACS_ADD_TIME(dest, src1, src2) \
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); \
211 #define EMACS_SUB_TIME(dest, src1, src2) \
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); \
218 #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0)
220 #define EMACS_TIME_EQUAL(time1, time2) \
221 ((time1).tv_sec == (time2).tv_sec && \
222 (time1).tv_usec == (time2).tv_usec)
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))
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))
234 #define EMACS_SET_SECS_USECS(time, secs, usecs) \
235 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
238 int set_file_times (Lisp_Object path, EMACS_TIME atime, EMACS_TIME mtime);
241 void get_process_times (double *user_time, double *system_time,
244 #if defined(WIN32_NATIVE) || defined(BROKEN_CYGWIN)
246 /* setitimer emulation for Win32 (see nt.c) */
250 struct timeval it_value;
251 struct timeval it_interval;
254 #define ITIMER_REAL 1
255 #define ITIMER_PROF 2
257 #endif /* WIN32_NATIVE || BROKEN_CYGWIN */
259 #if defined (WIN32_NATIVE) || defined (CYGWIN)
261 int mswindows_setitimer (int kind, const struct itimerval *itnew,
262 struct itimerval *itold);
264 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN) */
266 /* #### Move this comment elsewhere when we figure out the place.
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.
276 By making the encapsulation explicit we might be making the code
277 that uses is slightly less pretty, but this is more than compensated
278 for by the huge increase in clarity.
280 "Standard library function" can refer to any function in any
281 standard library. If we are explicitly changing the semantics
282 (e.g. Mule-encapsulating), we should use an extended version of
283 the prefix, e.g. perhaps "qxe_xlat_" for functions that Mule-
284 encapsulate, or "qxe_retry_" for functions that automatically
285 retry a system call interrupted by EINTR. In general, if there
286 is no prefix extension, it means the function is trying to
287 provide (more or less) the same semantics as the standard library
288 function; but be aware that the reimplementation may be incomplete
289 or differ in important respects. This is especially the case
290 when attempts are made to implement Unix functions on MS Windows.
293 int qxe_setitimer (int kind, const struct itimerval *itnew,
294 struct itimerval *itold);
296 #endif /* INCLUDED_systime_h_ */