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 SXEmacs
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Synched up with: FSF 19.30. */
22 #ifndef INCLUDED_systime_h_
23 #define INCLUDED_systime_h_
25 #ifdef TIME_WITH_SYS_TIME
26 # include <sys/time.h>
29 # ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
36 /* select() is supposed to be (Unix98) defined in sys/time.h,
37 but FreeBSD and Irix 5 put it in unistd.h instead.
38 If we have it, including it can't hurt. */
50 #if defined(HAVE_TZNAME)
51 #ifndef tzname /* For SGI. */
52 extern char *tzname[]; /* RS6000 and others want it this way. */
56 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
57 disagree about the name of the guard symbol. */
59 #ifdef _STRUCT_TIMEVAL
66 /* EMACS_TIME is the type to use to represent temporal intervals.
67 At one point this was 'struct timeval' on some systems, int on others.
68 But this is stupid. Other things than select() code like to
69 manipulate time values, and so microsecond precision should be
70 maintained. Separate typedefs and conversion functions are provided
73 EMACS_SECS (TIME) is an rvalue for the seconds component of TIME.
74 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS.
76 EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME.
77 EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS.
79 Note that all times are returned in "normalized" format (i.e. the
80 usecs value is in the range 0 <= value < 1000000) and are assumed
81 to be passed in in this format.
83 EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME.
85 EMACS_GET_TIME (TIME) stores the current system time in TIME, which
88 set_file_times (PATH, ATIME, MTIME) changes the last-access and
89 last-modification times of the file named PATH to ATIME and
90 MTIME, which are EMACS_TIMEs.
92 EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format.
94 EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the
95 result in DEST. Either or both may be negative.
97 EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and
98 stores the result in DEST. Either or both may be negative.
100 EMACS_TIME_NEG_P (TIME) is true iff TIME is negative.
102 EMACS_TIME_EQUAL (TIME1, TIME2) is true iff TIME1 is the same as TIME2.
103 EMACS_TIME_GREATER (TIME1, TIME2) is true iff TIME1 is greater than
105 EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is
106 greater than or equal to TIME2.
112 #define EMACS_SELECT_TIME struct timeval
113 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time))
115 #else /* not HAVE_TIMEVAL */
118 long tv_sec; /* seconds */
119 long tv_usec; /* microseconds */
122 #define EMACS_SELECT_TIME int
123 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \
124 EMACS_TIME_TO_INT (time, select_time)
126 #endif /* not HAVE_TIMEVAL */
128 #define EMACS_TIME_TO_INT(time, intvar) \
130 EMACS_TIME tmptime = time; \
132 if (tmptime.tv_usec > 0) \
133 (intvar) = tmptime.tv_sec + 1; \
135 (intvar) = tmptime.tv_sec; \
138 #define EMACS_TIME struct timeval
139 #define EMACS_SECS(time) ((time).tv_sec + 0)
140 #define EMACS_USECS(time) ((time).tv_usec + 0)
141 #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds))
142 #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds))
144 #if !defined (HAVE_GETTIMEOFDAY)
145 int gettimeofday(struct timeval *, void *);
148 /* On SVR4, the compiler may complain if given this extra BSD arg. */
149 #ifdef GETTIMEOFDAY_ONE_ARGUMENT
150 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time)
152 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time,0)
155 /* According to the Xt sources, some NTP daemons on some systems may
156 return non-normalized values. */
157 #define EMACS_GET_TIME(time) \
159 EMACS_GETTIMEOFDAY (&(time)); \
160 EMACS_NORMALIZE_TIME (time); \
163 #define EMACS_NORMALIZE_TIME(time) \
165 while ((time).tv_usec >= 1000000) \
167 (time).tv_usec -= 1000000; \
170 while ((time).tv_usec < 0) \
172 (time).tv_usec += 1000000; \
177 #define EMACS_ADD_TIME(dest, src1, src2) \
179 (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
180 (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \
181 EMACS_NORMALIZE_TIME (dest); \
184 #define EMACS_SUB_TIME(dest, src1, src2) \
186 (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
187 (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \
188 EMACS_NORMALIZE_TIME (dest); \
191 #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0)
193 #define EMACS_TIME_EQUAL(time1, time2) \
194 ((time1).tv_sec == (time2).tv_sec && \
195 (time1).tv_usec == (time2).tv_usec)
197 #define EMACS_TIME_GREATER(time1, time2) \
198 ((time1).tv_sec > (time2).tv_sec || \
199 ((time1).tv_sec == (time2).tv_sec && \
200 (time1).tv_usec > (time2).tv_usec))
202 #define EMACS_TIME_EQUAL_OR_GREATER(time1, time2) \
203 ((time1).tv_sec > (time2).tv_sec || \
204 ((time1).tv_sec == (time2).tv_sec && \
205 (time1).tv_usec >= (time2).tv_usec))
207 #define EMACS_SET_SECS_USECS(time, secs, usecs) \
208 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
211 int set_file_times(Lisp_Object path, EMACS_TIME atime, EMACS_TIME mtime);
214 void get_process_times(double *user_time, double *system_time,
218 /* #### Move this comment elsewhere when we figure out the place.
220 "qxe" is a unique prefix used to identify encapsulations of standard
221 library functions. We used to play pre-processing games but in
222 general this leads to nothing but trouble because someone first
223 encountering the code will have no idea that what appears to be a
224 call to a library function has actually been redefined to be a call
225 somewhere else. This is doubly true when the redefinition occurs
226 in out-of-the way s+m files and only on certainly systems.
228 By making the encapsulation explicit we might be making the code
229 that uses is slightly less pretty, but this is more than compensated
230 for by the huge increase in clarity.
232 "Standard library function" can refer to any function in any
233 standard library. If we are explicitly changing the semantics
234 (e.g. Mule-encapsulating), we should use an extended version of
235 the prefix, e.g. perhaps "qxe_xlat_" for functions that Mule-
236 encapsulate, or "qxe_retry_" for functions that automatically
237 retry a system call interrupted by EINTR. In general, if there
238 is no prefix extension, it means the function is trying to
239 provide (more or less) the same semantics as the standard library
240 function; but be aware that the reimplementation may be incomplete
241 or differ in important respects. This is especially the case
242 when attempts are made to implement Unix functions on MS Windows.
245 int qxe_setitimer(int kind, const struct itimerval *itnew,
246 struct itimerval *itold);
248 #endif /* INCLUDED_systime_h_ */