diff options
| author | Adam Saponara <saponara@gmail.com> | 2016-05-29 13:44:16 -0400 |
|---|---|---|
| committer | Julien Pauli <jpauli@php.net> | 2016-07-08 16:53:24 +0200 |
| commit | e4f7f00a7748b1312f6486639c158be887f23e18 (patch) | |
| tree | 6455c198428be0d47c3a624d39ce5cdbb895b49b /ext/standard/basic_functions.c | |
| parent | 6ab9b848e8b3d3421217fe6e863f1874609ff773 (diff) | |
| download | php-git-e4f7f00a7748b1312f6486639c158be887f23e18.tar.gz | |
Add optind param to getopt
Diffstat (limited to 'ext/standard/basic_functions.c')
| -rw-r--r-- | ext/standard/basic_functions.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 20f03bb67f..7fa1ad4bfc 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -646,6 +646,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_getopt, 0, 0, 1) ZEND_ARG_INFO(0, options) ZEND_ARG_INFO(0, opts) /* ARRAY_INFO(0, opts, 1) */ + ZEND_ARG_INFO(1, optind) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_flush, 0) @@ -4269,7 +4270,7 @@ static int parse_opts(char * opts, opt_struct ** result) } /* }}} */ -/* {{{ proto array getopt(string options [, array longopts]) +/* {{{ proto array getopt(string options [, array longopts [, int &optind]]) Get options from the command line argument list */ PHP_FUNCTION(getopt) { @@ -4281,13 +4282,20 @@ PHP_FUNCTION(getopt) char *php_optarg = NULL; int php_optind = 1; zval val, *args = NULL, *p_longopts = NULL; + zval *zoptind = NULL; int optname_len = 0; opt_struct *opts, *orig_opts; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a", &options, &options_len, &p_longopts) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|az/", &options, &options_len, &p_longopts, &zoptind) == FAILURE) { RETURN_FALSE; } + /* Init zoptind to 1 */ + if (zoptind) { + zval_dtor(zoptind); + ZVAL_LONG(zoptind, 1); + } + /* Get argv from the global symbol table. We calculate argc ourselves * in order to be on the safe side, even though it is also available * from the symbol table. */ @@ -4429,6 +4437,11 @@ PHP_FUNCTION(getopt) php_optarg = NULL; } + /* Set zoptind to php_optind */ + if (zoptind) { + ZVAL_LONG(zoptind, php_optind); + } + free_longopts(orig_opts); efree(orig_opts); free_argv(argv, argc); |
