]> granicus.if.org Git - php/commitdiff
Use and supply zend_open func
authorSascha Schumann <sas@php.net>
Tue, 13 May 2003 23:09:27 +0000 (23:09 +0000)
committerSascha Schumann <sas@php.net>
Tue, 13 May 2003 23:09:27 +0000 (23:09 +0000)
main/main.c
main/php_streams.h
main/streams.c

index 2ebad78e60b011c408feaf056c255350c376ac00..183531460a5480f981ea7e9408c36e7d6a77a5a5 100644 (file)
@@ -767,6 +767,17 @@ static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path
 }
 /* }}} */
 
+
+/* {{{ php_open_wrapper_for_zend
+ */
+static zend_bool php_open_wrapper_for_zend(const char *filename, struct _zend_file_handle *fh)
+{
+       TSRMLS_FETCH();
+
+       return php_stream_open_wrapper_as_file_handle((char *)filename, "rb", ENFORCE_SAFE_MODE|USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, fh);
+}
+/* }}} */
+
 /* {{{ php_get_configuration_directive_for_zend
  */
 static int php_get_configuration_directive_for_zend(char *name, uint name_length, zval *contents)
@@ -1100,6 +1111,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
        zuf.printf_function = php_printf;
        zuf.write_function = php_body_write_wrapper;
        zuf.fopen_function = php_fopen_wrapper_for_zend;
+       zuf.open_function = php_open_wrapper_for_zend;
        zuf.message_handler = php_message_handler_for_zend;
        zuf.block_interruptions = sapi_module.block_interruptions;
        zuf.unblock_interruptions = sapi_module.unblock_interruptions;
index 01dfa2cfd6eae187311e9ba595928802db7d89a1..83e8c8b71c03a6d11e4fdea1fd16915be48e78fc 100755 (executable)
@@ -553,6 +553,10 @@ PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstr
 PHPAPI FILE * _php_stream_open_wrapper_as_file(char * path, char * mode, int options, char **opened_path STREAMS_DC TSRMLS_DC);
 #define php_stream_open_wrapper_as_file(path, mode, options, opened_path) _php_stream_open_wrapper_as_file((path), (mode), (options), (opened_path) STREAMS_CC TSRMLS_CC)
 
+
+PHPAPI zend_bool _php_stream_open_wrapper_as_file_handle(char * path, char * mode, int options, zend_file_handle * STREAMS_DC TSRMLS_DC);
+#define php_stream_open_wrapper_as_file_handle(path, mode, options, fh) _php_stream_open_wrapper_as_file_handle((path), (mode), (options), (fh) STREAMS_CC TSRMLS_CC)
+
 /* for user-space streams */
 PHPAPI extern php_stream_ops php_stream_userspace_ops;
 PHPAPI extern php_stream_ops php_stream_userspace_dir_ops;
index 5776a0e3264a0e8636e18bd7d5c6151179b4809b..5c6108a9156b32946d0fbaa9fc5d6da90794840f 100755 (executable)
@@ -2704,6 +2704,42 @@ PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int optio
 }
 /* }}} */
 
+
+
+/* {{{ php_stream_open_wrapper_as_file_handle */
+PHPAPI zend_bool _php_stream_open_wrapper_as_file_handle(char *path, char *mode, int options, zend_file_handle *fh STREAMS_DC TSRMLS_DC)
+{
+       php_stream *stream = NULL;
+
+       stream = php_stream_open_wrapper_rel(path, mode, options|STREAM_WILL_CAST, &fh->opened_path);
+
+       if (stream == NULL)
+               return FAILURE;
+
+       if (php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_TRY_HARD 
+                               | PHP_STREAM_CAST_RELEASE, (void **) &fh->handle.fd, 
+                               REPORT_ERRORS) == SUCCESS) {
+               if ((options & STREAM_OPEN_FOR_INCLUDE) 
+                               && php_stream_is(stream, PHP_STREAM_IS_SOCKET)) {
+                       fh->type = ZEND_HANDLE_SOCKET_FD;
+               } else {
+                       fh->type = ZEND_HANDLE_FD;
+               }
+       } else if (php_stream_cast(stream, PHP_STREAM_AS_STDIO
+                               |PHP_STREAM_CAST_TRY_HARD | PHP_STREAM_CAST_RELEASE,
+                               (void**) &fh->handle.fp, REPORT_ERRORS) == SUCCESS) {
+               fh->type = ZEND_HANDLE_FP;
+       } else {
+               php_stream_close(stream);
+               if (fh->opened_path)
+                       efree(fh->opened_path);
+               fh->opened_path = NULL;
+               return FAILURE;
+       }
+       return SUCCESS;
+}
+/* }}} */
+
 /* {{{ php_stream_make_seekable */
 PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream, int flags STREAMS_DC TSRMLS_DC)
 {