summaryrefslogtreecommitdiffstats
path: root/getopt
diff options
context:
space:
mode:
authorSami Kerola2011-06-13 00:49:08 +0200
committerSami Kerola2011-06-25 16:19:13 +0200
commit4a898108c0b079b29024f44955e4a4853b191e91 (patch)
tree27c42dd5864146cfde0440760104ea7de707d5e2 /getopt
parentgetopt: remove unnecessary free() (diff)
downloadkernel-qcow2-util-linux-4a898108c0b079b29024f44955e4a4853b191e91.tar.gz
kernel-qcow2-util-linux-4a898108c0b079b29024f44955e4a4853b191e91.tar.xz
kernel-qcow2-util-linux-4a898108c0b079b29024f44955e4a4853b191e91.zip
getopt: make user getopt_long parsing to use function pointer
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'getopt')
-rw-r--r--getopt/getopt.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/getopt/getopt.c b/getopt/getopt.c
index ceb9d3ded..b857aac83 100644
--- a/getopt/getopt.c
+++ b/getopt/getopt.c
@@ -76,7 +76,10 @@ static shell_t shell=BASH; /* The shell we generate output for. */
static int quiet_errors=0; /* 0 is not quiet. */
static int quiet_output=0; /* 0 is not quiet. */
static int quote=1; /* 1 is do quote. */
-static int alternative=0; /* 0 is getopt_long, 1 is getopt_long_only */
+
+/* Allow changing which getopt is in use with function pointer */
+int (*getopt_long_fp) (int argc, char *const *argv, const char *optstr,
+ const struct option * longopts, int *longindex);
/* Function prototypes */
static const char *normalize(const char *arg);
@@ -172,9 +175,7 @@ static int generate_output(char * argv[],int argc,const char *optstr,
opterr=0;
optind=0; /* Reset getopt(3) */
- while ((opt = (alternative?
- getopt_long_only(argc,argv,optstr,longopts,&longindex):
- getopt_long(argc,argv,optstr,longopts,&longindex)))
+ while ((opt = (getopt_long_fp(argc,argv,optstr,longopts,&longindex)))
!= EOF)
if (opt == '?' || opt == ':' )
exit_code = GETOPT_EXIT_CODE;
@@ -352,6 +353,7 @@ int main(int argc, char *argv[])
textdomain(PACKAGE);
init_longopt();
+ getopt_long_fp = getopt_long;
if (getenv("GETOPT_COMPATIBLE"))
compatible=1;
@@ -379,7 +381,7 @@ int main(int argc, char *argv[])
while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF)
switch (opt) {
case 'a':
- alternative=1;
+ getopt_long_fp = getopt_long_only;
break;
case 'h':
print_help();