[hackers] [ubase] swapon, swapoff: show usage with -a device || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Fri, 6 Feb 2015 16:16:29 +0100 (CET)

commit faa6fe28e2fabf39a8160dda6438033775d887b2
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri Feb 6 15:20:41 2015 +0100

    swapon, swapoff: show usage with -a device
    
    ... and small cleanup.

diff --git a/swapoff.c b/swapoff.c
index 93a77f1..5f32e9d 100644
--- a/swapoff.c
+++ b/swapoff.c
_AT_@ -11,7 +11,7 @@
 static void
 usage(void)
 {
- eprintf("usage: %s [-a] device\n", argv0);
+ eprintf("usage: %s -a | device\n", argv0);
 }
 
 int
_AT_@ -20,6 +20,8 @@ main(int argc, char *argv[])
         int i;
         int ret = 0;
         int all = 0;
+ struct mntent *me;
+ FILE *fp;
 
         ARGBEGIN {
         case 'a':
_AT_@ -29,13 +31,10 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- if (!all && argc < 1)
+ if ((!all && argc < 1) || (all && argc > 0))
                 usage();
 
         if (all) {
- struct mntent *me = NULL;
- FILE *fp;
-
                 fp = setmntent("/etc/fstab", "r");
                 if (!fp)
                         eprintf("setmntent %s:", "/etc/fstab");
diff --git a/swapon.c b/swapon.c
index ef31a50..672c64e 100644
--- a/swapon.c
+++ b/swapon.c
_AT_@ -11,7 +11,7 @@
 static void
 usage(void)
 {
- eprintf("usage: %s [-dp] [-a] device\n", argv0);
+ eprintf("usage: %s [-dp] -a | device\n", argv0);
 }
 
 int
_AT_@ -21,6 +21,8 @@ main(int argc, char *argv[])
         int ret = 0;
         int flags = 0;
         int all = 0;
+ struct mntent *me;
+ FILE *fp;
 
         ARGBEGIN {
         case 'a':
_AT_@ -36,13 +38,10 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- if (!all && argc < 1)
+ if ((!all && argc < 1) || (all && argc > 0))
                 usage();
 
         if (all) {
- struct mntent *me = NULL;
- FILE *fp;
-
                 fp = setmntent("/etc/fstab", "r");
                 if (!fp)
                         eprintf("setmntent %s:", "/etc/fstab");
Received on Fri Feb 06 2015 - 16:16:29 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 06 2015 - 16:24:24 CET