diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-07-16 16:21:45 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-07-16 16:44:37 +0200 |
commit | 46faf8f018e95de27873dbcf7c094af18c4c08e4 (patch) | |
tree | edd85291c8c8070f3182617152098c9289242e6e /main/php_ini.c | |
parent | 349a388b90e767da9128efe6da0e4ebf5c752092 (diff) | |
download | php-git-46faf8f018e95de27873dbcf7c094af18c4c08e4.tar.gz |
Introduce zend_stream_init_fp() API
Reduce the amount of code that mucks around with zend_file_handle
initialization.
Diffstat (limited to 'main/php_ini.c')
-rw-r--r-- | main/php_ini.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/main/php_ini.c b/main/php_ini.c index f6c2edf235..d508c13b50 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -419,8 +419,9 @@ int php_init_config(void) int php_ini_scanned_path_len; char *open_basedir; int free_ini_search_path = 0; - zend_file_handle fh; zend_string *opened_path = NULL; + FILE *fp; + const char *filename; zend_hash_init(&configuration_hash, 8, NULL, config_zval_dtor, 1); @@ -572,7 +573,8 @@ int php_init_config(void) * Find and open actual ini file */ - memset(&fh, 0, sizeof(fh)); + fp = NULL; + filename = NULL; /* If SAPI does not want to ignore all ini files OR an overriding file/path is given. * This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still @@ -585,31 +587,31 @@ int php_init_config(void) if (!VCWD_STAT(php_ini_file_name, &statbuf)) { if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) { - fh.handle.fp = VCWD_FOPEN(php_ini_file_name, "r"); - if (fh.handle.fp) { - fh.filename = expand_filepath(php_ini_file_name, NULL); + fp = VCWD_FOPEN(php_ini_file_name, "r"); + if (fp) { + filename = expand_filepath(php_ini_file_name, NULL); } } } } /* Otherwise search for php-%sapi-module-name%.ini file in search path */ - if (!fh.handle.fp) { + if (!fp) { const char *fmt = "php-%s.ini"; char *ini_fname; spprintf(&ini_fname, 0, fmt, sapi_module.name); - fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &opened_path); + fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &opened_path); efree(ini_fname); - if (fh.handle.fp) { - fh.filename = ZSTR_VAL(opened_path); + if (fp) { + filename = ZSTR_VAL(opened_path); } } /* If still no ini file found, search for php.ini file in search path */ - if (!fh.handle.fp) { - fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path); - if (fh.handle.fp) { - fh.filename = ZSTR_VAL(opened_path); + if (!fp) { + fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path); + if (fp) { + filename = ZSTR_VAL(opened_path); } } } @@ -620,8 +622,9 @@ int php_init_config(void) PG(open_basedir) = open_basedir; - if (fh.handle.fp) { - fh.type = ZEND_HANDLE_FP; + if (fp) { + zend_file_handle fh; + zend_stream_init_fp(&fh, fp, filename); RESET_ACTIVE_INI_HASH(); zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash); @@ -655,7 +658,6 @@ int php_init_config(void) zend_stat_t sb; char ini_file[MAXPATHLEN]; char *p; - zend_file_handle fh2; zend_llist scanned_ini_list; zend_llist_element *element; int l, total_l = 0; @@ -663,7 +665,6 @@ int php_init_config(void) int lenpath; zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1); - memset(&fh2, 0, sizeof(fh2)); bufpath = estrdup(php_ini_scanned_path); for (debpath = bufpath ; debpath ; debpath=endpath) { @@ -697,11 +698,10 @@ int php_init_config(void) } if (VCWD_STAT(ini_file, &sb) == 0) { if (S_ISREG(sb.st_mode)) { - if ((fh2.handle.fp = VCWD_FOPEN(ini_file, "r"))) { - fh2.filename = ini_file; - fh2.type = ZEND_HANDLE_FP; - - if (zend_parse_ini_file(&fh2, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash) == SUCCESS) { + zend_file_handle fh; + zend_stream_init_fp(&fh, VCWD_FOPEN(ini_file, "r"), ini_file); + if (fh.handle.fp) { + if (zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash) == SUCCESS) { /* Here, add it to the list of ini files read */ l = (int)strlen(ini_file); total_l += l + 2; @@ -784,17 +784,14 @@ PHPAPI int php_parse_user_ini_file(const char *dirname, char *ini_filename, Hash { zend_stat_t sb; char ini_file[MAXPATHLEN]; - zend_file_handle fh; snprintf(ini_file, MAXPATHLEN, "%s%c%s", dirname, DEFAULT_SLASH, ini_filename); if (VCWD_STAT(ini_file, &sb) == 0) { if (S_ISREG(sb.st_mode)) { - memset(&fh, 0, sizeof(fh)); - if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) { - fh.filename = ini_file; - fh.type = ZEND_HANDLE_FP; - + zend_file_handle fh; + zend_stream_init_fp(&fh, VCWD_FOPEN(ini_file, "r"), ini_file); + if (fh.handle.fp) { /* Reset active ini section */ RESET_ACTIVE_INI_HASH(); |