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 int setitimer (int kind, const struct itimerval* itnew,
255 struct itimerval* itold);
257 #define ITIMER_REAL 1
258 #define ITIMER_PROF 2
260 #endif /* WIN32_NATIVE */
262 #endif /* INCLUDED_systime_h_ */