diff options
| author | Zeev Suraski <zeev@php.net> | 2000-10-29 22:42:01 +0000 |
|---|---|---|
| committer | Zeev Suraski <zeev@php.net> | 2000-10-29 22:42:01 +0000 |
| commit | 4af433d627f069a5b783168940739cbbafa835a7 (patch) | |
| tree | 744d62e179054ed117e6b0f8d7bd83c1689a54f4 /ext/standard/basic_functions.c | |
| parent | ab3beffad78160010a58d377e0d507c76e87e6c4 (diff) | |
| download | php-git-4af433d627f069a5b783168940739cbbafa835a7.tar.gz | |
Use the new INI parser for parse_ini_str()
- parse_ini_str() is now thread-safe, and supported under Windows (Zeev)
Diffstat (limited to 'ext/standard/basic_functions.c')
| -rw-r--r-- | ext/standard/basic_functions.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 722c5cbcb2..4b9e2bdd25 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2318,6 +2318,49 @@ PHP_FUNCTION(move_uploaded_file) /* }}} */ + +static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, zval *arr) +{ + zval *element; + + switch (callback_type) { + case ZEND_INI_PARSER_ENTRY: + ALLOC_ZVAL(element); + *element = *arg2; + zval_copy_ctor(element); + INIT_PZVAL(element); + zend_hash_update(arr->value.ht, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL); + break; + case ZEND_INI_PARSER_SECTION: + break; + } +} + + +/* {{{ proto void parse_ini_file(string filename) + Parse configuration file */ +PHP_FUNCTION(parse_ini_file) +{ + zval **filename; + zend_file_handle fh; + + if (ARG_COUNT(ht)!=1 || zend_get_parameters_ex(1, &filename)==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string_ex(filename); + fh.handle.fp = V_FOPEN((*filename)->value.str.val, "r"); + if (!fh.handle.fp) { + php_error(E_WARNING,"Cannot open '%s' for reading", (*filename)->value.str.val); + return; + } + fh.type = ZEND_HANDLE_FP; + array_init(return_value); + zend_parse_ini_file(&fh, (zend_ini_parser_cb_t) php_simple_ini_parser_cb, return_value); + +} +/* }}} */ + + /* * Local variables: * tab-width: 4 |
