diff options
author | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-12-12 11:52:59 -0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-12-12 11:52:59 -0200 |
commit | 28c175edd10eb778c706fb133a40150cf1a58054 (patch) | |
tree | 5d42949895affa82c0069dee917935ce335a7cd7 /libkmod | |
parent | c35347f15cf0ed71a0929ddb0a0d8e2de5f73de8 (diff) | |
download | kmod-28c175edd10eb778c706fb133a40150cf1a58054.tar.gz |
coding style: be consistent with blank lines
Diffstat (limited to 'libkmod')
-rw-r--r-- | libkmod/libkmod-config.c | 2 | ||||
-rw-r--r-- | libkmod/libkmod-module.c | 27 | ||||
-rw-r--r-- | libkmod/libkmod-util.c | 11 |
3 files changed, 39 insertions, 1 deletions
diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index 2b3222d..c98bab9 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -179,6 +179,7 @@ static int kmod_config_add_alias(struct kmod_config *config, alias = malloc(sizeof(*alias) + namelen + modnamelen); if (!alias) goto oom_error_init; + alias->name = sizeof(*alias) + modnamelen + (char *)alias; memcpy(alias->modname, modname, modnamelen); @@ -187,6 +188,7 @@ static int kmod_config_add_alias(struct kmod_config *config, list = kmod_list_append(config->aliases, alias); if (!list) goto oom_error; + config->aliases = list; return 0; diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index ce01dc3..500193d 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -74,6 +74,7 @@ inline char *modname_normalize(const char *modname, char buf[NAME_MAX], else buf[s] = c; } + buf[s] = '\0'; if (len) @@ -133,6 +134,7 @@ int kmod_module_parse_depline(struct kmod_module *mod, char *line) dirnamelen = strlen(dirname); if (dirnamelen + 2 >= PATH_MAX) return 0; + memcpy(buf, dirname, dirnamelen); buf[dirnamelen] = '/'; dirnamelen++; @@ -410,6 +412,7 @@ KMOD_EXPORT struct kmod_module *kmod_module_get_module(const struct kmod_list *e { if (entry == NULL) return NULL; + return kmod_module_ref(entry->data); } @@ -730,6 +733,7 @@ KMOD_EXPORT struct kmod_list *kmod_module_get_sections(const struct kmod_module if (mod == NULL) return NULL; + snprintf(dname, sizeof(dname), "/sys/module/%s/sections", mod->name); d = opendir(dname); @@ -771,7 +775,6 @@ KMOD_EXPORT struct kmod_list *kmod_module_get_sections(const struct kmod_module err = read_str_ulong(fd, &address, 16); close(fd); - if (err < 0) { ERR(mod->ctx, "could not read long from '%s/%s': %m\n", dname, de.d_name); @@ -811,8 +814,10 @@ fail: KMOD_EXPORT const char *kmod_module_section_get_name(const struct kmod_list *entry) { struct kmod_module_section *section; + if (entry == NULL) return NULL; + section = entry->data; return section->name; } @@ -820,8 +825,10 @@ KMOD_EXPORT const char *kmod_module_section_get_name(const struct kmod_list *ent KMOD_EXPORT unsigned long kmod_module_section_get_address(const struct kmod_list *entry) { struct kmod_module_section *section; + if (entry == NULL) return (unsigned long)-1; + section = entry->data; return section->address; } @@ -845,7 +852,9 @@ KMOD_EXPORT const char *kmod_module_get_options(const struct kmod_module *mod) const struct kmod_list *l, *ctx_options; char *opts = NULL; size_t optslen = 0; + ctx_options = kmod_get_options(mod->ctx); + kmod_list_foreach(l, ctx_options) { const char *modname = kmod_option_get_modname(l); const char *str; @@ -865,15 +874,19 @@ KMOD_EXPORT const char *kmod_module_get_options(const struct kmod_module *mod) free(opts); goto failed; } + opts = tmp; + if (optslen > 0) { opts[optslen] = ' '; optslen++; } + memcpy(opts + optslen, str, len); optslen += len; opts[optslen] = '\0'; } + m->init.options = true; m->options = opts; } @@ -896,7 +909,9 @@ KMOD_EXPORT const char *kmod_module_get_install_commands(const struct kmod_modul const struct kmod_list *l, *ctx_install_commands; char *cmds = NULL; size_t cmdslen = 0; + ctx_install_commands = kmod_get_install_commands(mod->ctx); + kmod_list_foreach(l, ctx_install_commands) { const char *modname = kmod_command_get_modname(l); const char *str; @@ -916,15 +931,19 @@ KMOD_EXPORT const char *kmod_module_get_install_commands(const struct kmod_modul free(cmds); goto failed; } + cmds = tmp; + if (cmdslen > 0) { cmds[cmdslen] = ';'; cmdslen++; } + memcpy(cmds + cmdslen, str, len); cmdslen += len; cmds[cmdslen] = '\0'; } + m->init.install_commands = true; m->install_commands = cmds; } @@ -947,7 +966,9 @@ KMOD_EXPORT const char *kmod_module_get_remove_commands(const struct kmod_module const struct kmod_list *l, *ctx_remove_commands; char *cmds = NULL; size_t cmdslen = 0; + ctx_remove_commands = kmod_get_remove_commands(mod->ctx); + kmod_list_foreach(l, ctx_remove_commands) { const char *modname = kmod_command_get_modname(l); const char *str; @@ -967,15 +988,19 @@ KMOD_EXPORT const char *kmod_module_get_remove_commands(const struct kmod_module free(cmds); goto failed; } + cmds = tmp; + if (cmdslen > 0) { cmds[cmdslen] = ';'; cmdslen++; } + memcpy(cmds + cmdslen, str, len); cmdslen += len; cmds[cmdslen] = '\0'; } + m->init.remove_commands = true; m->remove_commands = cmds; } diff --git a/libkmod/libkmod-util.c b/libkmod/libkmod-util.c index 9a68a3e..40b7ada 100644 --- a/libkmod/libkmod-util.c +++ b/libkmod/libkmod-util.c @@ -45,6 +45,7 @@ char *getline_wrapped(FILE *fp, unsigned int *linenum) int size = 256; int i = 0; char *buf = malloc(size); + for(;;) { int ch = getc_unlocked(fp); @@ -147,8 +148,10 @@ inline void *memdup(const void *p, size_t n) ssize_t read_str_safe(int fd, char *buf, size_t buflen) { size_t todo = buflen; size_t done; + do { ssize_t r = read(fd, buf, todo); + if (r == 0) break; else if (r > 0) @@ -161,7 +164,9 @@ ssize_t read_str_safe(int fd, char *buf, size_t buflen) { return -errno; } } while (todo > 0); + done = buflen - todo; + if (done == 0) buf[0] = '\0'; else { @@ -170,6 +175,7 @@ ssize_t read_str_safe(int fd, char *buf, size_t buflen) { else if (buf[done - 1] != '\0') return -ENOSPC; } + return done; } @@ -177,6 +183,7 @@ int read_str_long(int fd, long *value, int base) { char buf[32], *end; long v; int err; + *value = 0; err = read_str_safe(fd, buf, sizeof(buf)); if (err < 0) @@ -185,6 +192,7 @@ int read_str_long(int fd, long *value, int base) { v = strtol(buf, &end, base); if (end == buf || !isspace(*end)) return -EINVAL; + *value = v; return 0; } @@ -193,6 +201,7 @@ int read_str_ulong(int fd, unsigned long *value, int base) { char buf[32], *end; long v; int err; + *value = 0; err = read_str_safe(fd, buf, sizeof(buf)); if (err < 0) @@ -208,9 +217,11 @@ int read_str_ulong(int fd, unsigned long *value, int base) { char *strchr_replace(char *s, int c, char r) { char *p; + for (p = s; *p != '\0'; p++) if (*p == c) *p = r; + return s; } |