]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
kmod-depmod: refactor extension matching array, support XZ.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Mon, 26 Dec 2011 15:19:07 +0000 (13:19 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 27 Dec 2011 14:09:17 +0000 (12:09 -0200)
move the extensions array match to global, conditionally add GZ and XZ
if the support is enabled.

tools/kmod-depmod.c

index 6755494b84a8b2001650618836837f1c596c99dc..388002c9742802d7efc4ff9b7847f7dc1a5a1f9f 100644 (file)
 #define DEFAULT_VERBOSE LOG_WARNING
 static int verbose = DEFAULT_VERBOSE;
 
+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",
@@ -1661,19 +1675,12 @@ static int depmod_modules_search_file(struct depmod *depmod, size_t baselen, siz
        struct kmod_module *kmod;
        struct mod *mod;
        const char *relpath, *modname;
-       const struct ext {
-               const char *ext;
-               size_t len;
-       } *eitr, exts[] = {
-               {".ko", sizeof(".ko") - 1},
-               {".ko.gz", sizeof(".ko.gz") - 1},
-               {NULL, 0},
-       };
+       const struct kmod_ext *eitr;
        size_t modnamelen;
        uint8_t matches = 0;
        int err = 0;
 
-       for (eitr = exts; eitr->ext != NULL; eitr++) {
+       for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
                if (namelen <= eitr->len)
                        continue;
                if (streq(path + baselen + namelen - eitr->len, eitr->ext)) {
@@ -2850,16 +2857,9 @@ 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 ext {
-                               const char *ext;
-                               size_t len;
-                       } *eitr, exts[] = {
-                               {".ko", sizeof(".ko") - 1},
-                               {".ko.gz", sizeof(".ko.gz") - 1},
-                               {NULL, 0},
-                       };
+                       const struct kmod_ext *eitr;
                        uint8_t matches = 0;
-                       for (eitr = exts; eitr->ext != NULL; eitr++) {
+                       for (eitr = kmod_exts; eitr->ext != NULL; eitr++) {
                                if (namelen <= eitr->len)
                                        continue;
                                if (streq(name + namelen - eitr->len, eitr->ext)) {