diff --git a/common/sudo_debug.c b/common/sudo_debug.c index ed842bc62..b2d98ca6d 100644 --- a/common/sudo_debug.c +++ b/common/sudo_debug.c @@ -52,6 +52,7 @@ #include "fatal.h" #include "sudo_plugin.h" #include "sudo_debug.h" +#include "sudo_util.h" #define DEFAULT_TEXT_DOMAIN "sudo" #include "gettext.h" diff --git a/config.h.in b/config.h.in index 301695c40..b392f1de6 100644 --- a/config.h.in +++ b/config.h.in @@ -1112,41 +1112,6 @@ code using `volatile' can become incorrect without. Disable with care. */ #undef volatile -/* - * 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) 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) 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) 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) -# endif /* HAVE_ST_MTIMESPEC */ -#endif /* HAVE_ST_MTIM */ - -#ifdef __GNUC__ -# define ignore_result(x) do { \ - __typeof__(x) y = (x); \ - (void)y; \ -} while(0) -#else -# define ignore_result(x) (void)(x) -#endif - /* BSD compatibility on some SVR4 systems. */ #ifdef __svr4__ # define BSD_COMP diff --git a/include/sudo_util.h b/include/sudo_util.h index b1c0fce97..519d84490 100644 --- a/include/sudo_util.h +++ b/include/sudo_util.h @@ -103,6 +103,39 @@ } while (0) #endif +/* + * Macros to extract ctime and mtime as timevals. + */ +#ifdef HAVE_ST_MTIM +# ifdef HAVE_ST__TIM +# define ctim_get(_x, _y) TIMESPEC_TO_TIMEVAL((_y), &(_x)->st_ctim.st__tim) +# define mtim_get(_x, _y) TIMESPEC_TO_TIMEVAL((_y), &(_x)->st_mtim.st__tim) +# else +# define ctim_get(_x, _y) TIMESPEC_TO_TIMEVAL((_y), &(_x)->st_ctim) +# define mtim_get(_x, _y) TIMESPEC_TO_TIMEVAL((_y), &(_x)->st_mtim) +# endif +#else +# ifdef HAVE_ST_MTIMESPEC +# define ctim_get(_x, _y) TIMESPEC_TO_TIMEVAL((_y), &(_x)->st_ctimespec) +# define mtim_get(_x, _y) TIMESPEC_TO_TIMEVAL((_y), &(_x)->st_mtimespec) +# 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) +# endif /* HAVE_ST_MTIMESPEC */ +#endif /* HAVE_ST_MTIM */ + +/* + * Macros to quiet gcc's warn_unused_result attribute. + */ +#ifdef __GNUC__ +# define ignore_result(x) do { \ + __typeof__(x) y = (x); \ + (void)y; \ +} while(0) +#else +# define ignore_result(x) (void)(x) +#endif + /* aix.c */ void aix_prep_user(char *user, const char *tty); void aix_restoreauthdb(void); diff --git a/plugins/sample/sample_plugin.c b/plugins/sample/sample_plugin.c index f1d6392e7..202f9bf2e 100644 --- a/plugins/sample/sample_plugin.c +++ b/plugins/sample/sample_plugin.c @@ -55,6 +55,7 @@ #include #include "sudo_plugin.h" +#include "sudo_util.h" #include "missing.h" /*