projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix license quoting in files.yaml
[gnulib.git]
/
lib
/
dtotimespec.c
diff --git
a/lib/dtotimespec.c
b/lib/dtotimespec.c
index
ea0470a
..
57a0cee
100644
(file)
--- a/
lib/dtotimespec.c
+++ b/
lib/dtotimespec.c
@@
-1,6
+1,6
@@
/* Convert double to timespec.
/* Convert double to timespec.
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2011
-2014
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-29,41
+29,31
@@
struct timespec
dtotimespec (double sec)
{
struct timespec
dtotimespec (double sec)
{
- enum { BILLION = 1000 * 1000 * 1000 };
double min_representable = TYPE_MINIMUM (time_t);
double max_representable =
double min_representable = TYPE_MINIMUM (time_t);
double max_representable =
- ((TYPE_MAXIMUM (time_t) * (double)
BILLION + (BILLION - 1))
- / BILLION);
-
struct timespec r
;
+ ((TYPE_MAXIMUM (time_t) * (double)
TIMESPEC_RESOLUTION
+ + (TIMESPEC_RESOLUTION - 1))
+
/ TIMESPEC_RESOLUTION)
;
if (! (min_representable < sec))
if (! (min_representable < sec))
- {
- r.tv_sec = TYPE_MINIMUM (time_t);
- r.tv_nsec = 0;
- }
+ return make_timespec (TYPE_MINIMUM (time_t), 0);
else if (! (sec < max_representable))
else if (! (sec < max_representable))
- {
- r.tv_sec = TYPE_MAXIMUM (time_t);
- r.tv_nsec = BILLION - 1;
- }
+ return make_timespec (TYPE_MAXIMUM (time_t), TIMESPEC_RESOLUTION - 1);
else
{
time_t s = sec;
else
{
time_t s = sec;
- double frac =
BILL
ION * (sec - s);
+ double frac =
TIMESPEC_RESOLUT
ION * (sec - s);
long ns = frac;
ns += ns < frac;
long ns = frac;
ns += ns < frac;
- s += ns /
BILL
ION;
- ns %=
BILL
ION;
+ s += ns /
TIMESPEC_RESOLUT
ION;
+ ns %=
TIMESPEC_RESOLUT
ION;
if (ns < 0)
{
s--;
if (ns < 0)
{
s--;
- ns +=
BILL
ION;
+ ns +=
TIMESPEC_RESOLUT
ION;
}
}
- r.tv_sec = s;
- r.tv_nsec = ns;
+ return make_timespec (s, ns);
}
}
-
- return r;
}
}