aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-02-20 20:20:12 -0600
committerRob Landley <rob@landley.net>2012-02-20 20:20:12 -0600
commit5a7c16cef9dd7e351d89be06a770efc7a4c5347a (patch)
treea31dcee3fa4c6d4368170ef58014270f1d08a823
parent9e59c272039097a92cc11a8f248be9b5552b30c7 (diff)
downloadtoybox-5a7c16cef9dd7e351d89be06a770efc7a4c5347a.tar.gz
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.
-rw-r--r--toys/lsmod.c25
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);
}