summaryrefslogtreecommitdiff
path: root/cp_mv.c
diff options
context:
space:
mode:
authorEric Andersen2000-07-13 18:42:58 +0000
committerEric Andersen2000-07-13 18:42:58 +0000
commitf4c022649b73fcc05f4b8f7ae3dc7036f58de96d (patch)
treee7047c841eafc5a6c224ac1685f878ed377c26ef /cp_mv.c
parent55380700d884358c42ca8d286b36699fd3745480 (diff)
downloadbusybox-f4c022649b73fcc05f4b8f7ae3dc7036f58de96d.zip
busybox-f4c022649b73fcc05f4b8f7ae3dc7036f58de96d.tar.gz
Patch from Marc Nijdam <marc_nijdam@hp.com>
> First (of many more) patch of cp_mv to getopt use. I'm using the most > simplistic approach, just get getopt used, then worry about a cleaner > option parsing style using getopt later. > > Marc
Diffstat (limited to 'cp_mv.c')
-rw-r--r--cp_mv.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/cp_mv.c b/cp_mv.c
index 3dc637d..cd061be 100644
--- a/cp_mv.c
+++ b/cp_mv.c
@@ -41,6 +41,7 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
+#include <getopt.h>
#define is_cp 0
#define is_mv 1
@@ -189,21 +190,21 @@ rm_Action(const char *fileName, struct stat *statbuf, void* junk)
extern int cp_mv_main(int argc, char **argv)
{
+ int i;
+ char c;
+
if (*applet_name == 'c' && *(applet_name + 1) == 'p')
dz_i = is_cp;
else
dz_i = is_mv;
if (argc < 3)
usage(cp_mv_usage[dz_i]);
- argc--;
- argv++;
if (dz_i == is_cp) {
recursiveFlag = preserveFlag = forceFlag = FALSE;
followLinks = TRUE;
- while (*argv && **argv == '-') {
- while (*++(*argv)) {
- switch (**argv) {
+ while ((c = getopt(argc, argv, "adpRf")) != EOF) {
+ switch (c) {
case 'a':
followLinks = FALSE;
preserveFlag = TRUE;
@@ -224,11 +225,8 @@ extern int cp_mv_main(int argc, char **argv)
default:
usage(cp_mv_usage[is_cp]);
}
- }
- argc--;
- argv++;
}
- if (argc < 2) {
+ if ((argc - optind) < 2) {
usage(cp_mv_usage[dz_i]);
}
} else { /* (dz_i == is_mv) */
@@ -252,12 +250,12 @@ extern int cp_mv_main(int argc, char **argv)
goto exit_false;
}
- while (argc-- > 1) {
+ for (i = optind; i < (argc-1); i++) {
size_t srcLen;
volatile int flags_memo;
int status;
- baseSrcName = *(argv++);
+ baseSrcName=argv[i];
if ((srcLen = strlen(baseSrcName)) > BUFSIZ)
name_too_long__exit();