]> git.ipfire.org Git - thirdparty/bash.git/blame - include/posixtime.h
bash-5.2 distribution sources and documentation
[thirdparty/bash.git] / include / posixtime.h
CommitLineData
bb70624e
JA
1/* posixtime.h -- wrapper for time.h, sys/times.h mess. */
2
74091dd4 3/* Copyright (C) 1999-2021 Free Software Foundation, Inc.
bb70624e
JA
4
5 This file is part of GNU Bash, the Bourne Again SHell.
6
3185942a
JA
7 Bash is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
bb70624e 11
3185942a
JA
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
bb70624e
JA
16
17 You should have received a copy of the GNU General Public License
3185942a
JA
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
19*/
bb70624e
JA
20
21#ifndef _POSIXTIME_H_
22#define _POSIXTIME_H_
23
24/* include this after config.h */
25/* Some systems require this, mostly for the definition of `struct timezone'.
26 For example, Dynix/ptx has that definition in <time.h> rather than
27 sys/time.h */
74091dd4 28#if defined (HAVE_SYS_TIME_H)
bb70624e 29# include <sys/time.h>
bb70624e 30#endif
74091dd4 31#include <time.h>
bb70624e
JA
32
33#if !defined (HAVE_SYSCONF) || !defined (_SC_CLK_TCK)
34# if !defined (CLK_TCK)
35# if defined (HZ)
36# define CLK_TCK HZ
37# else
38# define CLK_TCK 60 /* 60HZ */
39# endif
40# endif /* !CLK_TCK */
41#endif /* !HAVE_SYSCONF && !_SC_CLK_TCK */
42
8868edaf
CR
43#if !HAVE_TIMEVAL
44struct timeval
45{
46 time_t tv_sec;
47 long int tv_usec;
48};
49#endif
50
51#if !HAVE_GETTIMEOFDAY
52extern int gettimeofday PARAMS((struct timeval *, void *));
53#endif
54
74091dd4
CR
55/* These exist on BSD systems, at least. */
56#if !defined (timerclear)
57# define timerclear(tvp) do { (tvp)->tv_sec = 0; (tvp)->tv_usec = 0; } while (0)
58#endif
59#if !defined (timerisset)
60# define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
61#endif
62#if !defined (timercmp)
63# define timercmp(a, b, CMP) \
64 (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_usec CMP (b)->tv_usec) \
65 : ((a)->tv_sec CMP (b)->tv_sec))
66#endif
67
68/* These are non-standard. */
69#if !defined (timerisunset)
70# define timerisunset(tvp) ((tvp)->tv_sec == 0 && (tvp)->tv_usec == 0)
71#endif
72#if !defined (timerset)
73# define timerset(tvp, s, u) do { tvp->tv_sec = s; tvp->tv_usec = u; } while (0)
74#endif
75
76#ifndef TIMEVAL_TO_TIMESPEC
77# define TIMEVAL_TO_TIMESPEC(tv, ts) \
78 do { \
79 (ts)->tv_sec = (tv)->tv_sec; \
80 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
81 } while (0)
82#endif
83
bb70624e 84#endif /* _POSIXTIME_H_ */