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