diff options
Diffstat (limited to 'toys')
-rw-r--r-- | toys/lsmod.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/toys/lsmod.c b/toys/lsmod.c index 7f588c8a..41bea371 100644 --- a/toys/lsmod.c +++ b/toys/lsmod.c @@ -6,7 +6,7 @@ * * Not in SUSv4. -USE_FREE(NEWTOY(lsmod, NULL, TOYFLAG_BIN)) +USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_BIN)) config LSMOD bool "lsmod" @@ -22,28 +22,25 @@ config LSMOD void lsmod_main(void) { - FILE * file = fopen("/proc/modules", "r"); - char *name, *size, *refcnt, *users; - if (!file) - perror_exit("cannot open /proc/moduls"); + FILE * file = xfopen("/proc/modules", "r"); + char *name, *size, *refcnt, *users; - xprintf("%-24s Size Used by\n", "Module"); + xprintf("%-24s Size Used by\n", "Module"); - while (fgets(toybuf, sizeof(toybuf), file)) { - int len; - name = strtok(toybuf, " "); - size = strtok(NULL, " "); + while (fgets(toybuf, sizeof(toybuf), file)) { + int len; + + name = strtok(toybuf, " "); + size = strtok(NULL, " "); refcnt = strtok(NULL, " "); users = strtok(NULL, " "); + if(name && size && refcnt && users) { len = strlen(users)-1; if (users[len] == ',' || users[len] == '-') users[len] = 0; xprintf("%-20s %8s %s %s\n", name, size, refcnt, users); - } else { - perror_exit("unrecognized input"); - break; - } + } else perror_exit("unrecognized input"); } fclose(file); } |