Avoid more ad-hoc initialization of zend_file_handle structures.
ZVAL_STR(&tmp, zval_get_string(filename));
filename = &tmp;
}
- file_handle.filename = Z_STRVAL_P(filename);
- file_handle.free_filename = 0;
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.opened_path = NULL;
- file_handle.handle.fp = NULL;
+ zend_stream_init_filename(&file_handle, Z_STRVAL_P(filename));
retval = zend_compile_file(&file_handle, type);
if (retval && file_handle.handle.stream.handle) {
zend_lex_state original_lex_state;
zend_file_handle file_handle;
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = filename;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
+ zend_stream_init_filename(&file_handle, filename);
zend_save_lexical_state(&original_lex_state);
if (open_file_for_scanning(&file_handle)==FAILURE) {
zend_message_dispatcher(ZMSG_FAILED_HIGHLIGHT_FOPEN, filename);
handle->filename = filename;
}
+ZEND_API void zend_stream_init_filename(zend_file_handle *handle, const char *filename) {
+ memset(handle, 0, sizeof(zend_file_handle));
+ handle->type = ZEND_HANDLE_FILENAME;
+ handle->filename = filename;
+}
+
ZEND_API int zend_stream_open(const char *filename, zend_file_handle *handle) /* {{{ */
{
if (zend_stream_open_function) {
BEGIN_EXTERN_C()
ZEND_API void zend_stream_init_fp(zend_file_handle *handle, FILE *fp, const char *filename);
+ZEND_API void zend_stream_init_filename(zend_file_handle *handle, const char *filename);
ZEND_API int zend_stream_open(const char *filename, zend_file_handle *handle);
ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t *len);
ZEND_API void zend_file_handle_dtor(zend_file_handle *fh);
file_handle->opened_path = NULL;
}
- ps_handle.type = ZEND_HANDLE_FILENAME;
- ps_handle.filename = ZSTR_VAL(persistent_script->script.filename);
+ zend_stream_init_filename(&ps_handle, ZSTR_VAL(persistent_script->script.filename));
ps_handle.opened_path = persistent_script->script.filename;
if (zend_get_file_handle_timestamp(&ps_handle, NULL) == persistent_script->timestamp) {
persistent_script = zend_accel_hash_find(&ZCSG(hash), realpath);
if (persistent_script && !persistent_script->corrupted) {
zend_file_handle file_handle;
-
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = ZSTR_VAL(realpath);
+ zend_stream_init_filename(&file_handle, ZSTR_VAL(realpath));
file_handle.opened_path = realpath;
if (force ||
ZCG(cache_opline) == EG(current_execute_data)->opline)) {
/* we are in include_once or FastCGI request */
- handle->filename = (char*)filename;
- handle->free_filename = 0;
+ zend_stream_init_filename(handle, (char*) filename);
handle->opened_path = zend_string_copy(ZCG(cache_persistent_script)->script.filename);
- handle->type = ZEND_HANDLE_FILENAME;
return SUCCESS;
}
ZCG(cache_opline) = NULL;
orig_map_ptr_last = CG(map_ptr_last);
/* Compile and execute proloading script */
- memset(&file_handle, 0, sizeof(file_handle));
- file_handle.filename = (char*)config;
- file_handle.free_filename = 0;
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.opened_path = NULL;
- file_handle.handle.fp = NULL;
+ zend_stream_init_filename(&file_handle, (char *) config);
preload_scripts = emalloc(sizeof(HashTable));
zend_hash_init(preload_scripts, 0, NULL, NULL, 0);
if (key != NULL) {
zend_persistent_script *persistent_script = zend_accel_hash_str_find(&ZCSG(hash), key, key_length);
if (persistent_script && !persistent_script->corrupted) {
- zend_file_handle handle = {{0}, NULL, NULL, 0, 0};
-
- handle.filename = ZSTR_VAL(filename);
- handle.type = ZEND_HANDLE_FILENAME;
-
if (ZCG(accel_directives).validate_timestamps) {
+ zend_file_handle handle;
+ zend_stream_init_filename(&handle, ZSTR_VAL(filename));
return validate_timestamp_and_record_ex(persistent_script, &handle) == SUCCESS;
}
return;
}
- handle.filename = script_name;
- handle.free_filename = 0;
- handle.opened_path = NULL;
- handle.type = ZEND_HANDLE_FILENAME;
+ zend_stream_init_filename(&handle, script_name);
orig_execute_data = EG(current_execute_data);
orig_compiler_options = CG(compiler_options);
name_len = spprintf(&name, 4096, "phar://%s/%s", arch, entry);
}
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = name;
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
+ zend_stream_init_filename(&file_handle, name);
PHAR_G(cwd) = NULL;
PHAR_G(cwd_len) = 0;
int history_lines_to_write = 0;
if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
- zend_file_handle *prepend_file_p;
zend_file_handle prepend_file;
-
- memset(&prepend_file, 0, sizeof(prepend_file));
- prepend_file.filename = PG(auto_prepend_file);
- prepend_file.opened_path = NULL;
- prepend_file.free_filename = 0;
- prepend_file.type = ZEND_HANDLE_FILENAME;
- prepend_file_p = &prepend_file;
-
- zend_execute_scripts(ZEND_REQUIRE, NULL, 1, prepend_file_p);
+ zend_stream_init_filename(&prepend_file, PG(auto_prepend_file));
+ zend_execute_scripts(ZEND_REQUIRE, NULL, 1, &prepend_file);
}
#ifndef PHP_WIN32
php_output_start_default();
- memset(&file_handle, 0, sizeof(file_handle));
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = filename;
- file_handle.free_filename = 0;
- file_handle.opened_path = NULL;
+ zend_stream_init_filename(&file_handle, filename);
zend_save_lexical_state(&original_lex_state);
if (open_file_for_scanning(&file_handle) == FAILURE) {
zend_restore_lexical_state(&original_lex_state);
}
/* Setup filehandle */
- memset(&fh, 0, sizeof(fh));
- fh.filename = filename;
- fh.type = ZEND_HANDLE_FILENAME;
+ zend_stream_init_filename(&fh, filename);
array_init(return_value);
if (zend_parse_ini_file(&fh, 0, (int)scanner_mode, ini_parser_cb, return_value) == FAILURE) {
PHPAPI int php_execute_script(zend_file_handle *primary_file)
{
zend_file_handle *prepend_file_p, *append_file_p;
- zend_file_handle prepend_file = {{0}, NULL, NULL, 0, 0}, append_file = {{0}, NULL, NULL, 0, 0};
+ zend_file_handle prepend_file, append_file;
#if HAVE_BROKEN_GETCWD
volatile int old_cwd_fd = -1;
#else
}
if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
- prepend_file.filename = PG(auto_prepend_file);
- prepend_file.opened_path = NULL;
- prepend_file.free_filename = 0;
- prepend_file.type = ZEND_HANDLE_FILENAME;
+ zend_stream_init_filename(&prepend_file, PG(auto_prepend_file));
prepend_file_p = &prepend_file;
} else {
prepend_file_p = NULL;
}
if (PG(auto_append_file) && PG(auto_append_file)[0]) {
- append_file.filename = PG(auto_append_file);
- append_file.opened_path = NULL;
- append_file.free_filename = 0;
- append_file.type = ZEND_HANDLE_FILENAME;
+ zend_stream_init_filename(&append_file, PG(auto_append_file));
append_file_p = &append_file;
} else {
append_file_p = NULL;
highlight_file((char *)r->filename, &syntax_highlighter_ini);
} else {
zend_file_handle zfd;
-
- zfd.type = ZEND_HANDLE_FILENAME;
- zfd.filename = (char *) r->filename;
- zfd.free_filename = 0;
- zfd.opened_path = NULL;
+ zend_stream_init_filename(&zfd, (char *) r->filename);
if (!parent_req) {
php_execute_script(&zfd);
we need in the environment.
*/
if (SG(request_info).path_translated || cgi || fastcgi) {
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = SG(request_info).path_translated;
- file_handle.handle.fp = NULL;
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
+ zend_stream_init_filename(&file_handle, SG(request_info).path_translated);
} else {
zend_stream_init_fp(&file_handle, stdin, "Standard input code");
}
}
{
zend_file_handle zfd;
- zfd.type = ZEND_HANDLE_FILENAME;
- zfd.filename = SG(request_info).path_translated;
- zfd.handle.fp = NULL;
- zfd.free_filename = 0;
- zfd.opened_path = NULL;
+ zend_stream_init_filename(&zfd, SG(request_info).path_translated);
zend_try {
php_execute_script(&zfd);
} zend_end_try();
old_cwd[0] = '\0';
php_ignore_value(VCWD_GETCWD(old_cwd, MAXPATHLEN - 1));
- zfd.type = ZEND_HANDLE_FILENAME;
- zfd.filename = server->router;
- zfd.handle.fp = NULL;
- zfd.free_filename = 0;
- zfd.opened_path = NULL;
+ zend_stream_init_filename(&zfd, server->router);
zend_try {
zval retval;
{
char *p;
int len;
- file_handle->type = ZEND_HANDLE_FILENAME;
- file_handle->handle.fd = 0;
- file_handle->filename = SG(request_info).path_translated;
- file_handle->free_filename = 0;
- file_handle->opened_path = NULL;
+ zend_stream_init_filename(file_handle, SG(request_info).path_translated);
p = argv0;
*p++ = ':';