[hackers] [sbase] s/getopt/ARGBEGIN/ and -r bug fix cp || Federico G. Benavento

From: <git_AT_suckless.org>
Date: Mon, 11 Mar 2013 02:00:02 +0100

commit e509d56bae7fd9799ae47d081d8b5dbaf6a3efe8
Author: Federico G. Benavento <benavento_AT_gmail.com>
Date: Sun Mar 10 21:59:22 2013 -0300

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

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

This archive was generated by hypermail 2.3.0 : Mon Mar 11 2013 - 02:12:05 CET