summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/apr_general.h3
-rw-r--r--include/apr_getopt.h26
-rw-r--r--misc/beos/getopt.c60
-rw-r--r--misc/os2/getopt.c60
-rw-r--r--misc/unix/getopt.c60
-rw-r--r--misc/win32/getopt.c60
-rw-r--r--test/testargs.c7
7 files changed, 132 insertions, 144 deletions
diff --git a/include/apr_general.h b/include/apr_general.h
index 89c2a9622..b798dc2e9 100644
--- a/include/apr_general.h
+++ b/include/apr_general.h
@@ -241,9 +241,6 @@ ap_status_t ap_create_signal(ap_signum_t, ap_context_t *);
ap_status_t ap_send_signal(ap_signum_t, ap_context_t *);
ap_status_t ap_setup_signal(ap_signum_t, Sigfunc *, ap_context_t *);
-ap_status_t ap_getopt(ap_context_t *, ap_int32_t, char *const *, const char *,
- ap_int32_t *);
-
#ifdef __cplusplus
}
#endif
diff --git a/include/apr_getopt.h b/include/apr_getopt.h
index 7932d2402..7e463e2a8 100644
--- a/include/apr_getopt.h
+++ b/include/apr_getopt.h
@@ -56,24 +56,16 @@
#ifndef APR_GETOPT_H
#define APR_GETOPT_H
-/* Rename all interfaces to prevent a name clash with system libraries */
-#define opterr apr_opterr
-#define optind apr_optind
-#define optopt apr_optopt
-#define optreset apr_optreset
-#define optarg apr_optarg
-#define getopt apr_getopt
+API_VAR_IMPORT int
+ ap_opterr, /* if error message should be printed */
+ ap_optind, /* index into parent argv vector */
+ ap_optopt, /* character checked for validity */
+ ap_optreset; /* reset getopt */
+API_VAR_IMPORT char *
+ ap_optarg; /* argument associated with option */
-extern int
- opterr, /* if error message should be printed */
- optind, /* index into parent argv vector */
- optopt, /* character checked for validity */
- optreset; /* reset getopt */
-extern char *
- optarg; /* argument associated with option */
-
-extern int
- getopt(int _argc, char *const _argv[], const char *_opts);
+ap_status_t ap_getopt(ap_context_t *, ap_int32_t, char *const *, const char *,
+ ap_int32_t *);
#endif /* ! APR_GETOPT_H */
diff --git a/misc/beos/getopt.c b/misc/beos/getopt.c
index 55fb69b10..b3c1c47b4 100644
--- a/misc/beos/getopt.c
+++ b/misc/beos/getopt.c
@@ -36,11 +36,11 @@
#include <string.h>
#include "misc.h"
-int opterr = 1, /* if error message should be printed */
- optind = 1, /* index into parent argv vector */
- optopt, /* character checked for validity */
- optreset; /* reset getopt */
-char *optarg; /* argument associated with option */
+int ap_opterr = 1, /* if error message should be printed */
+ ap_optind = 1, /* index into parent argv vector */
+ ap_optopt, /* character checked for validity */
+ ap_optreset; /* reset getopt */
+char *ap_optarg = ""; /* argument associated with option */
#define EMSG ""
@@ -70,73 +70,73 @@ ap_status_t ap_getopt(struct context_t *cont, ap_int32_t nargc,
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
- if (optreset || !*place) { /* update scanning pointer */
- optreset = 0;
- if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ if (ap_optreset || !*place) { /* update scanning pointer */
+ ap_optreset = 0;
+ if (ap_optind >= nargc || *(place = nargv[ap_optind]) != '-') {
place = EMSG;
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_EOF);
}
if (place[1] && *++place == '-') { /* found "--" */
- ++optind;
+ ++ap_optind;
place = EMSG;
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_EOF);
}
} /* option letter okay? */
- if ((optopt = (int) *place++) == (int) ':' ||
- !(oli = strchr(ostr, optopt))) {
+ if ((ap_optopt = (int) *place++) == (int) ':' ||
+ !(oli = strchr(ostr, ap_optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
- if (optopt == (int) '-')
- *rv = optopt;
+ if (ap_optopt == (int) '-')
+ *rv = ap_optopt;
return (APR_EOF);
if (!*place)
- ++optind;
- if (opterr && *ostr != ':') {
+ ++ap_optind;
+ if (ap_opterr && *ostr != ':') {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
- "%s: illegal option -- %c\n", p, optopt);
+ "%s: illegal option -- %c\n", p, ap_optopt);
}
- *rv = optopt;
+ *rv = ap_optopt;
return APR_BADCH;
}
if (*++oli != ':') { /* don't need argument */
- optarg = NULL;
+ ap_optarg = NULL;
if (!*place)
- ++optind;
+ ++ap_optind;
}
else { /* need an argument */
if (*place) /* no white space */
- optarg = place;
- else if (nargc <= ++optind) { /* no arg */
+ ap_optarg = place;
+ else if (nargc <= ++ap_optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_BADARG);
- if (opterr) {
+ if (ap_opterr) {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
"%s: option requires an argument -- %c\n",
- p, optopt);
+ p, ap_optopt);
}
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_BADCH);
}
else /* white space */
- optarg = nargv[optind];
+ ap_optarg = nargv[ap_optind];
place = EMSG;
- ++optind;
+ ++ap_optind;
}
- *rv = optopt;
+ *rv = ap_optopt;
return APR_SUCCESS;
}
diff --git a/misc/os2/getopt.c b/misc/os2/getopt.c
index 55fb69b10..b3c1c47b4 100644
--- a/misc/os2/getopt.c
+++ b/misc/os2/getopt.c
@@ -36,11 +36,11 @@
#include <string.h>
#include "misc.h"
-int opterr = 1, /* if error message should be printed */
- optind = 1, /* index into parent argv vector */
- optopt, /* character checked for validity */
- optreset; /* reset getopt */
-char *optarg; /* argument associated with option */
+int ap_opterr = 1, /* if error message should be printed */
+ ap_optind = 1, /* index into parent argv vector */
+ ap_optopt, /* character checked for validity */
+ ap_optreset; /* reset getopt */
+char *ap_optarg = ""; /* argument associated with option */
#define EMSG ""
@@ -70,73 +70,73 @@ ap_status_t ap_getopt(struct context_t *cont, ap_int32_t nargc,
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
- if (optreset || !*place) { /* update scanning pointer */
- optreset = 0;
- if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ if (ap_optreset || !*place) { /* update scanning pointer */
+ ap_optreset = 0;
+ if (ap_optind >= nargc || *(place = nargv[ap_optind]) != '-') {
place = EMSG;
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_EOF);
}
if (place[1] && *++place == '-') { /* found "--" */
- ++optind;
+ ++ap_optind;
place = EMSG;
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_EOF);
}
} /* option letter okay? */
- if ((optopt = (int) *place++) == (int) ':' ||
- !(oli = strchr(ostr, optopt))) {
+ if ((ap_optopt = (int) *place++) == (int) ':' ||
+ !(oli = strchr(ostr, ap_optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
- if (optopt == (int) '-')
- *rv = optopt;
+ if (ap_optopt == (int) '-')
+ *rv = ap_optopt;
return (APR_EOF);
if (!*place)
- ++optind;
- if (opterr && *ostr != ':') {
+ ++ap_optind;
+ if (ap_opterr && *ostr != ':') {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
- "%s: illegal option -- %c\n", p, optopt);
+ "%s: illegal option -- %c\n", p, ap_optopt);
}
- *rv = optopt;
+ *rv = ap_optopt;
return APR_BADCH;
}
if (*++oli != ':') { /* don't need argument */
- optarg = NULL;
+ ap_optarg = NULL;
if (!*place)
- ++optind;
+ ++ap_optind;
}
else { /* need an argument */
if (*place) /* no white space */
- optarg = place;
- else if (nargc <= ++optind) { /* no arg */
+ ap_optarg = place;
+ else if (nargc <= ++ap_optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_BADARG);
- if (opterr) {
+ if (ap_opterr) {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
"%s: option requires an argument -- %c\n",
- p, optopt);
+ p, ap_optopt);
}
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_BADCH);
}
else /* white space */
- optarg = nargv[optind];
+ ap_optarg = nargv[ap_optind];
place = EMSG;
- ++optind;
+ ++ap_optind;
}
- *rv = optopt;
+ *rv = ap_optopt;
return APR_SUCCESS;
}
diff --git a/misc/unix/getopt.c b/misc/unix/getopt.c
index 55fb69b10..b3c1c47b4 100644
--- a/misc/unix/getopt.c
+++ b/misc/unix/getopt.c
@@ -36,11 +36,11 @@
#include <string.h>
#include "misc.h"
-int opterr = 1, /* if error message should be printed */
- optind = 1, /* index into parent argv vector */
- optopt, /* character checked for validity */
- optreset; /* reset getopt */
-char *optarg; /* argument associated with option */
+int ap_opterr = 1, /* if error message should be printed */
+ ap_optind = 1, /* index into parent argv vector */
+ ap_optopt, /* character checked for validity */
+ ap_optreset; /* reset getopt */
+char *ap_optarg = ""; /* argument associated with option */
#define EMSG ""
@@ -70,73 +70,73 @@ ap_status_t ap_getopt(struct context_t *cont, ap_int32_t nargc,
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
- if (optreset || !*place) { /* update scanning pointer */
- optreset = 0;
- if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ if (ap_optreset || !*place) { /* update scanning pointer */
+ ap_optreset = 0;
+ if (ap_optind >= nargc || *(place = nargv[ap_optind]) != '-') {
place = EMSG;
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_EOF);
}
if (place[1] && *++place == '-') { /* found "--" */
- ++optind;
+ ++ap_optind;
place = EMSG;
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_EOF);
}
} /* option letter okay? */
- if ((optopt = (int) *place++) == (int) ':' ||
- !(oli = strchr(ostr, optopt))) {
+ if ((ap_optopt = (int) *place++) == (int) ':' ||
+ !(oli = strchr(ostr, ap_optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
- if (optopt == (int) '-')
- *rv = optopt;
+ if (ap_optopt == (int) '-')
+ *rv = ap_optopt;
return (APR_EOF);
if (!*place)
- ++optind;
- if (opterr && *ostr != ':') {
+ ++ap_optind;
+ if (ap_opterr && *ostr != ':') {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
- "%s: illegal option -- %c\n", p, optopt);
+ "%s: illegal option -- %c\n", p, ap_optopt);
}
- *rv = optopt;
+ *rv = ap_optopt;
return APR_BADCH;
}
if (*++oli != ':') { /* don't need argument */
- optarg = NULL;
+ ap_optarg = NULL;
if (!*place)
- ++optind;
+ ++ap_optind;
}
else { /* need an argument */
if (*place) /* no white space */
- optarg = place;
- else if (nargc <= ++optind) { /* no arg */
+ ap_optarg = place;
+ else if (nargc <= ++ap_optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_BADARG);
- if (opterr) {
+ if (ap_opterr) {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
"%s: option requires an argument -- %c\n",
- p, optopt);
+ p, ap_optopt);
}
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_BADCH);
}
else /* white space */
- optarg = nargv[optind];
+ ap_optarg = nargv[ap_optind];
place = EMSG;
- ++optind;
+ ++ap_optind;
}
- *rv = optopt;
+ *rv = ap_optopt;
return APR_SUCCESS;
}
diff --git a/misc/win32/getopt.c b/misc/win32/getopt.c
index 6941ef451..b3c1c47b4 100644
--- a/misc/win32/getopt.c
+++ b/misc/win32/getopt.c
@@ -36,11 +36,11 @@
#include <string.h>
#include "misc.h"
-int opterr = 1, /* if error message should be printed */
- optind = 1, /* index into parent argv vector */
- optopt, /* character checked for validity */
- optreset; /* reset getopt */
-char *optarg = ""; /* argument associated with option */
+int ap_opterr = 1, /* if error message should be printed */
+ ap_optind = 1, /* index into parent argv vector */
+ ap_optopt, /* character checked for validity */
+ ap_optreset; /* reset getopt */
+char *ap_optarg = ""; /* argument associated with option */
#define EMSG ""
@@ -70,73 +70,73 @@ ap_status_t ap_getopt(struct context_t *cont, ap_int32_t nargc,
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
- if (optreset || !*place) { /* update scanning pointer */
- optreset = 0;
- if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ if (ap_optreset || !*place) { /* update scanning pointer */
+ ap_optreset = 0;
+ if (ap_optind >= nargc || *(place = nargv[ap_optind]) != '-') {
place = EMSG;
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_EOF);
}
if (place[1] && *++place == '-') { /* found "--" */
- ++optind;
+ ++ap_optind;
place = EMSG;
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_EOF);
}
} /* option letter okay? */
- if ((optopt = (int) *place++) == (int) ':' ||
- !(oli = strchr(ostr, optopt))) {
+ if ((ap_optopt = (int) *place++) == (int) ':' ||
+ !(oli = strchr(ostr, ap_optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
- if (optopt == (int) '-')
- *rv = optopt;
+ if (ap_optopt == (int) '-')
+ *rv = ap_optopt;
return (APR_EOF);
if (!*place)
- ++optind;
- if (opterr && *ostr != ':') {
+ ++ap_optind;
+ if (ap_opterr && *ostr != ':') {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
- "%s: illegal option -- %c\n", p, optopt);
+ "%s: illegal option -- %c\n", p, ap_optopt);
}
- *rv = optopt;
+ *rv = ap_optopt;
return APR_BADCH;
}
if (*++oli != ':') { /* don't need argument */
- optarg = NULL;
+ ap_optarg = NULL;
if (!*place)
- ++optind;
+ ++ap_optind;
}
else { /* need an argument */
if (*place) /* no white space */
- optarg = place;
- else if (nargc <= ++optind) { /* no arg */
+ ap_optarg = place;
+ else if (nargc <= ++ap_optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_BADARG);
- if (opterr) {
+ if (ap_opterr) {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
"%s: option requires an argument -- %c\n",
- p, optopt);
+ p, ap_optopt);
}
- *rv = optopt;
+ *rv = ap_optopt;
return (APR_BADCH);
}
else /* white space */
- optarg = nargv[optind];
+ ap_optarg = nargv[ap_optind];
place = EMSG;
- ++optind;
+ ++ap_optind;
}
- *rv = optopt;
+ *rv = ap_optopt;
return APR_SUCCESS;
}
diff --git a/test/testargs.c b/test/testargs.c
index a5ecaf5c6..2f5b6bfd6 100644
--- a/test/testargs.c
+++ b/test/testargs.c
@@ -57,13 +57,12 @@
#include "apr_errno.h"
#include "apr_general.h"
#include "apr_lib.h"
+#include "apr_getopt.h"
#include <stdio.h>
#ifdef BEOS
#include <unistd.h>
#endif
-API_VAR_IMPORT char *optarg; /* argument associated with option */
-
int main(int argc, char * const argv[])
{
ap_context_t *context;
@@ -78,12 +77,12 @@ int main(int argc, char * const argv[])
printf("option %c\n", data);
break;
case 'c':
- printf("option %c with %s\n", data, optarg);
+ printf("option %c with %s\n", data, ap_optarg);
break;
case 'd':
printf("option %c", data);
if (optarg) {
- printf(" with %s\n", optarg);
+ printf(" with %s\n", ap_optarg);
}
else {
printf("\n");