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

This commit is contained in:
sin 2013-08-31 23:04:49 +01:00
parent 355911f010
commit 428cd4fe84
6 changed files with 27 additions and 0 deletions

9
cp.c
View File

@ -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);

View File

@ -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]);

View File

@ -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) {

3
mv.c
View File

@ -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);

4
rm.c
View File

@ -26,6 +26,10 @@ main(int argc, char *argv[])
default:
usage();
} ARGEND;
if (argc < 1)
usage();
for(; argc > 0; argc--, argv++)
rm(argv[0]);

View File

@ -35,6 +35,10 @@ main(int argc, char *argv[])
default:
usage();
} ARGEND;
if (argc < 1)
usage();
for(; argc > 0; argc--, argv++)
touch(argv[0]);