From 5a7c16cef9dd7e351d89be06a770efc7a4c5347a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 20 Feb 2012 20:20:12 -0600 Subject: 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. --- toys/lsmod.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'toys/lsmod.c') 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); } -- cgit v1.2.3