return r;
}
+const struct kmod_ext kmod_exts[] = {
+ {".ko", sizeof(".ko") - 1},
+#ifdef ENABLE_ZLIB
+ {".ko.gz", sizeof(".ko.gz") - 1},
+#endif
+#ifdef ENABLE_XZ
+ {".ko.xz", sizeof(".ko.xz") - 1},
+#endif
+ {NULL, 0},
+};
+
+int path_ends_with_kmod_ext(const char *path, size_t len)
+{
+ const struct kmod_ext *eitr;
+
+ for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
+ if (len <= eitr->len)
+ continue;
+ if (streq(path + len - eitr->len, eitr->ext))
+ return true;
+ }
+
+ return false;
+}
+
#define USEC_PER_SEC 1000000ULL
#define NSEC_PER_USEC 1000ULL
unsigned long long ts_usec(const struct timespec *ts)
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)));
+
+extern const struct kmod_ext {
+ const char *ext;
+ size_t len;
+} kmod_exts[];
+#define KMOD_EXT_UNC 0
+int path_ends_with_kmod_ext(const char *path, size_t len) __attribute__((nonnull(1)));
+
unsigned long long stat_mstamp(const struct stat *st);
unsigned long long ts_usec(const struct timespec *ts);
#define DEFAULT_VERBOSE LOG_WARNING
static int verbose = DEFAULT_VERBOSE;
-#define KMOD_EXT_UNC 0
-
-static const struct kmod_ext {
- const char *ext;
- size_t len;
-} kmod_exts[] = {
- {".ko", sizeof(".ko") - 1},
-#ifdef ENABLE_ZLIB
- {".ko.gz", sizeof(".ko.gz") - 1},
-#endif
-#ifdef ENABLE_XZ
- {".ko.xz", sizeof(".ko.xz") - 1},
-#endif
- {NULL, 0},
-};
-
static const char CFG_BUILTIN_KEY[] = "built-in";
static const char *default_cfg_paths[] = {
"/run/depmod.d",
struct mod *mod;
const char *relpath;
char modname[PATH_MAX];
- const struct kmod_ext *eitr;
size_t modnamelen;
- uint8_t matches = 0;
int err;
- for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
- if (namelen <= eitr->len)
- continue;
- if (streq(path + baselen + namelen - eitr->len, eitr->ext)) {
- matches = 1;
- break;
- }
- }
- if (!matches)
+ if (!path_ends_with_kmod_ext(path, baselen + namelen))
return 0;
if (path_to_modname(path, modname, &modnamelen) == NULL) {
path);
closedir(subdir);
} else if (S_ISREG(st.st_mode)) {
- const struct kmod_ext *eitr;
- uint8_t matches = 0;
- for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
- if (namelen <= eitr->len)
- continue;
- if (streq(name + namelen - eitr->len, eitr->ext)) {
- matches = 1;
- break;
- }
- }
- if (!matches)
+ if (!path_ends_with_kmod_ext(path, namelen))
continue;
memcpy(path + baselen, name, namelen + 1);
err = st.st_mtime <= mtime;
#include <sys/utsname.h>
#include <sys/stat.h>
#include "libkmod.h"
+#include "libkmod-util.h"
#include "kmod.h"
static bool is_module_filename(const char *name)
{
struct stat st;
- const char *ptr;
if (stat(name, &st) == 0 && S_ISREG(st.st_mode) &&
- (ptr = strstr(name, ".ko")) != NULL) {
- /*
- * We screened for .ko; make sure this is either at the end of
- * the name or followed by another '.' (e.g. gz or xz modules)
- */
- if(ptr[3] == '\0' || ptr[3] == '.')
+ path_ends_with_kmod_ext(name, strlen(name)))
return true;
- }
return false;
}