From b95d50bcc36ee6f94ef6d9eaa9715c66d6d7bfdd Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Thu, 12 Mar 2009 11:45:34 +0000 Subject: [PATCH] Enforce use of streq I don't mind either way, but if it is worth using streq() then we should be consistent and use it everywhere. Signed-off-by: Alan Jenkins . --- config_filter.c | 7 ++++--- depmod.c | 12 ++++++------ depmod.h | 3 --- modprobe.c | 34 +++++++++++++++++----------------- moduleops.c | 1 + rmmod.c | 2 +- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/config_filter.c b/config_filter.c index b9ff5a8..215732f 100644 --- a/config_filter.c +++ b/config_filter.c @@ -1,7 +1,8 @@ -#include "config_filter.h" - #include +#include "util.h" +#include "config_filter.h" + int config_filter(const char *name) { const char *const *p; @@ -38,7 +39,7 @@ int config_filter(const char *name) for (p = skip_suffix; *p; p++) { if (strlen(name) >= strlen(*p) && - strcmp(*p, strchr(name, 0) - strlen(*p)) == 0) + streq(*p, strchr(name, 0) - strlen(*p))) return 0; } diff --git a/depmod.c b/depmod.c index 0bac74e..1eee517 100644 --- a/depmod.c +++ b/depmod.c @@ -551,13 +551,13 @@ static int is_higher_priority(const char *newpath, const char *oldpath, * order */ for (ovtmp = overrides; ovtmp != NULL; ovtmp = ovtmp->next) { - if (strcmp(ovtmp->modfile, newpath) == 0) + if (streq(ovtmp->modfile, newpath)) return 1; - if (strcmp(ovtmp->modfile, oldpath) == 0) + if (streq(ovtmp->modfile, oldpath)) return 0; } for (i = 0, tmp = search; tmp != NULL; tmp = tmp->next, i++) { - if (strcmp(tmp->search_path, MODULE_BUILTIN_KEY) == 0) + if (streq(tmp->search_path, MODULE_BUILTIN_KEY)) prio_builtin = i; else if (strncmp(tmp->search_path, newpath, tmp->len) == 0) prio_new = i; @@ -696,7 +696,7 @@ static struct module *sort_modules(const char *dirname, struct module *list) line[len - 1] = '\0'; for (pos = &list; (mod = *pos); pos = &(*pos)->next) { - if (strcmp(line, mod->pathname + dir_len) == 0) { + if (streq(line, mod->pathname + dir_len)) { mod->order = linenum; *pos = mod->next; mod->next = NULL; @@ -1016,7 +1016,7 @@ static int parse_config_file(const char *filename, continue; } - if (strcmp(cmd, "search") == 0) { + if (streq(cmd, "search")) { char *search_path; while ((search_path = strsep_skipspace(&ptr, "\t "))) { @@ -1072,7 +1072,7 @@ static int parse_config_file(const char *filename, newfilename, strerror(errno)); } } - } else if (strcmp(cmd, "make_map_files") == 0) { + } else if (streq(cmd, "make_map_files")) { char *option; option = strsep_skipspace(&ptr, "\t "); diff --git a/depmod.h b/depmod.h index b9cc4b1..decdf2e 100644 --- a/depmod.h +++ b/depmod.h @@ -9,9 +9,6 @@ void add_symbol(const char *name, struct module *owner); struct module *find_symbol(const char *name, const char *modname, int weak); void add_dep(struct module *mod, struct module *depends_on); -/* I hate strcmp. */ -#define streq(a,b) (strcmp((a),(b)) == 0) - struct module { /* Next module in list of all modules */ diff --git a/modprobe.c b/modprobe.c index e4d6679..3f79cc0 100644 --- a/modprobe.c +++ b/modprobe.c @@ -80,7 +80,7 @@ static struct module *find_module(const char *filename, struct list_head *list) struct module *i; list_for_each_entry(i, list, list) { - if (strcmp(i->filename, filename) == 0) + if (streq(i->filename, filename)) return i; } return NULL; @@ -326,7 +326,7 @@ static void *get_section32(void *file, secnames = file + sechdrs[hdr->e_shstrndx].sh_offset; for (i = 1; i < hdr->e_shnum; i++) - if (strcmp(secnames + sechdrs[i].sh_name, name) == 0) { + if (streq(secnames + sechdrs[i].sh_name, name)) { *secsize = sechdrs[i].sh_size; return file + sechdrs[i].sh_offset; } @@ -353,7 +353,7 @@ static void *get_section64(void *file, secnames = file + sechdrs[hdr->e_shstrndx].sh_offset; for (i = 1; i < hdr->e_shnum; i++) - if (strcmp(secnames + sechdrs[i].sh_name, name) == 0) { + if (streq(secnames + sechdrs[i].sh_name, name)) { *secsize = sechdrs[i].sh_size; return file + sechdrs[i].sh_offset; } @@ -416,7 +416,7 @@ static void invalidate_section32(void *mod, const char *secname) unsigned int i; for (i = 1; i < hdr->e_shnum; i++) - if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) + if (streq(secnames+sechdrs[i].sh_name, secname)) sechdrs[i].sh_flags &= ~SHF_ALLOC; } @@ -428,7 +428,7 @@ static void invalidate_section64(void *mod, const char *secname) unsigned int i; for (i = 1; i < hdr->e_shnum; i++) - if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) + if (streq(secnames+sechdrs[i].sh_name, secname)) sechdrs[i].sh_flags &= ~(unsigned long long)SHF_ALLOC; } @@ -558,7 +558,7 @@ static int find_blacklist(const char *modname, const struct module_blacklist *blacklist) { while (blacklist) { - if (strcmp(blacklist->modulename, modname) == 0) + if (streq(blacklist->modulename, modname)) return 1; blacklist = blacklist->next; } @@ -627,7 +627,7 @@ static char *add_extra_options(const char *modname, const struct module_options *options) { while (options) { - if (strcmp(options->modulename, modname) == 0) + if (streq(options->modulename, modname)) optstring = prepend_option(optstring, options->options); options = options->next; } @@ -1073,7 +1073,7 @@ static int parse_config_file(const char *filename, continue; } - if (strcmp(cmd, "alias") == 0) { + if (streq(cmd, "alias")) { char *wildcard = strsep_skipspace(&ptr, "\t "); char *realname = strsep_skipspace(&ptr, "\t "); @@ -1081,7 +1081,7 @@ static int parse_config_file(const char *filename, grammar(cmd, filename, linenum); else if (fnmatch(underscores(wildcard),name,0) == 0) *aliases = add_alias(underscores(realname), *aliases); - } else if (strcmp(cmd, "include") == 0) { + } else if (streq(cmd, "include")) { struct module_alias *newalias = NULL; char *newfilename; @@ -1109,7 +1109,7 @@ static int parse_config_file(const char *filename, if (newalias) *aliases = newalias; } - } else if (strcmp(cmd, "options") == 0) { + } else if (streq(cmd, "options")) { modname = strsep_skipspace(&ptr, "\t "); if (!modname || !ptr) grammar(cmd, filename, linenum); @@ -1118,7 +1118,7 @@ static int parse_config_file(const char *filename, *options = add_options(underscores(modname), ptr, *options); } - } else if (strcmp(cmd, "install") == 0) { + } else if (streq(cmd, "install")) { modname = strsep_skipspace(&ptr, "\t "); if (!modname || !ptr) grammar(cmd, filename, linenum); @@ -1127,7 +1127,7 @@ static int parse_config_file(const char *filename, *commands = add_command(underscores(modname), ptr, *commands); } - } else if (strcmp(cmd, "blacklist") == 0) { + } else if (streq(cmd, "blacklist")) { modname = strsep_skipspace(&ptr, "\t "); if (!modname) grammar(cmd, filename, linenum); @@ -1135,7 +1135,7 @@ static int parse_config_file(const char *filename, *blacklist = add_blacklist(underscores(modname), *blacklist); } - } else if (strcmp(cmd, "remove") == 0) { + } else if (streq(cmd, "remove")) { modname = strsep_skipspace(&ptr, "\t "); if (!modname || !ptr) grammar(cmd, filename, linenum); @@ -1144,16 +1144,16 @@ static int parse_config_file(const char *filename, *commands = add_command(underscores(modname), ptr, *commands); } - } else if (strcmp(cmd, "config") == 0) { + } else if (streq(cmd, "config")) { char *tmp = strsep_skipspace(&ptr, "\t "); if (!tmp) grammar(cmd, filename, linenum); - else if (strcmp(tmp, "binary_indexes") == 0) { + else if (streq(tmp, "binary_indexes")) { tmp = strsep_skipspace(&ptr, "\t "); - if (strcmp(tmp, "yes") == 0) + if (streq(tmp, "yes")) use_binary_indexes = 1; - if (strcmp(tmp, "no") == 0) + if (streq(tmp, "no")) use_binary_indexes = 0; } } else diff --git a/moduleops.c b/moduleops.c index fe09f86..1ee52be 100644 --- a/moduleops.c +++ b/moduleops.c @@ -6,6 +6,7 @@ #include #include #include "depmod.h" +#include "util.h" #include "logging.h" #include "moduleops.h" #include "tables.h" diff --git a/rmmod.c b/rmmod.c index 357a90d..7ef2e31 100644 --- a/rmmod.c +++ b/rmmod.c @@ -48,7 +48,7 @@ static void mod_in_use(const char *modname, char *usedby) { /* New /proc/modules uses a single "-" to mean "nothing". Old one just puts nothing there. */ - if (usedby[0] == '-' || strcmp(usedby, "") == 0) { + if (usedby[0] == '-' || streq(usedby, "")) { error("Module %s is in use\n", modname); return; } -- 2.11.4.GIT