]> git.ipfire.org Git - thirdparty/kmod.git/blobdiff - tools/depmod.c
fix is_module_filename()
[thirdparty/kmod.git] / tools / depmod.c
index 7bbdcd353e6319250a36ca6153770aabfb676950..de773918ae788c73daa7a30c96d36a28da227bc9 100644 (file)
 #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",
@@ -1204,20 +1188,10 @@ static int depmod_modules_search_file(struct depmod *depmod, size_t baselen, siz
        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) {
@@ -2413,17 +2387,7 @@ static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *pa
                                                     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;