1*a7c91847Schristos /* timespec -- System time interface
2*a7c91847Schristos
3*a7c91847Schristos Copyright (C) 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
4*a7c91847Schristos
5*a7c91847Schristos This program is free software; you can redistribute it and/or modify
6*a7c91847Schristos it under the terms of the GNU General Public License as published by
7*a7c91847Schristos the Free Software Foundation; either version 2, or (at your option)
8*a7c91847Schristos any later version.
9*a7c91847Schristos
10*a7c91847Schristos This program is distributed in the hope that it will be useful,
11*a7c91847Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
12*a7c91847Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*a7c91847Schristos GNU General Public License for more details.
14*a7c91847Schristos
15*a7c91847Schristos You should have received a copy of the GNU General Public License
16*a7c91847Schristos along with this program; if not, write to the Free Software Foundation,
17*a7c91847Schristos Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18*a7c91847Schristos
19*a7c91847Schristos #if ! defined TIMESPEC_H
20*a7c91847Schristos # define TIMESPEC_H
21*a7c91847Schristos
22*a7c91847Schristos # include <sys/types.h>
23*a7c91847Schristos # if TIME_WITH_SYS_TIME
24*a7c91847Schristos # include <sys/time.h>
25*a7c91847Schristos # include <time.h>
26*a7c91847Schristos # else
27*a7c91847Schristos # if HAVE_SYS_TIME_H
28*a7c91847Schristos # include <sys/time.h>
29*a7c91847Schristos # else
30*a7c91847Schristos # include <time.h>
31*a7c91847Schristos # endif
32*a7c91847Schristos # endif
33*a7c91847Schristos
34*a7c91847Schristos # if ! HAVE_STRUCT_TIMESPEC
35*a7c91847Schristos /* Some systems don't define this struct, e.g., AIX 4.1, Ultrix 4.3. */
36*a7c91847Schristos struct timespec
37*a7c91847Schristos {
38*a7c91847Schristos time_t tv_sec;
39*a7c91847Schristos long tv_nsec;
40*a7c91847Schristos };
41*a7c91847Schristos # endif
42*a7c91847Schristos
43*a7c91847Schristos /* Return negative, zero, positive if A < B, A == B, A > B, respectively.
44*a7c91847Schristos Assume the nanosecond components are in range, or close to it. */
45*a7c91847Schristos static inline int
timespec_cmp(struct timespec a,struct timespec b)46*a7c91847Schristos timespec_cmp (struct timespec a, struct timespec b)
47*a7c91847Schristos {
48*a7c91847Schristos return (a.tv_sec < b.tv_sec ? -1
49*a7c91847Schristos : a.tv_sec > b.tv_sec ? 1
50*a7c91847Schristos : a.tv_nsec - b.tv_nsec);
51*a7c91847Schristos }
52*a7c91847Schristos
53*a7c91847Schristos # if ! HAVE_DECL_NANOSLEEP
54*a7c91847Schristos /* Don't specify a prototype here. Some systems (e.g., OSF) declare
55*a7c91847Schristos nanosleep with a conflicting one (const-less first parameter). */
56*a7c91847Schristos int nanosleep ();
57*a7c91847Schristos # endif
58*a7c91847Schristos
59*a7c91847Schristos void gettime (struct timespec *);
60*a7c91847Schristos int settime (struct timespec const *);
61*a7c91847Schristos
62*a7c91847Schristos #endif
63