From f19ffcc6b7f72f66d1c50e48cac1abf21a9db1c2 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 22 Apr 2010 09:52:26 -0400 Subject: [PATCH] Add timespec2timeval and use it when getting ctime/mtime --- config.h.in | 25 +++++++++++++++---------- configure.in | 19 ++++++++++++------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/config.h.in b/config.h.in index 3af0be749..223593879 100644 --- a/config.h.in +++ b/config.h.in @@ -538,13 +538,13 @@ /* Define to 1 if you have the header file. */ #undef HAVE_TERMIO_H -/* Define to 1 if you have struct timespec in sys/time.h */ -#undef HAVE_TIMESPEC - -/* Define to 1 if you have a timespecsub macro or function that takes two +/* Define to 1 if you have a timersub macro or function that takes two arguments (not three) */ #undef HAVE_TIMERSUB2 +/* Define to 1 if you have struct timespec in sys/time.h */ +#undef HAVE_TIMESPEC + /* Define to 1 if you have the `tzset' function. */ #undef HAVE_TZSET @@ -780,18 +780,23 @@ /* * Macros to convert ctime and mtime into timevals. */ +#define timespec2timeval(_ts, _tv) do { \ + (_tv)->tv_sec = (_ts)->tv_sec; \ + (_tv)->tv_usec = (_ts)->tv_nsec / 1000; \ +} while (0) + #ifdef HAVE_ST_MTIM # ifdef HAVE_ST__TIM -# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctim.st__tim.tv_sec; (_y)->tv_usec = (_x)->st_ctim.st__tim.tv_nsec / 1000; } while (0) -# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtim.st__tim.tv_sec; (_y)->tv_usec = (_x)->st_mtim.st__tim.tv_nsec / 1000; } while (0) +# define ctim_get(_x, _y) timespec2timeval(&(_x)->st_ctim.st__tim, (_y)) +# define mtim_get(_x, _y) timespec2timeval(&(_x)->st_mtim.st__tim, (_y)) # else -# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctim.tv_sec; (_y)->tv_usec = (_x)->st_ctim.tv_nsec / 1000; } while (0) -# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtim.tv_sec; (_y)->tv_usec = (_x)->st_mtim.tv_nsec / 1000; } while (0) +# define ctim_get(_x, _y) timespec2timeval(&(_x)->st_ctim, (_y)) +# define mtim_get(_x, _y) timespec2timeval(&(_x)->st_mtim, (_y)) # endif #else # ifdef HAVE_ST_MTIMESPEC -# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctimespec.tv_sec; (_y)->tv_usec = (_x)->st_ctimespec.tv_nsec / 1000; } while (0) -# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtimespec.tv_sec; (_y)->tv_usec = (_x)->st_mtimespec.tv_nsec / 1000; } while (0) +# define ctim_get(_x, _y) timespec2timeval(&(_x)->st_ctimespec, (_y)) +# define mtim_get(_x, _y) timespec2timeval(&(_x)->st_mtimespec, (_y)) # else # define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctime; (_y)->tv_usec = 0; } while (0) # define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtime; (_y)->tv_usec = 0; } while (0) diff --git a/configure.in b/configure.in index ab6d9f5d4..0c93e62b9 100644 --- a/configure.in +++ b/configure.in @@ -2790,7 +2790,7 @@ AH_TEMPLATE(HAVE_ST_MTIM, [Define to 1 if your struct stat has an st_mtim member AH_TEMPLATE(HAVE_ST_MTIMESPEC, [Define to 1 if your struct stat has an st_mtimespec member]) AH_TEMPLATE(HAVE_TERMIOS_H, [Define to 1 if you have the header file and the `tcgetattr' function.]) AH_TEMPLATE(HAVE_TIMESPEC, [Define to 1 if you have struct timespec in sys/time.h]) -AH_TEMPLATE(HAVE_TIMESPECSUB2, [Define to 1 if you have a timespecsub macro or function that takes two arguments (not three)]) +AH_TEMPLATE(HAVE_TIMERSUB2, [Define to 1 if you have a timersub macro or function that takes two arguments (not three)]) AH_TEMPLATE(HAVE___PROGNAME, [Define to 1 if your crt0.o defines the __progname symbol for you.]) AH_TEMPLATE(HOST_IN_LOG, [Define to 1 if you want the hostname to be entered into the log file.]) AH_TEMPLATE(IGNORE_DOT_PATH, [Define to 1 if you want to ignore '.' and empty PATH elements]) @@ -2827,18 +2827,23 @@ AH_TOP([#ifndef _SUDO_CONFIG_H AH_BOTTOM([/* * Macros to convert ctime and mtime into timevals. */ +#define timespec2timeval(_ts, _tv) do { \ + (_tv)->tv_sec = (_ts)->tv_sec; \ + (_tv)->tv_usec = (_ts)->tv_nsec / 1000; \ +} while (0) + #ifdef HAVE_ST_MTIM # ifdef HAVE_ST__TIM -# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctim.st__tim.tv_sec; (_y)->tv_usec = (_x)->st_ctim.st__tim.tv_nsec / 1000; } while (0) -# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtim.st__tim.tv_sec; (_y)->tv_usec = (_x)->st_mtim.st__tim.tv_nsec / 1000; } while (0) +# define ctim_get(_x, _y) timespec2timeval(&(_x)->st_ctim.st__tim, (_y)) +# define mtim_get(_x, _y) timespec2timeval(&(_x)->st_mtim.st__tim, (_y)) # else -# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctim.tv_sec; (_y)->tv_usec = (_x)->st_ctim.tv_nsec / 1000; } while (0) -# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtim.tv_sec; (_y)->tv_usec = (_x)->st_mtim.tv_nsec / 1000; } while (0) +# define ctim_get(_x, _y) timespec2timeval(&(_x)->st_ctim, (_y)) +# define mtim_get(_x, _y) timespec2timeval(&(_x)->st_mtim, (_y)) # endif #else # ifdef HAVE_ST_MTIMESPEC -# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctimespec.tv_sec; (_y)->tv_usec = (_x)->st_ctimespec.tv_nsec / 1000; } while (0) -# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtimespec.tv_sec; (_y)->tv_usec = (_x)->st_mtimespec.tv_nsec / 1000; } while (0) +# define ctim_get(_x, _y) timespec2timeval(&(_x)->st_ctimespec, (_y)) +# define mtim_get(_x, _y) timespec2timeval(&(_x)->st_mtimespec, (_y)) # else # define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctime; (_y)->tv_usec = 0; } while (0) # define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtime; (_y)->tv_usec = 0; } while (0) -- 2.50.1