sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 428cd4fe842b87a5504e44b1f92cf30e1ed8a48f
parent 355911f01067b32778cd61d20ae221c78278e47c
Author: sin <sin@2f30.org>
Date:   Sat, 31 Aug 2013 23:04:49 +0100

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

Diffstat:
cp.c | 9+++++++++
mkdir.c | 3+++
mkfifo.c | 4++++
mv.c | 3+++
rm.c | 4++++
touch.c | 4++++
6 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/cp.c b/cp.c @@ -5,6 +5,12 @@ #include "fs.h" #include "util.h" +static void +usage(void) +{ + eprintf("usage: %s source... dest\n", argv0); +} + int main(int argc, char *argv[]) { @@ -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\n", argv[argc-1]); enmasse(argc, argv, cp); diff --git a/mkdir.c b/mkdir.c @@ -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 @@ -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 @@ -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\n", argv[argc-1]); enmasse(argc, &argv[0], mv); diff --git a/rm.c b/rm.c @@ -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 @@ -35,6 +35,10 @@ main(int argc, char *argv[]) default: usage(); } ARGEND; + + if (argc < 1) + usage(); + for(; argc > 0; argc--, argv++) touch(argv[0]);