aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/getopt.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/util-linux/getopt.c b/util-linux/getopt.c
index 032d0dc6b..0ad69ad9a 100644
--- a/util-linux/getopt.c
+++ b/util-linux/getopt.c
@@ -306,7 +306,7 @@ static const char *shortopts="+ao:l:n:qQs:Tu";
int getopt_main(int argc, char *argv[])
{
const char *optstr = NULL;
- const char *name = NULL;
+ char *name = NULL;
int opt;
int compatible=0;
@@ -326,11 +326,13 @@ int getopt_main(int argc, char *argv[])
}
if (argv[1][0] != '-' || compatible) {
+ char *s;
+
quote=0;
- optstr=xmalloc(strlen(argv[1])+1);
- strcpy(optstr,argv[1]+strspn(argv[1],"-+"));
+ s=xmalloc(strlen(argv[1])+1);
+ strcpy(s,argv[1]+strspn(argv[1],"-+"));
argv[1]=argv[0];
- return (generate_output(argv+1,argc-1,optstr,long_options));
+ return (generate_output(argv+1,argc-1,s,long_options));
}
while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF)
@@ -339,14 +341,12 @@ int getopt_main(int argc, char *argv[])
alternative=1;
break;
case 'o':
- free(optstr);
optstr = optarg;
break;
case 'l':
add_long_options(optarg);
break;
case 'n':
- free(name);
name = optarg;
break;
case 'q':
@@ -370,10 +370,7 @@ int getopt_main(int argc, char *argv[])
if (!optstr) {
if (optind >= argc)
bb_error_msg_and_die("missing optstring argument");
- else {
- optstr=bb_xstrdup(argv[optind]);
- optind++;
- }
+ else optstr=argv[optind++];
}
if (name)
argv[optind-1]=name;