1 /* Basic struct timeval utilities.
2 Copyright (C) 2011 Free Software Foundation, Inc.
4 This file is part of the libiberty library.
5 Libiberty is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 Libiberty 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 GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with libiberty; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18 Boston, MA 02110-1301, USA. */
22 /* On some systems (such as WindISS), you must include <sys/types.h>
23 to get the definition of "time_t" before you include <time.h>. */
24 #include <sys/types.h>
26 #ifdef TIME_WITH_SYS_TIME
27 # include <sys/time.h>
31 # include <sys/time.h>
39 #include "timeval-utils.h"
43 @deftypefn Extension void timeval_add (struct timeval *@var{a}, @
44 struct timeval *@var{b}, struct timeval *@var{result})
46 Adds @var{a} to @var{b} and stores the result in @var{result}.
53 timeval_add (struct timeval
*result
,
54 const struct timeval
*a
, const struct timeval
*b
)
56 result
->tv_sec
= a
->tv_sec
+ b
->tv_sec
;
57 result
->tv_usec
= a
->tv_usec
+ b
->tv_usec
;
58 if (result
->tv_usec
>= 1000000)
61 result
->tv_usec
-= 1000000;
67 @deftypefn Extension void timeval_sub (struct timeval *@var{a}, @
68 struct timeval *@var{b}, struct timeval *@var{result})
70 Subtracts @var{b} from @var{a} and stores the result in @var{result}.
77 timeval_sub (struct timeval
*result
,
78 const struct timeval
*a
, const struct timeval
*b
)
80 result
->tv_sec
= a
->tv_sec
- b
->tv_sec
;
81 result
->tv_usec
= a
->tv_usec
- b
->tv_usec
;
82 if (result
->tv_usec
< 0)
85 result
->tv_usec
+= 1000000;
This page took 0.030568 seconds and 4 git commands to generate.