summaryrefslogtreecommitdiff
path: root/sapi
diff options
context:
space:
mode:
authorfoobar <sniper@php.net>2007-04-15 22:50:58 +0000
committerfoobar <sniper@php.net>2007-04-15 22:50:58 +0000
commitc71b1401ffaa14dde1cd1932288a90596177fee0 (patch)
treeb1655de56ad57f29a8122dcdf05050ba2e7e9df7 /sapi
parent2f3e330ad00522fc007a48132195e44dd47252ed (diff)
downloadphp-git-c71b1401ffaa14dde1cd1932288a90596177fee0.tar.gz
- Synch these files from sapi/cli/ and allow using s.c. long-options
with CGI.
Diffstat (limited to 'sapi')
-rw-r--r--sapi/cgi/getopt.c33
-rw-r--r--sapi/cgi/php_getopt.h9
2 files changed, 29 insertions, 13 deletions
diff --git a/sapi/cgi/getopt.c b/sapi/cgi/getopt.c
index 82e90ed95f..963c4554e1 100644
--- a/sapi/cgi/getopt.c
+++ b/sapi/cgi/getopt.c
@@ -16,6 +16,8 @@
+----------------------------------------------------------------------+
*/
+/* $Id$ */
+
#include <stdio.h>
#include <string.h>
#include <assert.h>
@@ -77,29 +79,34 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta
}
if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
/* '--' indicates end of args if not followed by a known long option name */
+ if (argv[*optind][2] == '\0') {
+ (*optind)++;
+ return(EOF);
+ }
+
while (1) {
opts_idx++;
if (opts[opts_idx].opt_char == '-') {
(*optind)++;
- return(EOF);
+ return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
} else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
break;
}
}
optchr = 0;
- dash = 1;
- arg_start = 2 + strlen(opts[opts_idx].opt_name);
- }
- if (!dash) {
- dash = 1;
- optchr = 1;
- }
-
- /* Check if the guy tries to do a -: kind of flag */
- if (argv[*optind][optchr] == ':') {
dash = 0;
- (*optind)++;
- return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err));
+ arg_start = 2 + strlen(opts[opts_idx].opt_name);
+ } else {
+ if (!dash) {
+ dash = 1;
+ optchr = 1;
+ }
+ /* Check if the guy tries to do a -: kind of flag */
+ if (argv[*optind][optchr] == ':') {
+ dash = 0;
+ (*optind)++;
+ return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err));
+ }
}
if (opts_idx < 0) {
while (1) {
diff --git a/sapi/cgi/php_getopt.h b/sapi/cgi/php_getopt.h
index 4bfa433977..fc14c96743 100644
--- a/sapi/cgi/php_getopt.h
+++ b/sapi/cgi/php_getopt.h
@@ -16,8 +16,17 @@
+----------------------------------------------------------------------+
*/
+/* $Id$ */
+
#include "php.h"
+#ifdef NETWARE
+/*
+As NetWare LibC has optind and optarg macros defined in unistd.h our local variables were getting mistakenly preprocessed so undeffing optind and optarg
+*/
+#undef optarg
+#undef optind
+#endif
/* Define structure for one recognized option (both single char and long name).
* If short_open is '-' this is the last option.
*/