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 _XEMACS_SYSTIME_H_
24 #define _XEMACS_SYSTIME_H_
26 #ifdef TIME_WITH_SYS_TIME
30 #ifdef HAVE_SYS_TIME_H
37 #if defined(WINDOWSNT) && defined(HAVE_X_WINDOWS)
38 /* Provides gettimeofday etc */
39 #include <X11/Xw32defs.h>
48 #ifndef tzname /* For SGI. */
49 extern char *tzname[]; /* RS6000 and others want it this way. */
53 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
54 disagree about the name of the guard symbol. */
56 #ifdef _STRUCT_TIMEVAL
63 /* EMACS_TIME is the type to use to represent temporal intervals.
64 At one point this was 'struct timeval' on some systems, int on others.
65 But this is stupid. Other things than select() code like to
66 manipulate time values, and so microsecond precision should be
67 maintained. Separate typedefs and conversion functions are provided
70 EMACS_SECS (TIME) is an rvalue for the seconds component of TIME.
71 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS.
73 EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME.
74 EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS.
76 Note that all times are returned in "normalized" format (i.e. the
77 usecs value is in the range 0 <= value < 1000000) and are assumed
78 to be passed in in this format.
80 EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME.
82 EMACS_GET_TIME (TIME) stores the current system time in TIME, which
85 set_file_times (PATH, ATIME, MTIME) changes the last-access and
86 last-modification times of the file named PATH to ATIME and
87 MTIME, which are EMACS_TIMEs.
89 EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format.
91 EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the
92 result in DEST. Either or both may be negative.
94 EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and
95 stores the result in DEST. Either or both may be negative.
97 EMACS_TIME_NEG_P (TIME) is true iff TIME is negative.
99 EMACS_TIME_EQUAL (TIME1, TIME2) is true iff TIME1 is the same as TIME2.
100 EMACS_TIME_GREATER (TIME1, TIME2) is true iff TIME1 is greater than
102 EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is
103 greater than or equal to TIME2.
109 #define EMACS_SELECT_TIME struct timeval
110 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time))
112 #else /* not HAVE_TIMEVAL */
116 long tv_sec; /* seconds */
117 long tv_usec; /* microseconds */
120 #define EMACS_SELECT_TIME int
121 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \
122 EMACS_TIME_TO_INT (time, select_time)
124 #endif /* not HAVE_TIMEVAL */
126 #define EMACS_TIME_TO_INT(time, intvar) \
128 EMACS_TIME tmptime = time; \
130 if (tmptime.tv_usec > 0) \
131 (intvar) = tmptime.tv_sec + 1; \
133 (intvar) = tmptime.tv_sec; \
136 #define EMACS_TIME struct timeval
137 #define EMACS_SECS(time) ((time).tv_sec + 0)
138 #define EMACS_USECS(time) ((time).tv_usec + 0)
139 #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds))
140 #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds))
142 #if !defined (HAVE_GETTIMEOFDAY)
144 int gettimeofday (struct timeval *, struct timezone *);
147 /* On SVR4, the compiler may complain if given this extra BSD arg. */
148 #ifdef GETTIMEOFDAY_ONE_ARGUMENT
150 /* Solaris (at least) omits this prototype. IRIX5 has it and chokes if we
152 int gettimeofday (struct timeval *);
154 /* According to the Xt sources, some NTP daemons on some systems may
155 return non-normalized values. */
156 #define EMACS_GET_TIME(time) \
158 gettimeofday (&(time)); \
159 EMACS_NORMALIZE_TIME (time); \
161 #else /* not GETTIMEOFDAY_ONE_ARGUMENT */
163 /* Solaris doesn't provide any prototype of this unless a bunch of
164 crap we don't define are defined. */
165 int gettimeofday (struct timeval *, void *dummy);
167 #define EMACS_GET_TIME(time) \
169 struct timezone dummy; \
170 gettimeofday (&(time), &dummy); \
171 EMACS_NORMALIZE_TIME (time); \
173 #endif /* not GETTIMEOFDAY_ONE_ARGUMENT */
175 #define EMACS_NORMALIZE_TIME(time) \
177 while ((time).tv_usec >= 1000000) \
179 (time).tv_usec -= 1000000; \
182 while ((time).tv_usec < 0) \
184 (time).tv_usec += 1000000; \
189 #define EMACS_ADD_TIME(dest, src1, src2) \
191 (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
192 (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \
193 EMACS_NORMALIZE_TIME (dest); \
196 #define EMACS_SUB_TIME(dest, src1, src2) \
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); \
203 #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0)
205 #define EMACS_TIME_EQUAL(time1, time2) \
206 ((time1).tv_sec == (time2).tv_sec && \
207 (time1).tv_usec == (time2).tv_usec)
209 #define EMACS_TIME_GREATER(time1, time2) \
210 ((time1).tv_sec > (time2).tv_sec || \
211 ((time1).tv_sec == (time2).tv_sec && \
212 (time1).tv_usec > (time2).tv_usec))
214 #define EMACS_TIME_EQUAL_OR_GREATER(time1, time2) \
215 ((time1).tv_sec > (time2).tv_sec || \
216 ((time1).tv_sec == (time2).tv_sec && \
217 (time1).tv_usec >= (time2).tv_usec))
219 #define EMACS_SET_SECS_USECS(time, secs, usecs) \
220 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
222 int set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime);
224 void get_process_times (double *user_time, double *system_time,
227 #if defined(WINDOWSNT) || defined(BROKEN_CYGWIN)
229 /* setitimer emulation for Win32 (see nt.c) */
233 struct timeval it_value;
234 struct timeval it_interval;
237 int setitimer (int kind, const struct itimerval* itnew,
238 struct itimerval* itold);
240 #define ITIMER_REAL 1
241 #define ITIMER_PROF 2
243 #endif /* WINDOWSNT */
245 #endif /* _XEMACS_SYSTIME_H_ */