From dd5a40246b91bd5d3d165998e6ac3cc4f7083f63 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 4 Aug 2017 16:46:17 +0200 Subject: 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 --- archival/ar.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'archival/ar.c') 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) archive_handle = init_handle(); - /* --: prepend '-' to the first argument if required */ + /* prepend '-' to the first argument if required */ + if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') + argv[1] = xasprintf("-%s", argv[1]); /* -1: at least one param is reqd */ /* one of p,t,x[,r] is required */ - opt_complementary = "--:-1:p:t:x"IF_FEATURE_AR_CREATE(":r"); + opt_complementary = "-1:p:t:x"IF_FEATURE_AR_CREATE(":r"); opt = getopt32(argv, "voc""ptx"IF_FEATURE_AR_CREATE("r")); argv += optind; -- cgit v1.2.3