dist_man_MANS += misc-utils/getopt.1
PATHFILES += misc-utils/getopt.1
getopt_SOURCES = misc-utils/getopt.c
+getopt_LDADD = $(LDADD) libcommon.la
getoptexampledir = $(docdir)
dist_getoptexample_DATA = \
misc-utils/getopt-example.bash \
#include "closestream.h"
#include "nls.h"
+#include "strutils.h"
#include "xalloc.h"
/* NON_OPT is the code that is returned getopt(3) when a non-option is
}
+static void add_short_options(struct getopt_control *ctl, char *options)
+{
+ free(ctl->optstr);
+ if (*options != '+' && getenv("POSIXLY_CORRECT"))
+ ctl->optstr = strappend("+", options);
+ else
+ ctl->optstr = xstrdup(options);
+ if (!ctl->optstr)
+ err_oom();
+}
+
+
/*
* Register several long options. options is a string of long options,
* separated by commas or whitespace. This nukes options!
getopt_long_fp = getopt_long_only;
break;
case 'o':
- free(ctl.optstr);
- ctl.optstr = xstrdup(optarg);
+ add_short_options(&ctl, optarg);
break;
case 'l':
add_long_options(&ctl, optarg);
if (optind >= argc)
parse_error(_("missing optstring argument"));
else {
- ctl.optstr = xstrdup(argv[optind]);
+ add_short_options(&ctl, argv[optind]);
optind++;
}
}