systime.h 3.11 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
1
/* systime.h - System-dependent definitions for time manipulations.
Paul Eggert's avatar
Paul Eggert committed
2
   Copyright (C) 1993-1994, 2002-2019 Free Software Foundation, Inc.
Jim Blandy's avatar
Jim Blandy committed
3 4 5

This file is part of GNU Emacs.

6
GNU Emacs is free software: you can redistribute it and/or modify
Jim Blandy's avatar
Jim Blandy committed
7
it under the terms of the GNU General Public License as published by
8 9
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Jim Blandy's avatar
Jim Blandy committed
10 11 12 13 14 15 16

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
17
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
Jim Blandy's avatar
Jim Blandy committed
18

19 20
#ifndef EMACS_SYSTIME_H
#define EMACS_SYSTIME_H
21

22
#include <timespec.h>
Jim Blandy's avatar
Jim Blandy committed
23

24 25
INLINE_HEADER_BEGIN

26 27 28 29
#ifdef emacs
# ifdef HAVE_X_WINDOWS
#  include <X11/X.h>
# else
30
typedef unsigned long Time;
31
# endif
32 33
#endif

34 35
/* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
   disagree about the name of the guard symbol.  */
36
#ifdef HPUX
37 38 39 40 41
#ifdef _STRUCT_TIMEVAL
#ifndef __TIMEVAL__
#define __TIMEVAL__
#endif
#endif
42
#endif
43 44

#include <sys/time.h>	/* for 'struct timeval' */
Jim Blandy's avatar
Jim Blandy committed
45

46
/* Emacs uses struct timespec to represent nonnegative temporal intervals.
47

48 49 50 51
   WARNING: Since tv_sec might be an unsigned value, do not use struct
   timespec as a general-purpose data type for adding or subtracting
   arbitrary time values!  When computing A + B or A - B, typically A
   should be an absolute time since the epoch and B a nonnegative offset.  */
Jim Blandy's avatar
Jim Blandy committed
52

53
/* Return an invalid timespec.  */
Paul Eggert's avatar
Paul Eggert committed
54
INLINE struct timespec
55
invalid_timespec (void)
56
{
57
  return make_timespec (0, -1);
58
}
Jim Blandy's avatar
Jim Blandy committed
59

60
/* Return true if TIME is a valid timespec.  This currently doesn't worry
61 62
   about whether tv_nsec is less than TIMESPEC_RESOLUTION; leap seconds
   might cause a problem if it did.  */
63
INLINE bool
64
timespec_valid_p (struct timespec t)
65
{
66
  return t.tv_nsec >= 0;
67
}
68

69
/* Return current system time.  */
Paul Eggert's avatar
Paul Eggert committed
70
INLINE struct timespec
71
current_timespec (void)
72
{
73 74 75
  struct timespec r;
  gettime (&r);
  return r;
76
}
Jim Blandy's avatar
Jim Blandy committed
77

78
/* defined in sysdep.c */
79 80
extern int set_file_times (int, const char *, struct timespec, struct timespec);
extern struct timeval make_timeval (struct timespec) ATTRIBUTE_CONST;
81

82
/* defined in keyboard.c */
83
extern void set_waiting_for_input (struct timespec *);
84

85
/* When lisp.h is not included Lisp_Object is not defined (this can
86 87
   happen when this file is used outside the src directory).  */
#ifdef emacs
88 89 90 91 92 93 94 95 96 97 98 99

/* Emacs uses the integer list (HI LO US PS) to represent the time
   (HI << LO_TIME_BITS) + LO + US / 1e6 + PS / 1e12.  */
enum { LO_TIME_BITS = 16 };

/* A Lisp time (HI LO US PS), sans the cons cells.  */
struct lisp_time
{
  EMACS_INT hi;
  int lo, us, ps;
};

100
/* defined in editfns.c */
101
extern Lisp_Object make_lisp_time (struct timespec);
102 103
extern int decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object,
				   Lisp_Object, struct lisp_time *, double *);
104
extern struct timespec lisp_to_timespec (struct lisp_time);
105
extern struct timespec lisp_time_argument (Lisp_Object);
106 107
#endif

108 109
INLINE_HEADER_END

110
#endif /* EMACS_SYSTIME_H */