From: Lucas De Marchi Date: Tue, 17 Jan 2012 14:10:42 +0000 (-0200) Subject: Check if struct stat has mtim member X-Git-Tag: v5~87 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6068aaaea8e7cdc6039e6fd7a1aeab9db9d0225b;p=thirdparty%2Fkmod.git Check if struct stat has mtim member Not all libc's have a mtim member in struct stat (dietlibc doesn't). Change ts_usec() to receive a struct stat as parameter and implement it accordingly for both cases. --- diff --git a/configure.ac b/configure.ac index 66c2d51a..19f78d52 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,9 @@ AS_IF([test "x$enable_debug" = "xyes"], [ AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.]) ]) +# dietlibc doesn't have st.st_mtim struct member +AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include ]) + CC_CHECK_CFLAGS_APPEND([ \ -pipe \ -DANOTHER_BRICK_IN_THE \ @@ -125,7 +128,6 @@ CC_CHECK_CFLAGS_APPEND([ \ -Wl,--as-needed \ -Wl,--gc-sections]) - AC_CONFIG_HEADERS(config.h) AC_CONFIG_FILES([ Makefile diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index c1da16fc..f970f9e1 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -795,7 +795,7 @@ static int conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list, return err; } - *path_stamp = ts_usec(&st.st_mtim); + *path_stamp = stat_mstamp(&st); if (S_ISREG(st.st_mode)) { conf_files_insert_sorted(ctx, list, path, NULL); diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index 9d3b9395..c1c3c994 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -830,7 +830,7 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, idx->ctx = ctx; close(fd); - *stamp = ts_usec(&st.st_mtim); + *stamp = stat_mstamp(&st); return idx; diff --git a/libkmod/libkmod-util.c b/libkmod/libkmod-util.c index 7c2611b3..9a662b6e 100644 --- a/libkmod/libkmod-util.c +++ b/libkmod/libkmod-util.c @@ -341,8 +341,12 @@ char *path_make_absolute_cwd(const char *p) #define USEC_PER_SEC 1000000ULL #define NSEC_PER_USEC 1000ULL -unsigned long long ts_usec(const struct timespec *ts) +unsigned long long stat_mstamp(const struct stat *st) { - return (unsigned long long) ts->tv_sec * USEC_PER_SEC + - (unsigned long long) ts->tv_nsec / NSEC_PER_USEC; +#ifdef HAVE_STRUCT_STAT_ST_MTIM + return (unsigned long long) st->st_mtim.tv_sec * USEC_PER_SEC + + (unsigned long long) st->st_mtim.tv_nsec / NSEC_PER_USEC; +#else + return (unsigned long long) st->st_mtime; +#endif } diff --git a/libkmod/libkmod-util.h b/libkmod/libkmod-util.h index c9a1a218..317b2f71 100644 --- a/libkmod/libkmod-util.h +++ b/libkmod/libkmod-util.h @@ -24,6 +24,6 @@ char *path_make_absolute_cwd(const char *p) __must_check __attribute__((nonnull( int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) __must_check __attribute__((nonnull(1,2))); char *modname_normalize(const char *modname, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(1, 2))); char *path_to_modname(const char *path, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(2))); -unsigned long long ts_usec(const struct timespec *ts); +unsigned long long stat_mstamp(const struct stat *st); #endif diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index 91fdf7b6..5edd594e 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -620,7 +620,7 @@ static bool is_cache_invalid(const char *path, unsigned long long stamp) if (stat(path, &st) < 0) return true; - if (stamp != ts_usec(&st.st_mtim)) + if (stamp != stat_mstamp(&st)) return true; return false;