diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-09-07 08:02:25 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-09-07 08:08:29 +0300 |
commit | 32517af75ac8c32b3ff4870e14ff28418696c554 (patch) | |
tree | afa94e0713b8dc70c9e17036e07be02caaff8ddd /src/gdbmsync.c | |
parent | 4d5be2bb19bd299a5bd3525c4e28f571929d70de (diff) | |
download | gdbm-32517af75ac8c32b3ff4870e14ff28418696c554.tar.gz gdbm-32517af75ac8c32b3ff4870e14ff28418696c554.tar.bz2 |
Determine if st_mtim is present in struct stat
* configure.ac: Check for st_mtim and st_mtimespec in struct stat.
The former is POSIX, the latter is used instead of it on some systems
(reportedly, Darwin and NetBSD).
* src/systems.h [!HAVE_STRUCT_STAT_ST_MTIM]: Use st_mtimespec if
available.
* src/gdbmshell.c (print_snapshot): Fall back to st_mtime if nanosecond
precision is not available.
* src/gdbmsync.c (timespec_cmp): Take two pointers to struct stat as
arguments. Use the right time field, depending on the configuration
settings. All uses changed.
Diffstat (limited to 'src/gdbmsync.c')
-rw-r--r-- | src/gdbmsync.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/gdbmsync.c b/src/gdbmsync.c index d8fe369..ed20ef7 100644 --- a/src/gdbmsync.c +++ b/src/gdbmsync.c @@ -220,16 +220,23 @@ gdbm_failure_atomic (GDBM_FILE dbf, const char *even, const char *odd) } static inline int -timespec_cmp (struct timespec const *a, struct timespec const *b) +timespec_cmp (struct stat const *a, struct stat const *b) { - if (a->tv_sec < b->tv_sec) +#if HAVE_STRUCT_STAT_ST_MTIM + if (a->st_mtim.tv_sec < b->st_mtim.tv_sec) return -1; - if (a->tv_sec > b->tv_sec) + if (a->st_mtim.tv_sec > b->st_mtim.tv_sec) return 1; - if (a->tv_nsec < b->tv_nsec) + if (a->st_mtim.tv_nsec < b->st_mtim.tv_nsec) return -1; - if (a->tv_nsec > b->tv_nsec) + if (a->st_mtim.tv_nsec > b->st_mtim.tv_nsec) return 1; +#else + if (a->st_mtime < b->st_mtime) + return -1; + if (a->st_mtime > b->st_mtime) + return 1; +#endif return 0; } @@ -374,7 +381,7 @@ gdbm_latest_snapshot (const char *even, const char *odd, const char **ret) * Select the newer snapshot, i.e. the one whose mtime * is greater than the other's */ - switch (timespec_cmp (&st_even.st_mtim, &st_odd.st_mtim)) + switch (timespec_cmp (&st_even, &st_odd)) { case -1: *ret = odd; |