]> granicus.if.org Git - php/commitdiff
Make these all work with persistent streams too.
authorWez Furlong <wez@php.net>
Wed, 25 Sep 2002 15:46:47 +0000 (15:46 +0000)
committerWez Furlong <wez@php.net>
Wed, 25 Sep 2002 15:46:47 +0000 (15:46 +0000)
ext/ftp/php_ftp.c
ext/interbase/interbase.c
ext/ming/ming.c
ext/pdf/pdf.c
ext/posix/posix.c
ext/recode/recode.c
ext/standard/exec.c
ext/standard/file.c

index d1aa51b45fbacfcad0071092428f4dc12b211232..b7d00e57b942944f4937ecc2d800239ba86e451d 100644 (file)
@@ -476,7 +476,7 @@ PHP_FUNCTION(ftp_async_fget)
        }
 
        ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
-       ZEND_FETCH_RESOURCE(stream, php_stream*, &z_file, -1, "File-Handle", php_file_le_stream());
+       php_stream_from_zval(stream, &z_file);
        XTYPE(xtype, mode);
 
        /* ignore autoresume if autoseek is switched off */
@@ -702,7 +702,7 @@ PHP_FUNCTION(ftp_fput)
        }
 
        ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
-       ZEND_FETCH_RESOURCE(stream, php_stream*, &z_file, -1, "File-Handle", php_file_le_stream());
+       php_stream_from_zval(stream, &z_file);
        XTYPE(xtype, mode);
 
        /* ignore autoresume if autoseek is switched off */
@@ -748,7 +748,7 @@ PHP_FUNCTION(ftp_async_fput)
        }
 
        ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
-       ZEND_FETCH_RESOURCE(stream, php_stream*, &z_file, -1, "File-Handle", php_file_le_stream());
+       php_stream_from_zval(stream, &z_file);
        XTYPE(xtype, mode);
 
        /* ignore autoresume if autoseek is switched off */
index a194daca59b7a73b78c55f21de8952382a5e5570..63e88bf7b2d257970fee370eeeb13304e627e2a2 100644 (file)
@@ -2911,8 +2911,7 @@ PHP_FUNCTION(ibase_blob_import)
                RETURN_FALSE;
        }
 
-       stream = (php_stream*)zend_fetch_resource(file_arg TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream());
-       ZEND_VERIFY_RESOURCE(stream);
+       php_stream_from_zval(stream, file_arg);
        
        ib_blob.link = ib_link->link;
        ib_blob.trans_handle = ib_link->trans[trans_n];
index 4c0f5f6ce90577d7707c1ae719150a25146a0a1a..bcf81cd1aeba5bc320bbe11c57dd8d414121b030 100644 (file)
@@ -195,13 +195,15 @@ static void destroy_SWFInput_resource(zend_rsrc_list_entry *resource TSRMLS_DC)
 static SWFInput getInput(zval **zfile TSRMLS_DC)
 {
        FILE *file;
-       void *what;
-       int type;
+       php_stream *stream;
        SWFInput input;
 
-       what = zend_fetch_resource(zfile TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream());
+       php_stream_from_zval_no_verify(stream, zfile);
+
+       if (stream == NULL)
+               return NULL;
 
-       if (php_stream_cast((php_stream*)what, PHP_STREAM_AS_STDIO, (void *) &file, REPORT_ERRORS) != SUCCESS) {
+       if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void *) &file, REPORT_ERRORS) != SUCCESS) {
                return NULL;
        }
   
@@ -1449,7 +1451,7 @@ PHP_FUNCTION(swfmovie_saveToFile)
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &x) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
-       ZEND_FETCH_RESOURCE(what, php_stream *, x, -1,"File-Handle",php_file_le_stream());
+       php_stream_from_zval(what, x);
        RETURN_LONG(SWFMovie_output(movie, &phpStreamOutputMethod, what));
 }
 /* }}} */
@@ -1467,7 +1469,7 @@ PHP_FUNCTION(swfmovie_save)
        }
 
        if (Z_TYPE_PP(x) == IS_RESOURCE) {
-               ZEND_FETCH_RESOURCE(stream, php_stream *, x, -1,"File-Handle",php_file_le_stream());
+               php_stream_from_zval(stream, x);
                RETURN_LONG(SWFMovie_output(getMovie(getThis() TSRMLS_CC), &phpStreamOutputMethod, stream));
        }
 
index ddc7262aecae690505266d23988d9f39f83a82f5..ce169f7bddd6c697477af9ce9653bc1749562dca 100644 (file)
@@ -449,30 +449,30 @@ PHP_FUNCTION(pdf_set_info_keywords)
 PHP_FUNCTION(pdf_open)
 {
        zval **file;
-       void *what;
-       int type;
        FILE *fp = NULL;
        PDF *pdf;
        int argc = ZEND_NUM_ARGS();
 
-       if(argc > 1) 
+       if(argc > 1)  {
                WRONG_PARAM_COUNT;
-       if (argc != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
+       } else if (argc != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
                fp = NULL;
        } else {
-               what = zend_fetch_resource(file TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream());
-               ZEND_VERIFY_RESOURCE(what);
+               php_stream *stream;
+
+               php_stream_from_zval(stream, file);
                
-               if (php_stream_cast((php_stream*)what, PHP_STREAM_AS_STDIO, (void*)&fp, 1) == FAILURE)  {
+               if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void*)&fp, 1) == FAILURE)     {
                        RETURN_FALSE;
                }
-               /* XXX should do a zend_list_addref for <fp> here! */
        }
 
        pdf = PDF_new2(custom_errorhandler, pdf_emalloc, pdf_realloc, pdf_efree, NULL);
 
        if(fp) {
-               if (PDF_open_fp(pdf, fp) < 0) RETURN_FALSE;
+               if (PDF_open_fp(pdf, fp) < 0) {
+                       RETURN_FALSE;
+               }
        } else {
                PDF_open_mem(pdf, pdf_flushwrite);
        }
index ba0fd292b7b03fd5bf5d144d916e38c1f86337af..519c177e7906609524453020454c4782b36d354f 100644 (file)
@@ -25,7 +25,6 @@
 #include "php.h"
 #include "ext/standard/info.h"
 #include "ext/standard/php_string.h"
-#include "ext/standard/file.h" /* Provides php_file_le_stream() */
 #include "php_posix.h"
 
 #if HAVE_POSIX
@@ -582,22 +581,21 @@ PHP_FUNCTION(posix_ctermid)
 /* }}} */
 
 /* Checks if the provides resource is a stream and if it provides a file descriptor */
-static int php_posix_stream_get_fd(long rsrc_id, int *fd TSRMLS_DC)
+static int php_posix_stream_get_fd(zval *zfp, int *fd TSRMLS_DC)
 {
        php_stream *stream;
-       int rsrc_type;
 
-       stream = zend_list_find(rsrc_id, &rsrc_type);
-       if (!stream || rsrc_type != php_file_le_stream()) {
-               php_error(E_WARNING, "%s() expects argument 1 to be a valid stream resource",
-                                 get_active_function_name(TSRMLS_C));
+       php_stream_from_zval_no_verify(stream, &zfp);
+
+       if (stream == NULL) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "expects argument 1 to be a valid stream resource");
                return 0;
        }
        if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) {
                php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)fd, 0);
        } else {
-               php_error(E_WARNING, "%s() could not use stream of type '%s'",
-                                 get_active_function_name(TSRMLS_C), stream->ops->label);
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not use stream of type '%s'", 
+                               stream->ops->label);
                return 0;
        }
        return 1;
@@ -616,7 +614,7 @@ PHP_FUNCTION(posix_ttyname)
 
        switch (Z_TYPE_P(z_fd)) {
                case IS_RESOURCE:
-                       if (!php_posix_stream_get_fd(Z_RESVAL_P(z_fd), &fd TSRMLS_CC)) {
+                       if (!php_posix_stream_get_fd(z_fd, &fd TSRMLS_CC)) {
                                RETURN_FALSE;
                        }
                        break;
@@ -646,7 +644,7 @@ PHP_FUNCTION(posix_isatty)
 
        switch (Z_TYPE_P(z_fd)) {
                case IS_RESOURCE:
-                       if (!php_posix_stream_get_fd(Z_RESVAL_P(z_fd), &fd TSRMLS_CC)) {
+                       if (!php_posix_stream_get_fd(z_fd, &fd TSRMLS_CC)) {
                                RETURN_FALSE;
                        }
                        break;
index 9c1c8374406fd321fb10bfeb4d42b267b272ba00..cbcc6bf985c6dc8e26484644a74b8ef7e232362f 100644 (file)
@@ -184,28 +184,18 @@ PHP_FUNCTION(recode_file)
        zval **input, **output;
        php_stream *instream, *outstream;
        FILE  *in_fp,  *out_fp;
-       int    in_type, out_type;
 
        if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &req, &input, &output) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
 
-       instream = zend_fetch_resource(input TSRMLS_CC,-1, "File-Handle", &in_type, 1, php_file_le_stream());
-
-       if (!instream) {
-               php_error(E_WARNING,"Unable to find input file identifier");
-               RETURN_FALSE;
-       }
+       php_stream_from_zval(instream, input);
+       php_stream_from_zval(outstream, output);
 
        if (FAILURE == php_stream_cast(instream, PHP_STREAM_AS_STDIO, (void**)&in_fp, REPORT_ERRORS))   {
                RETURN_FALSE;
        }
        
-       outstream = zend_fetch_resource(output TSRMLS_CC,-1, "File-Handle", &out_type, 1, php_file_le_stream());
-       if (!outstream) {
-               php_error(E_WARNING,"Unable to find output file identifier");
-               RETURN_FALSE;
-       }
        if (FAILURE == php_stream_cast(outstream, PHP_STREAM_AS_STDIO, (void**)&out_fp, REPORT_ERRORS)) {
                RETURN_FALSE;
        }
index a855040a99910714671a6256ba0646f59c9f4046..441ae1f6655af74ac6ace179d93203e0542b2727 100644 (file)
@@ -732,7 +732,7 @@ PHP_FUNCTION(proc_open)
                        php_stream *stream;
                        int fd;
 
-                       ZEND_FETCH_RESOURCE(stream, php_stream *, descitem, -1, "File-Handle", php_file_le_stream());
+                       php_stream_from_zval(stream, descitem);
 
                        if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **)&fd, REPORT_ERRORS)) {
                                goto exit_fail;
index 20ad89d4136fcc54e89f807f30f9022a5f073b2e..75300986d8ab089ed0ff356383ecf26b8de08b7b 100644 (file)
@@ -1243,7 +1243,7 @@ PHPAPI PHP_FUNCTION(fgetss)
 }
 /* }}} */
 
-/* {{{ proto mixed fscanf(string str, string format [, string ...])
+/* {{{ proto mixed fscanf(resource stream, string format [, string ...])
    Implements a mostly ANSI compatible fscanf() */
 PHP_FUNCTION(fscanf)
 {