OpenCoverage

xtime.h

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/xtime.h
Source codeSwitch to Preprocessed file
LineSourceCount
1/* xtime -- extended-resolution integer timestamps-
2-
3 Copyright (C) 2005-2006, 2009-2018 Free Software Foundation, Inc.-
4-
5 This program is free software: you can redistribute it and/or modify-
6 it under the terms of the GNU General Public License as published by-
7 the Free Software Foundation; either version 3 of the License, or-
8 (at your option) any later version.-
9-
10 This program is distributed in the hope that it will be useful,-
11 but WITHOUT ANY WARRANTY; without even the implied warranty of-
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
13 GNU General Public License for more details.-
14-
15 You should have received a copy of the GNU General Public License-
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
17-
18/* Written by Paul Eggert. */-
19-
20#ifndef XTIME_H_-
21#define XTIME_H_ 1-
22-
23#ifndef _GL_INLINE_HEADER_BEGIN-
24 #error "Please include config.h first."-
25#endif-
26_GL_INLINE_HEADER_BEGIN-
27#ifndef XTIME_INLINE-
28# define XTIME_INLINE _GL_INLINE-
29#endif-
30-
31/* xtime_t is a signed type used for timestamps. It is an integer-
32 type that is a count of nanoseconds -- except for obsolescent hosts-
33 without sufficiently-wide integers, where it is a count of-
34 seconds. */-
35#if HAVE_LONG_LONG_INT-
36typedef long long int xtime_t;-
37# define XTIME_PRECISION 1000000000-
38#else-
39# include <limits.h>-
40typedef long int xtime_t;-
41# if LONG_MAX >> 31 >> 31 == 0-
42# define XTIME_PRECISION 1-
43# else-
44# define XTIME_PRECISION 1000000000-
45# endif-
46#endif-
47-
48#ifdef __cplusplus-
49extern "C" {-
50#endif-
51-
52/* Return an extended time value that contains S seconds and NS-
53 nanoseconds, without any overflow checking. */-
54XTIME_INLINE xtime_t-
55xtime_make (xtime_t s, long int ns)-
56{-
57 if (XTIME_PRECISION == 1)
1000000000 == 1Description
TRUEnever evaluated
FALSEevaluated 778 times by 1 test
Evaluated by:
  • dd
0-778
58 return s;
never executed: return s;
0
59 else-
60 return XTIME_PRECISION * s + ns;
executed 778 times by 1 test: return 1000000000 * s + ns;
Executed by:
  • dd
778
61}-
62-
63/* Return the number of seconds in T, which must be nonnegative. */-
64XTIME_INLINE xtime_t-
65xtime_nonnegative_sec (xtime_t t)-
66{-
67 return t / XTIME_PRECISION;
never executed: return t / 1000000000;
0
68}-
69-
70/* Return the number of seconds in T. */-
71XTIME_INLINE xtime_t-
72xtime_sec (xtime_t t)-
73{-
74 return (XTIME_PRECISION == 1
never executed: return (1000000000 == 1 ? t : t < 0 ? (t + 1000000000 - 1) / 1000000000 - 1 : xtime_nonnegative_sec (t));
0
75 ? t
never executed: return (1000000000 == 1 ? t : t < 0 ? (t + 1000000000 - 1) / 1000000000 - 1 : xtime_nonnegative_sec (t));
0
76 : t < 0
never executed: return (1000000000 == 1 ? t : t < 0 ? (t + 1000000000 - 1) / 1000000000 - 1 : xtime_nonnegative_sec (t));
0
77 ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1
never executed: return (1000000000 == 1 ? t : t < 0 ? (t + 1000000000 - 1) / 1000000000 - 1 : xtime_nonnegative_sec (t));
0
78 : xtime_nonnegative_sec (t));
never executed: return (1000000000 == 1 ? t : t < 0 ? (t + 1000000000 - 1) / 1000000000 - 1 : xtime_nonnegative_sec (t));
0
79}-
80-
81/* Return the number of nanoseconds in T, which must be nonnegative. */-
82XTIME_INLINE long int-
83xtime_nonnegative_nsec (xtime_t t)-
84{-
85 return t % XTIME_PRECISION;
never executed: return t % 1000000000;
0
86}-
87-
88/* Return the number of nanoseconds in T. */-
89XTIME_INLINE long int-
90xtime_nsec (xtime_t t)-
91{-
92 long int ns = t % XTIME_PRECISION;-
93 if (ns < 0)
ns < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
94 ns += XTIME_PRECISION;
never executed: ns += 1000000000;
0
95 return ns;
never executed: return ns;
0
96}-
97-
98#ifdef __cplusplus-
99}-
100#endif-
101-
102#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2