]>
Commit | Line | Data |
---|---|---|
c11b1abf | 1 | .\" Copyright (c) 2007 by Michael Kerrisk <mtk.manpages@gmail.com> |
d6d74fd8 | 2 | .\" |
5fbde956 | 3 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
d6d74fd8 MK |
4 | .\" |
5 | .\" 2007-07-31, mtk, Created | |
6 | .\" | |
1d767b55 | 7 | .TH TIMERADD 3 2021-03-22 "Linux" "Linux Programmer's Manual" |
d6d74fd8 | 8 | .SH NAME |
93d67152 | 9 | timeradd, timersub, timercmp, timerclear, timerisset \- timeval operations |
e90d015d AC |
10 | .SH LIBRARY |
11 | Standard C library | |
8fc3b2cf | 12 | .RI ( libc ", " \-lc ) |
d6d74fd8 MK |
13 | .SH SYNOPSIS |
14 | .nf | |
15 | .B #include <sys/time.h> | |
dbfe9c70 | 16 | .PP |
d6d74fd8 MK |
17 | .BI "void timeradd(struct timeval *" a ", struct timeval *" b , |
18 | .BI " struct timeval *" res ); | |
d6d74fd8 MK |
19 | .BI "void timersub(struct timeval *" a ", struct timeval *" b , |
20 | .BI " struct timeval *" res ); | |
dbfe9c70 | 21 | .PP |
d6d74fd8 | 22 | .BI "void timerclear(struct timeval *" tvp ); |
f6c92d2a | 23 | .BI "int timerisset(struct timeval *" tvp ); |
dbfe9c70 | 24 | .PP |
f6c92d2a | 25 | .BI "int timercmp(struct timeval *" a ", struct timeval *" b ", " CMP ); |
d6d74fd8 | 26 | .fi |
68e4db0a | 27 | .PP |
d39ad78f | 28 | .RS -4 |
d6d74fd8 MK |
29 | Feature Test Macro Requirements for glibc (see |
30 | .BR feature_test_macros (7)): | |
d39ad78f | 31 | .RE |
68e4db0a | 32 | .PP |
cfc2d88d | 33 | All functions shown above: |
9d281e06 | 34 | .nf |
51c612fb MK |
35 | Since glibc 2.19: |
36 | _DEFAULT_SOURCE | |
37 | Glibc 2.19 and earlier: | |
38 | _BSD_SOURCE | |
9d281e06 | 39 | .fi |
d6d74fd8 MK |
40 | .SH DESCRIPTION |
41 | The macros are provided to operate on | |
42 | .I timeval | |
43 | structures, defined in | |
0daa9e92 | 44 | .I <sys/time.h> |
d6d74fd8 | 45 | as: |
51f5698d | 46 | .PP |
088a639b | 47 | .in +4n |
bdd915e2 | 48 | .EX |
d6d74fd8 MK |
49 | struct timeval { |
50 | time_t tv_sec; /* seconds */ | |
51 | suseconds_t tv_usec; /* microseconds */ | |
52 | }; | |
bdd915e2 | 53 | .EE |
088a639b | 54 | .in |
d6d74fd8 MK |
55 | .PP |
56 | .BR timeradd () | |
57 | adds the time values in | |
58 | .I a | |
59 | and | |
60 | .IR b , | |
61 | and places the sum in the | |
62 | .I timeval | |
63 | pointed to by | |
64 | .IR res . | |
65 | The result is normalized such that | |
94e9d9fe | 66 | .I res\->tv_usec |
d6d74fd8 | 67 | has a value in the range 0 to 999,999. |
847e0d88 | 68 | .PP |
d6d74fd8 | 69 | .BR timersub () |
93d67152 | 70 | subtracts the time value in |
d6d74fd8 | 71 | .I b |
93d67152 | 72 | from the time value in |
d6d74fd8 MK |
73 | .IR a , |
74 | and places the result in the | |
75 | .I timeval | |
76 | pointed to by | |
77 | .IR res . | |
78 | The result is normalized such that | |
94e9d9fe | 79 | .I res\->tv_usec |
d6d74fd8 | 80 | has a value in the range 0 to 999,999. |
847e0d88 | 81 | .PP |
d6d74fd8 | 82 | .BR timerclear () |
7b01461a | 83 | zeros out the |
d6d74fd8 MK |
84 | .I timeval |
85 | structure pointed to by | |
86 | .IR tvp , | |
f49c451a | 87 | so that it represents the Epoch: 1970-01-01 00:00:00 +0000 (UTC). |
847e0d88 | 88 | .PP |
d6d74fd8 | 89 | .BR timerisset () |
c7094399 | 90 | returns true (nonzero) if either field of the |
d6d74fd8 MK |
91 | .I timeval |
92 | structure pointed to by | |
0daa9e92 | 93 | .I tvp |
c7094399 | 94 | contains a nonzero value. |
847e0d88 | 95 | .PP |
d6d74fd8 MK |
96 | .BR timercmp () |
97 | compares the timer values in | |
98 | .I a | |
99 | and | |
0daa9e92 | 100 | .I b |
d6d74fd8 MK |
101 | using the comparison operator |
102 | .IR CMP , | |
c7094399 | 103 | and returns true (nonzero) or false (0) depending on |
d6d74fd8 | 104 | the result of the comparison. |
6652fffa MK |
105 | Some systems (but not Linux/glibc), |
106 | have a broken | |
107 | .BR timercmp () | |
108 | implementation, | |
109 | .\" HP-UX, Tru64, Irix have a definition like: | |
110 | .\"#define timercmp(tvp, uvp, cmp) \ | |
111 | .\" ((tvp)->tv_sec cmp (uvp)->tv_sec || \ | |
112 | .\" (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec) | |
113 | in which | |
114 | .I CMP | |
115 | of | |
116 | .IR >= , | |
117 | .IR <= , | |
118 | and | |
119 | .I == | |
120 | do not work; | |
121 | portable applications can instead use | |
847e0d88 | 122 | .PP |
1ae6b2c7 AC |
123 | .in +4n |
124 | .EX | |
125 | !timercmp(..., <) | |
126 | !timercmp(..., >) | |
127 | !timercmp(..., !=) | |
128 | .EE | |
129 | .in | |
d6d74fd8 MK |
130 | .SH RETURN VALUE |
131 | .BR timerisset () | |
132 | and | |
133 | .BR timercmp () | |
c7094399 | 134 | return true (nonzero) or false (0). |
d6d74fd8 MK |
135 | .SH ERRORS |
136 | No errors are defined. | |
137 | .SH CONFORMING TO | |
7aecd4d8 | 138 | Not in POSIX.1. |
d6d74fd8 | 139 | Present on most BSD derivatives. |
47297adb | 140 | .SH SEE ALSO |
d6d74fd8 | 141 | .BR gettimeofday (2), |
f0c34053 | 142 | .BR time (7) |