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 */
70 #if defined(HAVE_TZNAME) && !defined(WIN32_NATIVE) && !defined(CYGWIN)
71 #ifndef tzname /* For SGI. */
72 extern char *tzname[]; /* RS6000 and others want it this way. */
76 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
77 disagree about the name of the guard symbol. */
79 #ifdef _STRUCT_TIMEVAL
86 /* EMACS_TIME is the type to use to represent temporal intervals.
87 At one point this was 'struct timeval' on some systems, int on others.
88 But this is stupid. Other things than select() code like to
89 manipulate time values, and so microsecond precision should be
90 maintained. Separate typedefs and conversion functions are provided
93 EMACS_SECS (TIME) is an rvalue for the seconds component of TIME.
94 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS.
96 EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME.
97 EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS.
99 Note that all times are returned in "normalized" format (i.e. the
100 usecs value is in the range 0 <= value < 1000000) and are assumed
101 to be passed in in this format.
103 EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME.
105 EMACS_GET_TIME (TIME) stores the current system time in TIME, which
108 set_file_times (PATH, ATIME, MTIME) changes the last-access and
109 last-modification times of the file named PATH to ATIME and
110 MTIME, which are EMACS_TIMEs.
112 EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format.
114 EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the
115 result in DEST. Either or both may be negative.
117 EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and
118 stores the result in DEST. Either or both may be negative.
120 EMACS_TIME_NEG_P (TIME) is true iff TIME is negative.
122 EMACS_TIME_EQUAL (TIME1, TIME2) is true iff TIME1 is the same as TIME2.
123 EMACS_TIME_GREATER (TIME1, TIME2) is true iff TIME1 is greater than
125 EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is
126 greater than or equal to TIME2.
132 #define EMACS_SELECT_TIME struct timeval
133 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time))
135 #else /* not HAVE_TIMEVAL */
139 long tv_sec; /* seconds */
140 long tv_usec; /* microseconds */
143 #define EMACS_SELECT_TIME int
144 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \
145 EMACS_TIME_TO_INT (time, select_time)
147 #endif /* not HAVE_TIMEVAL */
149 #define EMACS_TIME_TO_INT(time, intvar) \
151 EMACS_TIME tmptime = time; \
153 if (tmptime.tv_usec > 0) \
154 (intvar) = tmptime.tv_sec + 1; \
156 (intvar) = tmptime.tv_sec; \
159 #define EMACS_TIME struct timeval
160 #define EMACS_SECS(time) ((time).tv_sec + 0)
161 #define EMACS_USECS(time) ((time).tv_usec + 0)
162 #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds))
163 #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds))
165 #if !defined (HAVE_GETTIMEOFDAY)
166 int gettimeofday (struct timeval *, void *);
169 /* On SVR4, the compiler may complain if given this extra BSD arg. */
170 #ifdef GETTIMEOFDAY_ONE_ARGUMENT
171 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time)
173 #define EMACS_GETTIMEOFDAY(time) gettimeofday(time,0)
176 /* According to the Xt sources, some NTP daemons on some systems may
177 return non-normalized values. */
178 #define EMACS_GET_TIME(time) \
180 EMACS_GETTIMEOFDAY (&(time)); \
181 EMACS_NORMALIZE_TIME (time); \
184 #define EMACS_NORMALIZE_TIME(time) \
186 while ((time).tv_usec >= 1000000) \
188 (time).tv_usec -= 1000000; \
191 while ((time).tv_usec < 0) \
193 (time).tv_usec += 1000000; \
198 #define EMACS_ADD_TIME(dest, src1, src2) \
200 (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
201 (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \
202 EMACS_NORMALIZE_TIME (dest); \
205 #define EMACS_SUB_TIME(dest, src1, src2) \
207 (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
208 (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \
209 EMACS_NORMALIZE_TIME (dest); \
212 #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0)
214 #define EMACS_TIME_EQUAL(time1, time2) \
215 ((time1).tv_sec == (time2).tv_sec && \
216 (time1).tv_usec == (time2).tv_usec)
218 #define EMACS_TIME_GREATER(time1, time2) \
219 ((time1).tv_sec > (time2).tv_sec || \
220 ((time1).tv_sec == (time2).tv_sec && \
221 (time1).tv_usec > (time2).tv_usec))
223 #define EMACS_TIME_EQUAL_OR_GREATER(time1, time2) \
224 ((time1).tv_sec > (time2).tv_sec || \
225 ((time1).tv_sec == (time2).tv_sec && \
226 (time1).tv_usec >= (time2).tv_usec))
228 #define EMACS_SET_SECS_USECS(time, secs, usecs) \
229 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
231 int set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime);
233 void get_process_times (double *user_time, double *system_time,
236 #if defined(WIN32_NATIVE) || defined(BROKEN_CYGWIN)
238 /* setitimer emulation for Win32 (see nt.c) */
242 struct timeval it_value;
243 struct timeval it_interval;
246 int setitimer (int kind, const struct itimerval* itnew,
247 struct itimerval* itold);
249 #define ITIMER_REAL 1
250 #define ITIMER_PROF 2
252 #endif /* WIN32_NATIVE */
254 #endif /* INCLUDED_systime_h_ */