s/getopt/ARGBEGIN/ and -r bug fix cp

This commit is contained in:
Federico G. Benavento 2013-03-10 21:59:22 -03:00
parent 5c7b7e3fa8
commit e509d56bae

12
cp.c
View File

@ -1,7 +1,6 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "fs.h" #include "fs.h"
#include "util.h" #include "util.h"
@ -10,18 +9,17 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
struct stat st; struct stat st;
char c;
while((c = getopt(argc, argv, "r")) != -1) ARGBEGIN {
switch(c) {
case 'r': case 'r':
cp_rflag = true; cp_rflag = true;
break; break;
default: default:
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} } ARGEND;
if(argc > 3 && !cp_rflag && !(stat(argv[argc-1], &st) == 0 && S_ISDIR(st.st_mode)))
if(argc > 2 && !(stat(argv[argc-1], &st) == 0 && S_ISDIR(st.st_mode)))
eprintf("%s: not a directory\n", argv[argc-1]); eprintf("%s: not a directory\n", argv[argc-1]);
enmasse(argc - optind, &argv[optind], cp); enmasse(argc, argv, cp);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }