* doc/misc/htmlfontify.texi (Customization): Remove documentation of `hfy-fast-lock...
[emacs.git] / src / systime.h
blobdf733b290c3e706d46e969e3da4e48df029ee676
1 /* systime.h - System-dependent definitions for time manipulations.
2 Copyright (C) 1993-1994, 2002-2013 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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 3 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 #ifndef EMACS_SYSTIME_H
20 #define EMACS_SYSTIME_H
22 #include <timespec.h>
24 INLINE_HEADER_BEGIN
25 #ifndef SYSTIME_INLINE
26 # define SYSTIME_INLINE INLINE
27 #endif
29 #ifdef emacs
30 # ifdef HAVE_X_WINDOWS
31 # include <X11/X.h>
32 # else
33 typedef unsigned long Time;
34 # endif
35 #endif
37 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
38 disagree about the name of the guard symbol. */
39 #ifdef HPUX
40 #ifdef _STRUCT_TIMEVAL
41 #ifndef __TIMEVAL__
42 #define __TIMEVAL__
43 #endif
44 #endif
45 #endif
47 #include <sys/time.h> /* for 'struct timeval' */
49 /* The type to use to represent non-negative temporal intervals. Its
50 address can be passed as the timeout argument to the pselect system
51 call. */
52 typedef struct timespec EMACS_TIME;
54 /* Resolution of EMACS_TIME time stamps (in units per second), and log
55 base 10 of the resolution. The log must be a positive integer. */
56 enum { EMACS_TIME_RESOLUTION = 1000000000 };
57 enum { LOG10_EMACS_TIME_RESOLUTION = 9 };
59 /* EMACS_SECS (TIME) is the seconds component of TIME.
60 EMACS_NSECS (TIME) is the nanoseconds component of TIME.
61 emacs_secs_addr (PTIME) is the address of *PTIME's seconds component. */
62 SYSTIME_INLINE time_t EMACS_SECS (EMACS_TIME t) { return t.tv_sec; }
63 SYSTIME_INLINE int EMACS_NSECS (EMACS_TIME t) { return t.tv_nsec; }
64 SYSTIME_INLINE time_t *emacs_secs_addr (EMACS_TIME *t) { return &t->tv_sec; }
66 /* Return an Emacs time with seconds S and nanoseconds NS. */
67 SYSTIME_INLINE EMACS_TIME
68 make_emacs_time (time_t s, int ns)
70 EMACS_TIME r;
71 r.tv_sec = s;
72 r.tv_nsec = ns;
73 return r;
76 /* Return an invalid Emacs time. */
77 SYSTIME_INLINE EMACS_TIME
78 invalid_emacs_time (void)
80 EMACS_TIME r;
81 r.tv_sec = 0;
82 r.tv_nsec = -1;
83 return r;
86 /* Return current system time. */
87 SYSTIME_INLINE EMACS_TIME
88 current_emacs_time (void)
90 EMACS_TIME r;
91 gettime (&r);
92 return r;
95 /* Return the result of adding A to B, or of subtracting B from A.
96 On overflow, store an extremal value: ergo, if time_t is unsigned,
97 return 0 if the true answer would be negative.
99 WARNING: These are NOT general-purpose macros for adding or
100 subtracting arbitrary time values! They are generally intended to
101 be used with their first argument an absolute time since the epoch
102 and the second argument a non-negative offset. Do NOT use them for
103 anything else. */
104 SYSTIME_INLINE EMACS_TIME
105 add_emacs_time (EMACS_TIME a, EMACS_TIME b)
107 return timespec_add (a, b);
109 SYSTIME_INLINE EMACS_TIME
110 sub_emacs_time (EMACS_TIME a, EMACS_TIME b)
112 return timespec_sub (a, b);
115 /* Return the sign of the valid time stamp TIME, either -1, 0, or 1.
116 Note: this can only return a negative value if time_t is a signed
117 data type. */
118 SYSTIME_INLINE int
119 EMACS_TIME_SIGN (EMACS_TIME t)
121 return timespec_sign (t);
124 /* Return 1 if TIME is a valid time stamp. */
125 SYSTIME_INLINE int
126 EMACS_TIME_VALID_P (EMACS_TIME t)
128 return t.tv_nsec >= 0;
131 /* Convert the double D to the greatest EMACS_TIME not greater than D.
132 On overflow, return an extremal value; in particular, if time_t is
133 an unsigned data type and D is negative, return zero. Return the
134 minimum EMACS_TIME if D is not a number. */
135 SYSTIME_INLINE EMACS_TIME
136 EMACS_TIME_FROM_DOUBLE (double d)
138 return dtotimespec (d);
141 /* Convert the Emacs time T to an approximate double value D. */
142 SYSTIME_INLINE double
143 EMACS_TIME_TO_DOUBLE (EMACS_TIME t)
145 return timespectod (t);
148 /* defined in sysdep.c */
149 extern int set_file_times (int, const char *, EMACS_TIME, EMACS_TIME);
150 extern struct timeval make_timeval (EMACS_TIME) ATTRIBUTE_CONST;
152 /* defined in keyboard.c */
153 extern void set_waiting_for_input (EMACS_TIME *);
155 /* When lisp.h is not included Lisp_Object is not defined (this can
156 happen when this files is used outside the src directory).
157 Use GCPRO1 to determine if lisp.h was included. */
158 #ifdef GCPRO1
159 /* defined in editfns.c */
160 extern Lisp_Object make_lisp_time (EMACS_TIME);
161 extern bool decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object,
162 Lisp_Object, EMACS_TIME *, double *);
163 extern EMACS_TIME lisp_time_argument (Lisp_Object);
164 #endif
166 /* Compare times T1 and T2 for equality, inequality etc. */
167 SYSTIME_INLINE int
168 EMACS_TIME_EQ (EMACS_TIME t1, EMACS_TIME t2)
170 return timespec_cmp (t1, t2) == 0;
172 SYSTIME_INLINE int
173 EMACS_TIME_LT (EMACS_TIME t1, EMACS_TIME t2)
175 return timespec_cmp (t1, t2) < 0;
177 SYSTIME_INLINE int
178 EMACS_TIME_LE (EMACS_TIME t1, EMACS_TIME t2)
180 return timespec_cmp (t1, t2) <= 0;
183 INLINE_HEADER_END
185 #endif /* EMACS_SYSTIME_H */