summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dtotimespec.c10
-rw-r--r--lib/stat-time.h8
-rw-r--r--lib/timespec-add.c6
-rw-r--r--lib/timespec-sub.c6
-rw-r--r--lib/timespec.h18
-rw-r--r--lib/utimens.c4
-rw-r--r--lib/utimensat.c4
7 files changed, 31 insertions, 25 deletions
diff --git a/lib/dtotimespec.c b/lib/dtotimespec.c
index 599f7427a9..dcbd28051c 100644
--- a/lib/dtotimespec.c
+++ b/lib/dtotimespec.c
@@ -32,20 +32,20 @@ dtotimespec (double sec)
if (! (TYPE_MINIMUM (time_t) < sec))
return make_timespec (TYPE_MINIMUM (time_t), 0);
else if (! (sec < 1.0 + TYPE_MAXIMUM (time_t)))
- return make_timespec (TYPE_MAXIMUM (time_t), TIMESPEC_RESOLUTION - 1);
+ return make_timespec (TYPE_MAXIMUM (time_t), TIMESPEC_HZ - 1);
else
{
time_t s = sec;
- double frac = TIMESPEC_RESOLUTION * (sec - s);
+ double frac = TIMESPEC_HZ * (sec - s);
long ns = frac;
ns += ns < frac;
- s += ns / TIMESPEC_RESOLUTION;
- ns %= TIMESPEC_RESOLUTION;
+ s += ns / TIMESPEC_HZ;
+ ns %= TIMESPEC_HZ;
if (ns < 0)
{
s--;
- ns += TIMESPEC_RESOLUTION;
+ ns += TIMESPEC_HZ;
}
return make_timespec (s, ns);
diff --git a/lib/stat-time.h b/lib/stat-time.h
index 8e787bd3b2..69ebe85df1 100644
--- a/lib/stat-time.h
+++ b/lib/stat-time.h
@@ -213,7 +213,7 @@ stat_time_normalize (int result, struct stat *st _GL_UNUSED)
#if defined __sun && defined STAT_TIMESPEC
if (result == 0)
{
- long int timespec_resolution = 1000000000;
+ long int timespec_hz = 1000000000;
short int const ts_off[] = { offsetof (struct stat, st_atim),
offsetof (struct stat, st_mtim),
offsetof (struct stat, st_ctim) };
@@ -221,11 +221,11 @@ stat_time_normalize (int result, struct stat *st _GL_UNUSED)
for (i = 0; i < sizeof ts_off / sizeof *ts_off; i++)
{
struct timespec *ts = (struct timespec *) ((char *) st + ts_off[i]);
- long int q = ts->tv_nsec / timespec_resolution;
- long int r = ts->tv_nsec % timespec_resolution;
+ long int q = ts->tv_nsec / timespec_hz;
+ long int r = ts->tv_nsec % timespec_hz;
if (r < 0)
{
- r += timespec_resolution;
+ r += timespec_hz;
q--;
}
ts->tv_nsec = r;
diff --git a/lib/timespec-add.c b/lib/timespec-add.c
index f6a8c38b33..1913b979ed 100644
--- a/lib/timespec-add.c
+++ b/lib/timespec-add.c
@@ -18,7 +18,7 @@
/* Written by Paul Eggert. */
/* Return the sum of two timespec values A and B. On overflow, return
- an extremal value. This assumes 0 <= tv_nsec < TIMESPEC_RESOLUTION. */
+ an extremal value. This assumes 0 <= tv_nsec < TIMESPEC_HZ. */
#include <config.h>
#include "timespec.h"
@@ -31,7 +31,7 @@ timespec_add (struct timespec a, struct timespec b)
time_t rs = a.tv_sec;
time_t bs = b.tv_sec;
int ns = a.tv_nsec + b.tv_nsec;
- int nsd = ns - TIMESPEC_RESOLUTION;
+ int nsd = ns - TIMESPEC_HZ;
int rns = ns;
time_t tmin = TYPE_MINIMUM (time_t);
time_t tmax = TYPE_MAXIMUM (time_t);
@@ -63,7 +63,7 @@ timespec_add (struct timespec a, struct timespec b)
{
high_overflow:
rs = tmax;
- rns = TIMESPEC_RESOLUTION - 1;
+ rns = TIMESPEC_HZ - 1;
}
}
diff --git a/lib/timespec-sub.c b/lib/timespec-sub.c
index 398a6a5de4..9eac36e51a 100644
--- a/lib/timespec-sub.c
+++ b/lib/timespec-sub.c
@@ -19,7 +19,7 @@
/* Return the difference between two timespec values A and B. On
overflow, return an extremal value. This assumes 0 <= tv_nsec <
- TIMESPEC_RESOLUTION. */
+ TIMESPEC_HZ. */
#include <config.h>
#include "timespec.h"
@@ -38,7 +38,7 @@ timespec_sub (struct timespec a, struct timespec b)
if (ns < 0)
{
- rns = ns + TIMESPEC_RESOLUTION;
+ rns = ns + TIMESPEC_HZ;
if (bs < tmax)
bs++;
else if (- TYPE_SIGNED (time_t) < rs)
@@ -63,7 +63,7 @@ timespec_sub (struct timespec a, struct timespec b)
else
{
rs = tmax;
- rns = TIMESPEC_RESOLUTION - 1;
+ rns = TIMESPEC_HZ - 1;
}
}
diff --git a/lib/timespec.h b/lib/timespec.h
index 94ba8d0b6a..c414cfe45e 100644
--- a/lib/timespec.h
+++ b/lib/timespec.h
@@ -35,11 +35,17 @@ extern "C" {
#include "verify.h"
-/* Resolution of timespec timestamps (in units per second), and log
- base 10 of the resolution. */
+/* Inverse resolution of timespec timestamps (in units per second),
+ and log base 10 of the inverse resolution. */
-enum { TIMESPEC_RESOLUTION = 1000000000 };
-enum { LOG10_TIMESPEC_RESOLUTION = 9 };
+enum { TIMESPEC_HZ = 1000000000 };
+enum { LOG10_TIMESPEC_HZ = 9 };
+
+/* Obsolescent names for backward compatibility.
+ They are misnomers, because TIMESPEC_RESOLUTION is not a resolution. */
+
+enum { TIMESPEC_RESOLUTION = TIMESPEC_HZ };
+enum { LOG10_TIMESPEC_RESOLUTION = LOG10_TIMESPEC_HZ };
/* Return a timespec with seconds S and nanoseconds NS. */
@@ -88,8 +94,8 @@ timespec_cmp (struct timespec a, struct timespec b)
/* Pacify gcc -Wstrict-overflow (bleeding-edge circa 2017-10-02). See:
https://lists.gnu.org/r/bug-gnulib/2017-10/msg00006.html */
- assume (-1 <= a.tv_nsec && a.tv_nsec <= 2 * TIMESPEC_RESOLUTION);
- assume (-1 <= b.tv_nsec && b.tv_nsec <= 2 * TIMESPEC_RESOLUTION);
+ assume (-1 <= a.tv_nsec && a.tv_nsec <= 2 * TIMESPEC_HZ);
+ assume (-1 <= b.tv_nsec && b.tv_nsec <= 2 * TIMESPEC_HZ);
return a.tv_nsec - b.tv_nsec;
}
diff --git a/lib/utimens.c b/lib/utimens.c
index e65f55d82f..f6c4fe34c7 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -91,11 +91,11 @@ validate_timespec (struct timespec timespec[2])
if ((timespec[0].tv_nsec != UTIME_NOW
&& timespec[0].tv_nsec != UTIME_OMIT
&& ! (0 <= timespec[0].tv_nsec
- && timespec[0].tv_nsec < TIMESPEC_RESOLUTION))
+ && timespec[0].tv_nsec < TIMESPEC_HZ))
|| (timespec[1].tv_nsec != UTIME_NOW
&& timespec[1].tv_nsec != UTIME_OMIT
&& ! (0 <= timespec[1].tv_nsec
- && timespec[1].tv_nsec < TIMESPEC_RESOLUTION)))
+ && timespec[1].tv_nsec < TIMESPEC_HZ)))
{
errno = EINVAL;
return -1;
diff --git a/lib/utimensat.c b/lib/utimensat.c
index 72ac1b4adb..6d4144cb4a 100644
--- a/lib/utimensat.c
+++ b/lib/utimensat.c
@@ -94,10 +94,10 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2],
else if (times
&& ((times[0].tv_nsec != UTIME_NOW
&& ! (0 <= times[0].tv_nsec
- && times[0].tv_nsec < TIMESPEC_RESOLUTION))
+ && times[0].tv_nsec < TIMESPEC_HZ))
|| (times[1].tv_nsec != UTIME_NOW
&& ! (0 <= times[1].tv_nsec
- && times[1].tv_nsec < TIMESPEC_RESOLUTION))))
+ && times[1].tv_nsec < TIMESPEC_HZ))))
{
errno = EINVAL;
return -1;