Mercurial > hg > toybox
changeset 486:43be4ef80ffe
Minor cleanups: lsmod should USE_LSMOD() instead of USE_FREE(), use consistent tab/space idents, and doesn't need a break after a function that exits.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 20 Feb 2012 20:20:12 -0600 |
parents | d5d51fd18679 |
children | 9c43d4191337 |
files | toys/lsmod.c |
diffstat | 1 files changed, 11 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/lsmod.c Sat Feb 18 09:44:53 2012 +0100 +++ b/toys/lsmod.c Mon Feb 20 20:20:12 2012 -0600 @@ -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 @@ 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; - while (fgets(toybuf, sizeof(toybuf), file)) { - int len; - name = strtok(toybuf, " "); - size = strtok(NULL, " "); + 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); }