aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-04 16:46:17 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-04 16:46:17 +0200
commitdd5a40246b91bd5d3d165998e6ac3cc4f7083f63 (patch)
treeffbd1f118040b36ae23f43d491bd8de097fd0843 /archival
parent727948e585cb133c32c8d42570e5524c58190307 (diff)
downloadbusybox-w32-dd5a40246b91bd5d3d165998e6ac3cc4f7083f63.tar.gz
busybox-w32-dd5a40246b91bd5d3d165998e6ac3cc4f7083f63.tar.bz2
busybox-w32-dd5a40246b91bd5d3d165998e6ac3cc4f7083f63.zip
getopt32: move support for "always treat first arg as option" to users (tar/ar)
Now getopt() never leaks (and never performs) any xmalloc's. function old new delta ar_main 522 556 +34 tar_main 986 1014 +28 getopt32 1458 1350 -108 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 62/-108) Total: -46 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival')
-rw-r--r--archival/ar.c6
-rw-r--r--archival/tar.c4
2 files changed, 7 insertions, 3 deletions
diff --git a/archival/ar.c b/archival/ar.c
index 2886d155b..46c10aad4 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -240,10 +240,12 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
240 240
241 archive_handle = init_handle(); 241 archive_handle = init_handle();
242 242
243 /* --: prepend '-' to the first argument if required */ 243 /* prepend '-' to the first argument if required */
244 if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0')
245 argv[1] = xasprintf("-%s", argv[1]);
244 /* -1: at least one param is reqd */ 246 /* -1: at least one param is reqd */
245 /* one of p,t,x[,r] is required */ 247 /* one of p,t,x[,r] is required */
246 opt_complementary = "--:-1:p:t:x"IF_FEATURE_AR_CREATE(":r"); 248 opt_complementary = "-1:p:t:x"IF_FEATURE_AR_CREATE(":r");
247 opt = getopt32(argv, "voc""ptx"IF_FEATURE_AR_CREATE("r")); 249 opt = getopt32(argv, "voc""ptx"IF_FEATURE_AR_CREATE("r"));
248 argv += optind; 250 argv += optind;
249 251
diff --git a/archival/tar.c b/archival/tar.c
index 280ded4e1..f62b33005 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -966,7 +966,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
966 tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM; 966 tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
967 967
968 /* Prepend '-' to the first argument if required */ 968 /* Prepend '-' to the first argument if required */
969 opt_complementary = "--:" // first arg is options 969 if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0')
970 argv[1] = xasprintf("-%s", argv[1]);
971 opt_complementary =
970 "tt:vv:" // count -t,-v 972 "tt:vv:" // count -t,-v
971#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM 973#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
972 "\xff::" // --exclude=PATTERN is a list 974 "\xff::" // --exclude=PATTERN is a list