0
|
1 /* systime.h - System-dependent definitions for time manipulations.
|
|
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
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
|
|
9 later version.
|
|
10
|
|
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
|
|
14 for more details.
|
|
15
|
|
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. */
|
|
20
|
|
21 /* Synched up with: FSF 19.30. */
|
|
22
|
|
23 #ifndef _XEMACS_SYSTIME_H_
|
|
24 #define _XEMACS_SYSTIME_H_
|
|
25
|
|
26 #ifdef TIME_WITH_SYS_TIME
|
|
27 #include <sys/time.h>
|
|
28 #include <time.h>
|
|
29 #else
|
|
30 #ifdef HAVE_SYS_TIME_H
|
|
31 #include <sys/time.h>
|
|
32 #else
|
|
33 #include <time.h>
|
|
34 #endif
|
|
35 #endif
|
|
36
|
|
37 #ifdef HAVE_UTIME_H
|
|
38 # include <utime.h>
|
|
39 #endif
|
|
40
|
|
41 #ifdef HAVE_TZNAME
|
|
42 #ifndef tzname /* For SGI. */
|
|
43 extern char *tzname[]; /* RS6000 and others want it this way. */
|
|
44 #endif
|
|
45 #endif
|
|
46
|
|
47 /* SVr4 doesn't actually declare this in its #include files. */
|
|
48 #ifdef USG5_4
|
|
49 extern long timezone;
|
|
50 #endif
|
|
51
|
|
52 #ifdef VMS
|
|
53 #ifdef VAXC
|
|
54 #include "vmstime.h"
|
|
55 #endif
|
|
56 #endif
|
|
57
|
|
58 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
|
|
59 disagree about the name of the guard symbol. */
|
|
60 #ifdef HPUX
|
|
61 #ifdef _STRUCT_TIMEVAL
|
|
62 #ifndef __TIMEVAL__
|
|
63 #define __TIMEVAL__
|
|
64 #endif
|
|
65 #endif
|
|
66 #endif
|
|
67
|
|
68 /* EMACS_TIME is the type to use to represent temporal intervals.
|
|
69 At one point this was 'struct timeval' on some systems, int on others.
|
|
70 But this is stupid. Other things than select() code like to
|
|
71 manipulate time values, and so microsecond precision should be
|
|
72 maintained. Separate typedefs and conversion functions are provided
|
|
73 for select().
|
|
74
|
|
75 EMACS_SECS (TIME) is an rvalue for the seconds component of TIME.
|
|
76 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS.
|
|
77
|
|
78 EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME.
|
|
79 EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS.
|
|
80
|
|
81 Note that all times are returned in "normalized" format (i.e. the
|
|
82 usecs value is in the range 0 <= value < 1000000) and are assumed
|
|
83 to be passed in in this format.
|
|
84
|
|
85 EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME.
|
|
86
|
|
87 EMACS_GET_TIME (TIME) stores the current system time in TIME, which
|
|
88 should be an lvalue.
|
|
89
|
|
90 set_file_times (PATH, ATIME, MTIME) changes the last-access and
|
|
91 last-modification times of the file named PATH to ATIME and
|
|
92 MTIME, which are EMACS_TIMEs.
|
|
93
|
|
94 EMACS_NORMALIZE_TIME (TIME) coerces TIME into normalized format.
|
|
95
|
|
96 EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the
|
|
97 result in DEST. Either or both may be negative.
|
|
98
|
|
99 EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and
|
|
100 stores the result in DEST. Either or both may be negative.
|
|
101
|
|
102 EMACS_TIME_NEG_P (TIME) is true iff TIME is negative.
|
|
103
|
|
104 EMACS_TIME_EQUAL (TIME1, TIME2) is true iff TIME1 is the same as TIME2.
|
|
105 EMACS_TIME_GREATER (TIME1, TIME2) is true iff TIME1 is greater than
|
|
106 TIME2.
|
|
107 EMACS_TIME_EQUAL_OR_GREATER (TIME1, TIME2) is true iff TIME1 is
|
|
108 greater than or equal to TIME2.
|
|
109
|
|
110 */
|
|
111
|
|
112 #ifdef HAVE_TIMEVAL
|
|
113
|
|
114 #define EMACS_SELECT_TIME struct timeval
|
|
115 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) ((select_time) = (time))
|
|
116
|
|
117 #else /* not HAVE_TIMEVAL */
|
|
118
|
|
119 struct timeval
|
|
120 {
|
|
121 long tv_sec; /* seconds */
|
|
122 long tv_usec; /* microseconds */
|
|
123 };
|
|
124
|
|
125 #define EMACS_SELECT_TIME int
|
|
126 #define EMACS_TIME_TO_SELECT_TIME(time, select_time) \
|
|
127 EMACS_TIME_TO_INT (time, select_time)
|
|
128
|
|
129 #endif /* not HAVE_TIMEVAL */
|
|
130
|
|
131 #define EMACS_TIME_TO_INT(time, intvar) \
|
|
132 do { \
|
|
133 EMACS_TIME tmptime = time; \
|
|
134 \
|
|
135 if (tmptime.tv_usec > 0) \
|
|
136 (intvar) = tmptime.tv_sec + 1; \
|
|
137 else \
|
|
138 (intvar) = tmptime.tv_sec; \
|
|
139 } while (0)
|
|
140
|
|
141 #define EMACS_TIME struct timeval
|
|
142 #define EMACS_SECS(time) ((time).tv_sec + 0)
|
|
143 #define EMACS_USECS(time) ((time).tv_usec + 0)
|
|
144 #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds))
|
|
145 #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds))
|
|
146
|
|
147 #if !defined (HAVE_GETTIMEOFDAY)
|
|
148 struct timezone;
|
|
149 extern int gettimeofday (struct timeval *, struct timezone *);
|
|
150 #endif
|
|
151
|
|
152 /* On SVR4, the compiler may complain if given this extra BSD arg. */
|
|
153 #ifdef GETTIMEOFDAY_ONE_ARGUMENT
|
|
154 # ifdef SOLARIS2
|
|
155 /* Solaris (at least) omits this prototype. IRIX5 has it and chokes if we
|
|
156 declare it here. */
|
|
157 extern int gettimeofday (struct timeval *);
|
|
158 # endif
|
|
159 /* According to the Xt sources, some NTP daemons on some systems may
|
|
160 return non-normalized values. */
|
|
161 #define EMACS_GET_TIME(time) \
|
|
162 do { \
|
|
163 gettimeofday (&(time)); \
|
|
164 EMACS_NORMALIZE_TIME (time); \
|
|
165 } while (0)
|
|
166 #else /* not GETTIMEOFDAY_ONE_ARGUMENT */
|
|
167 # ifdef SOLARIS2
|
|
168 /* Solaris doesn't provide any prototype of this unless a bunch of
|
|
169 crap we don't define are defined. */
|
|
170 extern int gettimeofday (struct timeval *, void *dummy);
|
|
171 # endif
|
|
172 #define EMACS_GET_TIME(time) \
|
|
173 do { \
|
|
174 struct timezone dummy; \
|
|
175 gettimeofday (&(time), &dummy); \
|
|
176 EMACS_NORMALIZE_TIME (time); \
|
|
177 } while (0)
|
|
178 #endif /* not GETTIMEOFDAY_ONE_ARGUMENT */
|
|
179
|
|
180 #define EMACS_NORMALIZE_TIME(time) \
|
|
181 do { \
|
|
182 while ((time).tv_usec >= 1000000) \
|
|
183 { \
|
|
184 (time).tv_usec -= 1000000; \
|
|
185 (time).tv_sec++; \
|
|
186 } \
|
|
187 while ((time).tv_usec < 0) \
|
|
188 { \
|
|
189 (time).tv_usec += 1000000; \
|
|
190 (time).tv_sec--; \
|
|
191 } \
|
|
192 } while (0)
|
|
193
|
|
194 #define EMACS_ADD_TIME(dest, src1, src2) \
|
|
195 do { \
|
|
196 (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
|
|
197 (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \
|
|
198 EMACS_NORMALIZE_TIME (dest); \
|
|
199 } while (0)
|
|
200
|
|
201 #define EMACS_SUB_TIME(dest, src1, src2) \
|
|
202 do { \
|
|
203 (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
|
|
204 (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \
|
|
205 EMACS_NORMALIZE_TIME (dest); \
|
|
206 } while (0)
|
|
207
|
|
208 #define EMACS_TIME_NEG_P(time) ((long)(time).tv_sec < 0)
|
|
209
|
|
210 #define EMACS_TIME_EQUAL(time1, time2) \
|
|
211 ((time1).tv_sec == (time2).tv_sec && \
|
|
212 (time1).tv_usec == (time2).tv_usec)
|
|
213
|
|
214 #define EMACS_TIME_GREATER(time1, time2) \
|
|
215 ((time1).tv_sec > (time2).tv_sec || \
|
|
216 ((time1).tv_sec == (time2).tv_sec && \
|
|
217 (time1).tv_usec > (time2).tv_usec))
|
|
218
|
|
219 #define EMACS_TIME_EQUAL_OR_GREATER(time1, time2) \
|
|
220 ((time1).tv_sec > (time2).tv_sec || \
|
|
221 ((time1).tv_sec == (time2).tv_sec && \
|
|
222 (time1).tv_usec >= (time2).tv_usec))
|
|
223
|
|
224 #define EMACS_SET_SECS_USECS(time, secs, usecs) \
|
|
225 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs))
|
|
226
|
|
227 extern int set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime);
|
|
228
|
|
229 extern void get_process_times (double *user_time, double *system_time,
|
|
230 double *real_time);
|
|
231
|
|
232 #endif /* _XEMACS_SYSTIME_H_ */
|