annotate libiberty/timeval-utils.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Basic struct timeval utilities.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2011-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of the libiberty library.
kono
parents:
diff changeset
5 Libiberty is free software; you can redistribute it and/or
kono
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
kono
parents:
diff changeset
7 License as published by the Free Software Foundation; either
kono
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 Libiberty is distributed in the hope that it will be useful,
kono
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
kono
parents:
diff changeset
13 Library General Public License for more details.
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
kono
parents:
diff changeset
16 License along with libiberty; see the file COPYING.LIB. If not,
kono
parents:
diff changeset
17 write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
kono
parents:
diff changeset
18 Boston, MA 02110-1301, USA. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 /* On some systems (such as WindISS), you must include <sys/types.h>
kono
parents:
diff changeset
23 to get the definition of "time_t" before you include <time.h>. */
kono
parents:
diff changeset
24 #include <sys/types.h>
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 #ifdef TIME_WITH_SYS_TIME
kono
parents:
diff changeset
27 # include <sys/time.h>
kono
parents:
diff changeset
28 # include <time.h>
kono
parents:
diff changeset
29 #else
kono
parents:
diff changeset
30 # if HAVE_SYS_TIME_H
kono
parents:
diff changeset
31 # include <sys/time.h>
kono
parents:
diff changeset
32 # else
kono
parents:
diff changeset
33 # ifdef HAVE_TIME_H
kono
parents:
diff changeset
34 # include <time.h>
kono
parents:
diff changeset
35 # endif
kono
parents:
diff changeset
36 # endif
kono
parents:
diff changeset
37 #endif
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 #include "timeval-utils.h"
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 /*
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 @deftypefn Extension void timeval_add (struct timeval *@var{a}, @
kono
parents:
diff changeset
44 struct timeval *@var{b}, struct timeval *@var{result})
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 Adds @var{a} to @var{b} and stores the result in @var{result}.
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 @end deftypefn
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 */
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 void
kono
parents:
diff changeset
53 timeval_add (struct timeval *result,
kono
parents:
diff changeset
54 const struct timeval *a, const struct timeval *b)
kono
parents:
diff changeset
55 {
kono
parents:
diff changeset
56 result->tv_sec = a->tv_sec + b->tv_sec;
kono
parents:
diff changeset
57 result->tv_usec = a->tv_usec + b->tv_usec;
kono
parents:
diff changeset
58 if (result->tv_usec >= 1000000)
kono
parents:
diff changeset
59 {
kono
parents:
diff changeset
60 ++result->tv_sec;
kono
parents:
diff changeset
61 result->tv_usec -= 1000000;
kono
parents:
diff changeset
62 }
kono
parents:
diff changeset
63 }
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 /*
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 @deftypefn Extension void timeval_sub (struct timeval *@var{a}, @
kono
parents:
diff changeset
68 struct timeval *@var{b}, struct timeval *@var{result})
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 Subtracts @var{b} from @var{a} and stores the result in @var{result}.
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 @end deftypefn
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 */
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 void
kono
parents:
diff changeset
77 timeval_sub (struct timeval *result,
kono
parents:
diff changeset
78 const struct timeval *a, const struct timeval *b)
kono
parents:
diff changeset
79 {
kono
parents:
diff changeset
80 result->tv_sec = a->tv_sec - b->tv_sec;
kono
parents:
diff changeset
81 result->tv_usec = a->tv_usec - b->tv_usec;
kono
parents:
diff changeset
82 if (result->tv_usec < 0)
kono
parents:
diff changeset
83 {
kono
parents:
diff changeset
84 --result->tv_sec;
kono
parents:
diff changeset
85 result->tv_usec += 1000000;
kono
parents:
diff changeset
86 }
kono
parents:
diff changeset
87 }