diff options
| author | Jim Blandy | 1992-08-12 15:16:36 +0000 |
|---|---|---|
| committer | Jim Blandy | 1992-08-12 15:16:36 +0000 |
| commit | f469625ab752df672f5009f578aea9c3a4afc5ff (patch) | |
| tree | 48ba931e556c7c4e66565d8b2061bc41652f3fa1 /src | |
| parent | b1c884c393f1a1bd4aa3e8594dd569bab58324c7 (diff) | |
| download | emacs-f469625ab752df672f5009f578aea9c3a4afc5ff.tar.gz emacs-f469625ab752df672f5009f578aea9c3a4afc5ff.zip | |
Initial revision
Diffstat (limited to 'src')
| -rw-r--r-- | src/systime.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/systime.h b/src/systime.h new file mode 100644 index 00000000000..38902ef62e6 --- /dev/null +++ b/src/systime.h | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | /* systerm.h - System-dependent definitions for time manipulations. | ||
| 2 | Copyright (C) 1992 Free Software Foundation, Inc. | ||
| 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 | |||
| 20 | #ifdef NEED_TIME_H | ||
| 21 | |||
| 22 | /* _h_BSDTYPES is checked because on ISC unix, socket.h includes | ||
| 23 | both time.h and sys/time.h, and the later file is protected | ||
| 24 | from repeated inclusion. We just hope that other systems will | ||
| 25 | use this guard either not at all, or similarly. */ | ||
| 26 | #ifndef _h_BSDTYPES | ||
| 27 | #include <time.h> | ||
| 28 | #endif | ||
| 29 | #else /* not NEED_TIME_H */ | ||
| 30 | #ifdef HAVE_TIMEVAL | ||
| 31 | #include <sys/time.h> | ||
| 32 | #endif /* HAVE_TIMEVAL */ | ||
| 33 | #endif /* not NEED_TIME_H */ | ||
| 34 | |||
| 35 | /* EMACS_TIME is the type to use to represent temporal intervals - | ||
| 36 | struct timeval on some systems, int on others. It can be passed as | ||
| 37 | the timeout argument to the select () system call. | ||
| 38 | |||
| 39 | EMACS_SECS (TIME) is an rvalue for the seconds component of TIME. | ||
| 40 | EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS. | ||
| 41 | |||
| 42 | EMACS_HAS_USECS is defined iff EMACS_TIME has a usecs component. | ||
| 43 | EMACS_USECS (TIME) is an rvalue for the milliseconds component of TIME. | ||
| 44 | This returns zero if EMACS_TIME doesn't have a milliseconds component. | ||
| 45 | EMACS_SET_USECS (TIME, MILLISECONDS) sets that to MILLISECONDS. | ||
| 46 | This does nothing if EMACS_TIME doesn't have a milliseconds component. | ||
| 47 | |||
| 48 | EMACS_SET_SECS_USECS (TIME, SECS, USECS) sets both components of TIME. | ||
| 49 | |||
| 50 | EMACS_GET_TIME (TIME) stores the current system time in TIME, which | ||
| 51 | should be an lvalue. | ||
| 52 | EMACS_SET_UTIMES (PATH, ATIME, MTIME) changes the last-access and | ||
| 53 | last-modification times of the file named PATH to ATIME and | ||
| 54 | MTIME, which are EMACS_TIMEs. | ||
| 55 | |||
| 56 | EMACS_ADD_TIME (DEST, SRC1, SRC2) adds SRC1 to SRC2 and stores the | ||
| 57 | result in DEST. SRC should not be negative. | ||
| 58 | |||
| 59 | EMACS_SUB_TIME (DEST, SRC1, SRC2) subtracts SRC2 from SRC1 and | ||
| 60 | stores the result in DEST. SRC should not be negative. | ||
| 61 | EMACS_TIME_NEG_P (TIME) is true iff TIME is negative. | ||
| 62 | |||
| 63 | */ | ||
| 64 | |||
| 65 | #ifdef HAVE_TIMEVAL | ||
| 66 | |||
| 67 | #define EMACS_TIME struct timeval | ||
| 68 | #define EMACS_SECS(time) ((time).tv_sec + 0) | ||
| 69 | #define EMACS_USECS(time) ((time).tv_usec + 0) | ||
| 70 | #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds)) | ||
| 71 | #define EMACS_SET_USECS(time, milliseconds) ((time).tv_usec = (milliseconds)) | ||
| 72 | |||
| 73 | #define EMACS_GET_TIME(time) \ | ||
| 74 | { \ | ||
| 75 | EMACS_TIME dummy; \ | ||
| 76 | gettimeofday (&(time), &dummy); \ | ||
| 77 | } | ||
| 78 | |||
| 79 | #define EMACS_ADD_TIME(dest, src1, src2) \ | ||
| 80 | { \ | ||
| 81 | (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \ | ||
| 82 | (dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \ | ||
| 83 | if ((dest).tv_usec > 1000000) \ | ||
| 84 | (dest).tv_usec -= 1000000, (dest).tv_sec++; \ | ||
| 85 | } | ||
| 86 | |||
| 87 | #define EMACS_SUB_TIME(dest, src1, src2) \ | ||
| 88 | { \ | ||
| 89 | (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \ | ||
| 90 | (dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \ | ||
| 91 | if ((dest).tv_usec < 0) \ | ||
| 92 | (dest).tv_usec += 1000000, (dest).tv_sec--; \ | ||
| 93 | } | ||
| 94 | |||
| 95 | #define EMACS_TIME_NEG_P(time) \ | ||
| 96 | ((time).tv_sec < 0 \ | ||
| 97 | || ((time).tv_sec == 0 \ | ||
| 98 | && (time).tv_usec < 0)) | ||
| 99 | |||
| 100 | #else /* not def HAVE_TIMEVAL */ | ||
| 101 | |||
| 102 | #define EMACS_TIME int | ||
| 103 | #define EMACS_SECS(time) (time) | ||
| 104 | #define EMACS_SET_SECS(time, seconds) ((time) = (seconds)) | ||
| 105 | |||
| 106 | #define EMACS_GET_TIME(t) ((t) = time ((long *) 0)) | ||
| 107 | #define EMACS_ADD_TIME(dest, src1, src2) ((dest) = (src1) + (src2)) | ||
| 108 | #define EMACS_SUB_TIME(dest, src1, src2) ((dest) = (src1) - (src2)) | ||
| 109 | #define EMACS_TIME_NEG_P(t) ((t) < 0) | ||
| 110 | |||
| 111 | #endif /* def HAVE_TIMEVAL */ | ||
| 112 | |||
| 113 | #define EMACS_SET_SECS_USECS(time, secs, usecs) \ | ||
| 114 | (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs)) | ||
| 115 | |||
| 116 | #ifdef USE_UTIME | ||
| 117 | |||
| 118 | #define EMACS_SET_UTIMES(path, atime, mtime) \ | ||
| 119 | { \ | ||
| 120 | struct time_t tv[2]; \ | ||
| 121 | tv[0] = EMACS_SECS (atime); \ | ||
| 122 | tv[1] = EMACS_SECS (mtime); \ | ||
| 123 | utime ((path), tv); \ | ||
| 124 | } | ||
| 125 | |||
| 126 | #else | ||
| 127 | |||
| 128 | #define EMACS_SET_UTIMES(path, atime, mtime) \ | ||
| 129 | { \ | ||
| 130 | EMACS_TIME tv[2]; \ | ||
| 131 | tv[0] = atime; \ | ||
| 132 | tv[1] = mtime; \ | ||
| 133 | utimes ((path), tv); \ | ||
| 134 | } | ||
| 135 | |||
| 136 | #endif | ||