Commit | Line | Data |
---|---|---|
10a4cc63 | 1 | /* systime.h - System-dependent definitions for time manipulations. |
3a22ee35 | 2 | Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
f469625a JB |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
6 | GNU Emacs 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 1, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU Emacs 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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Emacs; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
d712c26d | 20 | #ifdef TIME_WITH_SYS_TIME |
7b89707c | 21 | #include <sys/time.h> |
f469625a | 22 | #include <time.h> |
d712c26d | 23 | #else |
5cbdb356 JB |
24 | #ifdef HAVE_SYS_TIME_H |
25 | #include <sys/time.h> | |
d712c26d JB |
26 | #else |
27 | #include <time.h> | |
98f77753 | 28 | #endif |
b7cceaf1 | 29 | #endif |
c0c45059 KH |
30 | #ifdef HAVE_UTIME_H |
31 | #include <utime.h> | |
32 | #endif | |
7b89707c | 33 | |
2ffe7ef2 RS |
34 | #ifdef HAVE_TZNAME |
35 | #ifndef tzname /* For SGI. */ | |
36 | extern char *tzname[]; /* RS6000 and others want it this way. */ | |
37 | #endif | |
38 | #endif | |
39 | ||
9e70858b JB |
40 | /* SVr4 doesn't actually declare this in its #include files. */ |
41 | #ifdef USG5_4 | |
42 | extern long timezone; | |
43 | #endif | |
44 | ||
210b2b4f JB |
45 | #ifdef VMS |
46 | #ifdef VAXC | |
47 | #include "vmstime.h" | |
48 | #endif | |
49 | #endif | |
50 | ||
71068d78 KH |
51 | /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h |
52 | disagree about the name of the guard symbol. */ | |
c810639a | 53 | #ifdef HPUX |
71068d78 KH |
54 | #ifdef _STRUCT_TIMEVAL |
55 | #ifndef __TIMEVAL__ | |
56 | #define __TIMEVAL__ | |
57 | #endif | |
58 | #endif | |
c810639a | 59 | #endif |
10a4cc63 | 60 | \f |
f469625a JB |
61 | /* EMACS_TIME is the type to use to represent temporal intervals - |
62 | struct timeval on some systems, int on others. It can be passed as | |
88729235 | 63 | the timeout argument to the select system call. |
f469625a JB |
64 | |
65 | EMACS_SECS (TIME) is an rvalue for the seconds component of TIME. | |
66 | EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS. | |
67 | ||
68 | EMACS_HAS_USECS is defined iff EMACS_TIME has a usecs component. | |
7f86bdac JB |
69 | EMACS_USECS (TIME) is an rvalue for the microseconds component of TIME. |
70 | This returns zero if EMACS_TIME doesn't have a microseconds component. | |
71 | EMACS_SET_USECS (TIME, MICROSECONDS) sets that to MICROSECONDS. | |
72 | This does nothing if EMACS_TIME doesn't have a microseconds component. | |
f469625a JB |
73 | |
74 | EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME. | |
75 | ||
76 | EMACS_GET_TIME (TIME) stores the current system time in TIME, which | |
77 | should be an lvalue. | |
f469625a JB |
78 | |
79 | EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the | |
80 | result in DEST. SRC should not be negative. | |
81 | ||
82 | EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and | |
83 | stores the result in DEST. SRC should not be negative. | |
84 | EMACS_TIME_NEG_P (TIME) is true iff TIME is negative. | |
85 | ||
86 | */ | |
87 | ||
88 | #ifdef HAVE_TIMEVAL | |
89 | ||
722687f5 JB |
90 | #define EMACS_HAS_USECS |
91 | ||
f469625a JB |
92 | #define EMACS_TIME struct timeval |
93 | #define EMACS_SECS(time) ((time).tv_sec + 0) | |
94 | #define EMACS_USECS(time) ((time).tv_usec + 0) | |
95 | #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds)) | |
7f86bdac | 96 | #define EMACS_SET_USECS(time, microseconds) ((time).tv_usec = (microseconds)) |
f469625a | 97 | |
4fb83f3c | 98 | /* On SVR4, the compiler may complain if given this extra BSD arg. */ |
af57e5a7 | 99 | #ifdef GETTIMEOFDAY_ONE_ARGUMENT |
4fb83f3c RS |
100 | #define EMACS_GET_TIME(time) \ |
101 | { \ | |
102 | gettimeofday (&(time)); \ | |
103 | } | |
af57e5a7 | 104 | #else /* not GETTIMEOFDAY_ONE_ARGUMENT */ |
f469625a JB |
105 | #define EMACS_GET_TIME(time) \ |
106 | { \ | |
10a4cc63 | 107 | struct timezone dummy; \ |
f469625a JB |
108 | gettimeofday (&(time), &dummy); \ |
109 | } | |
af57e5a7 | 110 | #endif /* not GETTIMEOFDAY_ONE_ARGUMENT */ |
f469625a JB |
111 | |
112 | #define EMACS_ADD_TIME(dest, src1, src2) \ | |
113 | { \ | |
114 | (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \ | |
115 | (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \ | |
116 | if ((dest).tv_usec > 1000000) \ | |
117 | (dest).tv_usec -= 1000000, (dest).tv_sec++; \ | |
118 | } | |
119 | ||
120 | #define EMACS_SUB_TIME(dest, src1, src2) \ | |
121 | { \ | |
122 | (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \ | |
123 | (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \ | |
124 | if ((dest).tv_usec < 0) \ | |
125 | (dest).tv_usec += 1000000, (dest).tv_sec--; \ | |
126 | } | |
127 | ||
128 | #define EMACS_TIME_NEG_P(time) \ | |
cf4138ad | 129 | ((long)(time).tv_sec < 0 \ |
f469625a | 130 | || ((time).tv_sec == 0 \ |
cf4138ad | 131 | && (long)(time).tv_usec < 0)) |
f469625a | 132 | |
10a4cc63 | 133 | #else /* ! defined (HAVE_TIMEVAL) */ |
f469625a JB |
134 | |
135 | #define EMACS_TIME int | |
136 | #define EMACS_SECS(time) (time) | |
ef15f270 | 137 | #define EMACS_USECS(time) 0 |
f469625a | 138 | #define EMACS_SET_SECS(time, seconds) ((time) = (seconds)) |
ef15f270 | 139 | #define EMACS_SET_USECS(time, usecs) 0 |
f469625a JB |
140 | |
141 | #define EMACS_GET_TIME(t) ((t) = time ((long *) 0)) | |
142 | #define EMACS_ADD_TIME(dest, src1, src2) ((dest) = (src1) + (src2)) | |
143 | #define EMACS_SUB_TIME(dest, src1, src2) ((dest) = (src1) - (src2)) | |
144 | #define EMACS_TIME_NEG_P(t) ((t) < 0) | |
145 | ||
10a4cc63 | 146 | #endif /* ! defined (HAVE_TIMEVAL) */ |
f469625a JB |
147 | |
148 | #define EMACS_SET_SECS_USECS(time, secs, usecs) \ | |
149 | (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs)) | |
150 | ||
c0c45059 | 151 | extern int set_file_times (); |