[hackers] [sbase] None of these work without the proper # of arguments so print usage || sin

From: <git_AT_suckless.org>
Date: Sat, 05 Oct 2013 16:29:21 +0200

commit 428cd4fe842b87a5504e44b1f92cf30e1ed8a48f
Author: sin <sin_AT_2f30.org>
Date: Sat Aug 31 23:04:49 2013 +0100

    None of these work without the proper # of arguments so print usage

diff --git a/cp.c b/cp.c
index 7e18220..50a57d9 100644
--- a/cp.c
+++ b/cp.c
_AT_@ -5,6 +5,12 @@
 #include "fs.h"
 #include "util.h"
 
+static void
+usage(void)
+{
+ eprintf("usage: %s source... dest
", argv0);
+}
+
 int
 main(int argc, char *argv[])
 {
_AT_@ -18,6 +24,9 @@ main(int argc, char *argv[])
                 exit(EXIT_FAILURE);
         } ARGEND;
 
+ if (argc < 2)
+ usage();
+
         if(argc > 2 && !(stat(argv[argc-1], &st) == 0 && S_ISDIR(st.st_mode)))
                 eprintf("%s: not a directory
", argv[argc-1]);
         enmasse(argc, argv, cp);
diff --git a/mkdir.c b/mkdir.c
index 459cae5..a6eafa3 100644
--- a/mkdir.c
+++ b/mkdir.c
_AT_@ -29,6 +29,9 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
+ if (argc < 1)
+ usage();
+
         for(; argc > 0; argc--, argv++) {
                 if(pflag) {
                         mkdirp(argv[0]);
diff --git a/mkfifo.c b/mkfifo.c
index 406e532..447c7eb 100644
--- a/mkfifo.c
+++ b/mkfifo.c
_AT_@ -18,6 +18,10 @@ main(int argc, char *argv[])
         default:
                 usage();
         } ARGEND;
+
+ if (argc < 1)
+ usage();
+
         for(; argc > 0; argc--, argv++) {
                 if(mkfifo(argv[0], S_IRUSR|S_IWUSR|S_IRGRP|\
                                         S_IWGRP|S_IROTH|S_IWOTH) == -1) {
diff --git a/mv.c b/mv.c
index 1608118..5c54ce6 100644
--- a/mv.c
+++ b/mv.c
_AT_@ -25,6 +25,9 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
+ if (argc < 2)
+ usage();
+
         if(argc > 3 && !(stat(argv[argc-1], &st) == 0 && S_ISDIR(st.st_mode)))
                 eprintf("%s: not a directory
", argv[argc-1]);
         enmasse(argc, &argv[0], mv);
diff --git a/rm.c b/rm.c
index a9d02c1..725310c 100644
--- a/rm.c
+++ b/rm.c
_AT_@ -26,6 +26,10 @@ main(int argc, char *argv[])
         default:
                 usage();
         } ARGEND;
+
+ if (argc < 1)
+ usage();
+
         for(; argc > 0; argc--, argv++)
                 rm(argv[0]);
 
diff --git a/touch.c b/touch.c
index 0ac00e5..a1391a2 100644
--- a/touch.c
+++ b/touch.c
_AT_@ -35,6 +35,10 @@ main(int argc, char *argv[])
         default:
                 usage();
         } ARGEND;
+
+ if (argc < 1)
+ usage();
+
         for(; argc > 0; argc--, argv++)
                 touch(argv[0]);
 
Received on Sat Oct 05 2013 - 16:29:21 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 05 2013 - 16:36:27 CEST