[PATCH] modinfo: fix argument parsing, and printing of firmware
Timo Teräs
timo.teras at iki.fi
Wed Oct 28 08:20:57 UTC 2015
getopt was missing a short option for 'firmware', thus the -F option
for specific keyword was flagged as last OPT_TAGS entry. This caused
"-F firmware" to print twice the firmware fields (once due to incorrectly
set OPT_TAGS and once for OPT_F) and incorrectly with the fieldname
prefix.
This adds -f as shortcut for "-F firmware" so that OPT_TAGS and OPT_F
are now set properly by getopt32(). This allows removing the incorrect
and unneeded OPT_F setting based on the keyword field.
function old new delta
modinfo_main 438 430 -8
modinfo 457 438 -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-27) Total: -27 bytes
text data bss dec hex filename
787574 15136 3656 806366 c4dde busybox_old
787547 15136 3656 806339 c4dc3 busybox_unstripped
Fixes: 772f17a843 "modinfo: match more standard module fields and fix version field"
Signed-off-by: Timo Teräs <timo.teras at iki.fi>
Cc: Tanguy Pruvot <tanguy.pruvot at gmail.com>
---
modutils/modinfo.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/modutils/modinfo.c b/modutils/modinfo.c
index 8e74b64..e2c9df3 100644
--- a/modutils/modinfo.c
+++ b/modutils/modinfo.c
@@ -31,7 +31,7 @@ enum {
struct modinfo_env {
char *field;
- int tags;
+ unsigned tags;
};
static void display(const char *data, const char *pattern, int flag)
@@ -62,11 +62,13 @@ static void modinfo(const char *path, const char *version,
"firmware",
};
size_t len;
- int j;
+ unsigned j;
char *ptr, *the_module;
const char *field = env->field;
- int tags = env->tags;
+ unsigned tags = env->tags;
+ if (!tags)
+ tags = OPT_TAGS;
if (tags & 1) { /* filename */
display(path, shortcuts[0], 1 != tags);
}
@@ -84,8 +86,6 @@ static void modinfo(const char *path, const char *version,
return;
}
- if (field)
- tags |= OPT_F;
for (j = 1; (1<<j) & (OPT_TAGS + OPT_F); j++) {
const char *pattern;
@@ -141,8 +141,8 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv)
env.field = NULL;
opt_complementary = "-1"; /* minimum one param */
- opts = getopt32(argv, "nladvAsDumpF:0", &env.field);
- env.tags = opts & OPT_TAGS ? opts & OPT_TAGS : OPT_TAGS;
+ opts = getopt32(argv, "nladvAsDumpfF:0", &env.field);
+ env.tags = opts & (OPT_TAGS + OPT_F);
argv += optind;
uname(&uts);
--
2.6.1
More information about the busybox
mailing list