diff options
Diffstat (limited to 'ext/standard/basic_functions.c')
-rwxr-xr-x | ext/standard/basic_functions.c | 164 |
1 files changed, 79 insertions, 85 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 876ef347eb..54c3188771 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -463,8 +463,6 @@ PHP_RINIT_FUNCTION(basic) /* {{{ */ BG(strtok_last) = NULL; BG(ctype_string) = NULL; BG(locale_changed) = 0; - BG(array_walk_fci) = empty_fcall_info; - BG(array_walk_fci_cache) = empty_fcall_info_cache; BG(user_compare_fci) = empty_fcall_info; BG(user_compare_fci_cache) = empty_fcall_info_cache; BG(page_uid) = -1; @@ -729,98 +727,98 @@ PHP_FUNCTION(long2ip) * System Functions * ********************/ -/* {{{ Get the value of an environment variable or every available environment variable - if no varname is present */ -PHP_FUNCTION(getenv) -{ - char *ptr, *str = NULL; - size_t str_len; - zend_bool local_only = 0; - - ZEND_PARSE_PARAMETERS_START(0, 2) - Z_PARAM_OPTIONAL - Z_PARAM_STRING_OR_NULL(str, str_len) - Z_PARAM_BOOL(local_only) - ZEND_PARSE_PARAMETERS_END(); - - if (!str) { - array_init(return_value); - php_import_environment_variables(return_value); - return; - } - - if (!local_only) { - /* SAPI method returns an emalloc()'d string */ - ptr = sapi_getenv(str, str_len); - if (ptr) { - // TODO: avoid reallocation ??? - RETVAL_STRING(ptr); - efree(ptr); - return; - } - } +PHPAPI zend_string *php_getenv(const char *str, size_t str_len) { #ifdef PHP_WIN32 { - wchar_t dummybuf; - DWORD size; - wchar_t *keyw, *valw; - - keyw = php_win32_cp_conv_any_to_w(str, str_len, PHP_WIN32_CP_IGNORE_LEN_P); + wchar_t *keyw = php_win32_cp_conv_any_to_w(str, str_len, PHP_WIN32_CP_IGNORE_LEN_P); if (!keyw) { - RETURN_FALSE; + return NULL; } SetLastError(0); - /*If the given buffer is not large enough to hold the data, the return value is - the buffer size, in characters, required to hold the string and its terminating - null character. We use this return value to alloc the final buffer. */ - size = GetEnvironmentVariableW(keyw, &dummybuf, 0); + /* If the given buffer is not large enough to hold the data, the return value is + * the buffer size, in characters, required to hold the string and its terminating + * null character. We use this return value to alloc the final buffer. */ + wchar_t dummybuf; + DWORD size = GetEnvironmentVariableW(keyw, &dummybuf, 0); if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) { - /* The environment variable doesn't exist. */ - free(keyw); - RETURN_FALSE; + /* The environment variable doesn't exist. */ + free(keyw); + return NULL; } if (size == 0) { - /* env exists, but it is empty */ - free(keyw); - RETURN_EMPTY_STRING(); + /* env exists, but it is empty */ + free(keyw); + return ZSTR_EMPTY_ALLOC(); } - valw = emalloc((size + 1) * sizeof(wchar_t)); + wchar_t *valw = emalloc((size + 1) * sizeof(wchar_t)); size = GetEnvironmentVariableW(keyw, valw, size); if (size == 0) { - /* has been removed between the two calls */ - free(keyw); - efree(valw); - RETURN_EMPTY_STRING(); + /* has been removed between the two calls */ + free(keyw); + efree(valw); + return ZSTR_EMPTY_ALLOC(); } else { - ptr = php_win32_cp_w_to_any(valw); - RETVAL_STRING(ptr); + char *ptr = php_win32_cp_w_to_any(valw); + zend_string *result = zend_string_init(ptr, strlen(ptr), 0); free(ptr); free(keyw); efree(valw); - return; + return result; } } #else - tsrm_env_lock(); /* system method returns a const */ - ptr = getenv(str); - + char *ptr = getenv(str); + zend_string *result = NULL; if (ptr) { - RETVAL_STRING(ptr); + result = zend_string_init(ptr, strlen(ptr), 0); } tsrm_env_unlock(); + return result; +#endif +} + +/* {{{ Get the value of an environment variable or every available environment variable + if no varname is present */ +PHP_FUNCTION(getenv) +{ + char *str = NULL; + size_t str_len; + bool local_only = 0; - if (ptr) { - return; - } + ZEND_PARSE_PARAMETERS_START(0, 2) + Z_PARAM_OPTIONAL + Z_PARAM_STRING_OR_NULL(str, str_len) + Z_PARAM_BOOL(local_only) + ZEND_PARSE_PARAMETERS_END(); -#endif + if (!str) { + array_init(return_value); + php_import_environment_variables(return_value); + return; + } + + if (!local_only) { + /* SAPI method returns an emalloc()'d string */ + char *ptr = sapi_getenv(str, str_len); + if (ptr) { + // TODO: avoid reallocation ??? + RETVAL_STRING(ptr); + efree(ptr); + return; + } + } + + zend_string *res = php_getenv(str, str_len); + if (res) { + RETURN_STR(res); + } RETURN_FALSE; } /* }}} */ @@ -1172,7 +1170,7 @@ PHP_FUNCTION(getopt) int optname_int = atoi(optname); if ((args = zend_hash_index_find(Z_ARRVAL_P(return_value), optname_int)) != NULL) { if (Z_TYPE_P(args) != IS_ARRAY) { - convert_to_array_ex(args); + convert_to_array(args); } zend_hash_next_index_insert(Z_ARRVAL_P(args), &val); } else { @@ -1182,7 +1180,7 @@ PHP_FUNCTION(getopt) /* other strings */ if ((args = zend_hash_str_find(Z_ARRVAL_P(return_value), optname, strlen(optname))) != NULL) { if (Z_TYPE_P(args) != IS_ARRAY) { - convert_to_array_ex(args); + convert_to_array(args); } zend_hash_next_index_insert(Z_ARRVAL_P(args), &val); } else { @@ -1472,7 +1470,7 @@ PHPAPI int _php_error_log_ex(int opt_err, const char *message, size_t message_le return FAILURE; case 3: /*save to a file */ - stream = php_stream_open_wrapper(opt, "a", IGNORE_URL_WIN | REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(opt, "a", REPORT_ERRORS, NULL); if (!stream) { return FAILURE; } @@ -1809,7 +1807,7 @@ PHP_FUNCTION(register_shutdown_function) } /* }}} */ -PHPAPI zend_bool register_user_shutdown_function(const char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry) /* {{{ */ +PHPAPI bool register_user_shutdown_function(const char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry) /* {{{ */ { if (!BG(user_shutdown_function_names)) { ALLOC_HASHTABLE(BG(user_shutdown_function_names)); @@ -1821,7 +1819,7 @@ PHPAPI zend_bool register_user_shutdown_function(const char *function_name, size } /* }}} */ -PHPAPI zend_bool remove_user_shutdown_function(const char *function_name, size_t function_len) /* {{{ */ +PHPAPI bool remove_user_shutdown_function(const char *function_name, size_t function_len) /* {{{ */ { if (BG(user_shutdown_function_names)) { return zend_hash_str_del(BG(user_shutdown_function_names), function_name, function_len) != FAILURE; @@ -1831,7 +1829,7 @@ PHPAPI zend_bool remove_user_shutdown_function(const char *function_name, size_t } /* }}} */ -PHPAPI zend_bool append_user_shutdown_function(php_shutdown_function_entry *shutdown_function_entry) /* {{{ */ +PHPAPI bool append_user_shutdown_function(php_shutdown_function_entry *shutdown_function_entry) /* {{{ */ { if (!BG(user_shutdown_function_names)) { ALLOC_HASHTABLE(BG(user_shutdown_function_names)); @@ -1859,7 +1857,7 @@ PHP_FUNCTION(highlight_file) size_t filename_len; int ret; zend_syntax_highlighter_ini syntax_highlighter_ini; - zend_bool i = 0; + bool i = 0; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_PATH(filename, filename_len) @@ -1934,7 +1932,7 @@ PHP_FUNCTION(highlight_string) zend_string *str; zend_syntax_highlighter_ini syntax_highlighter_ini; char *hicompiled_string_description; - zend_bool i = 0; + bool i = 0; int old_error_reporting = EG(error_reporting); ZEND_PARSE_PARAMETERS_START(1, 2) @@ -1953,12 +1951,8 @@ PHP_FUNCTION(highlight_string) hicompiled_string_description = zend_make_compiled_string_description("highlighted code"); - // TODO: Accept zend_string in highlight_string API. - zval str_zv; - ZVAL_STR_COPY(&str_zv, str); - highlight_string(&str_zv, &syntax_highlighter_ini, hicompiled_string_description); + highlight_string(str, &syntax_highlighter_ini, hicompiled_string_description); efree(hicompiled_string_description); - zval_ptr_dtor(&str_zv); EG(error_reporting) = old_error_reporting; @@ -2013,7 +2007,7 @@ PHP_FUNCTION(ini_get_all) char *extname = NULL; size_t extname_len = 0, module_number = 0; zend_module_entry *module; - zend_bool details = 1; + bool details = 1; zend_string *key; zend_ini_entry *ini_entry; @@ -2197,7 +2191,7 @@ PHP_FUNCTION(get_include_path) PHP_FUNCTION(print_r) { zval *var; - zend_bool do_return = 0; + bool do_return = 0; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(var) @@ -2235,8 +2229,8 @@ PHP_FUNCTION(connection_status) /* {{{ Set whether we want to ignore a user abort event or not */ PHP_FUNCTION(ignore_user_abort) { - zend_bool arg = 0; - zend_bool arg_is_null = 1; + bool arg = 0; + bool arg_is_null = 1; int old_setting; ZEND_PARSE_PARAMETERS_START(0, 1) @@ -2399,7 +2393,7 @@ PHP_FUNCTION(register_tick_function) } if (Z_TYPE(tick_fe.arguments[0]) != IS_ARRAY && Z_TYPE(tick_fe.arguments[0]) != IS_OBJECT) { - convert_to_string_ex(&tick_fe.arguments[0]); + convert_to_string(&tick_fe.arguments[0]); } if (!BG(user_tick_functions)) { @@ -2470,7 +2464,7 @@ PHP_FUNCTION(move_uploaded_file) { char *path, *new_path; size_t path_len, new_path_len; - zend_bool successful = 0; + bool successful = 0; #ifndef PHP_WIN32 int oldmask; int ret; @@ -2601,7 +2595,7 @@ PHP_FUNCTION(parse_ini_file) { char *filename = NULL; size_t filename_len = 0; - zend_bool process_sections = 0; + bool process_sections = 0; zend_long scanner_mode = ZEND_INI_SCANNER_NORMAL; zend_file_handle fh; zend_ini_parser_cb_t ini_parser_cb; @@ -2642,7 +2636,7 @@ PHP_FUNCTION(parse_ini_string) { char *string = NULL, *str = NULL; size_t str_len = 0; - zend_bool process_sections = 0; + bool process_sections = 0; zend_long scanner_mode = ZEND_INI_SCANNER_NORMAL; zend_ini_parser_cb_t ini_parser_cb; |