Make these all work with persistent streams too.

This commit is contained in:
Wez Furlong 2002-09-25 15:46:47 +00:00
parent 696e0a2301
commit 0141e97052
8 changed files with 34 additions and 45 deletions

View 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(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); XTYPE(xtype, mode);
/* ignore autoresume if autoseek is switched off */ /* 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(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); XTYPE(xtype, mode);
/* ignore autoresume if autoseek is switched off */ /* 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(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); XTYPE(xtype, mode);
/* ignore autoresume if autoseek is switched off */ /* ignore autoresume if autoseek is switched off */

View file

@ -2911,8 +2911,7 @@ PHP_FUNCTION(ibase_blob_import)
RETURN_FALSE; RETURN_FALSE;
} }
stream = (php_stream*)zend_fetch_resource(file_arg TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream()); php_stream_from_zval(stream, file_arg);
ZEND_VERIFY_RESOURCE(stream);
ib_blob.link = ib_link->link; ib_blob.link = ib_link->link;
ib_blob.trans_handle = ib_link->trans[trans_n]; ib_blob.trans_handle = ib_link->trans[trans_n];

View file

@ -195,13 +195,15 @@ static void destroy_SWFInput_resource(zend_rsrc_list_entry *resource TSRMLS_DC)
static SWFInput getInput(zval **zfile TSRMLS_DC) static SWFInput getInput(zval **zfile TSRMLS_DC)
{ {
FILE *file; FILE *file;
void *what; php_stream *stream;
int type;
SWFInput input; 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 (php_stream_cast((php_stream*)what, PHP_STREAM_AS_STDIO, (void *) &file, REPORT_ERRORS) != SUCCESS) { if (stream == NULL)
return NULL;
if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void *) &file, REPORT_ERRORS) != SUCCESS) {
return NULL; return NULL;
} }
@ -1449,7 +1451,7 @@ PHP_FUNCTION(swfmovie_saveToFile)
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &x) == FAILURE) { if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &x) == FAILURE) {
WRONG_PARAM_COUNT; 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)); RETURN_LONG(SWFMovie_output(movie, &phpStreamOutputMethod, what));
} }
/* }}} */ /* }}} */
@ -1467,7 +1469,7 @@ PHP_FUNCTION(swfmovie_save)
} }
if (Z_TYPE_PP(x) == IS_RESOURCE) { 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)); RETURN_LONG(SWFMovie_output(getMovie(getThis() TSRMLS_CC), &phpStreamOutputMethod, stream));
} }

View file

@ -449,30 +449,30 @@ PHP_FUNCTION(pdf_set_info_keywords)
PHP_FUNCTION(pdf_open) PHP_FUNCTION(pdf_open)
{ {
zval **file; zval **file;
void *what;
int type;
FILE *fp = NULL; FILE *fp = NULL;
PDF *pdf; PDF *pdf;
int argc = ZEND_NUM_ARGS(); int argc = ZEND_NUM_ARGS();
if(argc > 1) if(argc > 1) {
WRONG_PARAM_COUNT; 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; fp = NULL;
} else { } else {
what = zend_fetch_resource(file TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream()); php_stream *stream;
ZEND_VERIFY_RESOURCE(what);
if (php_stream_cast((php_stream*)what, PHP_STREAM_AS_STDIO, (void*)&fp, 1) == FAILURE) { php_stream_from_zval(stream, file);
if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void*)&fp, 1) == FAILURE) {
RETURN_FALSE; RETURN_FALSE;
} }
/* XXX should do a zend_list_addref for <fp> here! */
} }
pdf = PDF_new2(custom_errorhandler, pdf_emalloc, pdf_realloc, pdf_efree, NULL); pdf = PDF_new2(custom_errorhandler, pdf_emalloc, pdf_realloc, pdf_efree, NULL);
if(fp) { if(fp) {
if (PDF_open_fp(pdf, fp) < 0) RETURN_FALSE; if (PDF_open_fp(pdf, fp) < 0) {
RETURN_FALSE;
}
} else { } else {
PDF_open_mem(pdf, pdf_flushwrite); PDF_open_mem(pdf, pdf_flushwrite);
} }

View file

@ -25,7 +25,6 @@
#include "php.h" #include "php.h"
#include "ext/standard/info.h" #include "ext/standard/info.h"
#include "ext/standard/php_string.h" #include "ext/standard/php_string.h"
#include "ext/standard/file.h" /* Provides php_file_le_stream() */
#include "php_posix.h" #include "php_posix.h"
#if HAVE_POSIX #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 */ /* 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; php_stream *stream;
int rsrc_type;
stream = zend_list_find(rsrc_id, &rsrc_type); php_stream_from_zval_no_verify(stream, &zfp);
if (!stream || rsrc_type != php_file_le_stream()) {
php_error(E_WARNING, "%s() expects argument 1 to be a valid stream resource", if (stream == NULL) {
get_active_function_name(TSRMLS_C)); php_error_docref(NULL TSRMLS_CC, E_WARNING, "expects argument 1 to be a valid stream resource");
return 0; return 0;
} }
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) { if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) {
php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)fd, 0); php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)fd, 0);
} else { } else {
php_error(E_WARNING, "%s() could not use stream of type '%s'", php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not use stream of type '%s'",
get_active_function_name(TSRMLS_C), stream->ops->label); stream->ops->label);
return 0; return 0;
} }
return 1; return 1;
@ -616,7 +614,7 @@ PHP_FUNCTION(posix_ttyname)
switch (Z_TYPE_P(z_fd)) { switch (Z_TYPE_P(z_fd)) {
case IS_RESOURCE: 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; RETURN_FALSE;
} }
break; break;
@ -646,7 +644,7 @@ PHP_FUNCTION(posix_isatty)
switch (Z_TYPE_P(z_fd)) { switch (Z_TYPE_P(z_fd)) {
case IS_RESOURCE: 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; RETURN_FALSE;
} }
break; break;

View file

@ -184,28 +184,18 @@ PHP_FUNCTION(recode_file)
zval **input, **output; zval **input, **output;
php_stream *instream, *outstream; php_stream *instream, *outstream;
FILE *in_fp, *out_fp; FILE *in_fp, *out_fp;
int in_type, out_type;
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &req, &input, &output) == FAILURE) { if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &req, &input, &output) == FAILURE) {
WRONG_PARAM_COUNT; WRONG_PARAM_COUNT;
} }
instream = zend_fetch_resource(input TSRMLS_CC,-1, "File-Handle", &in_type, 1, php_file_le_stream()); php_stream_from_zval(instream, input);
php_stream_from_zval(outstream, output);
if (!instream) {
php_error(E_WARNING,"Unable to find input file identifier");
RETURN_FALSE;
}
if (FAILURE == php_stream_cast(instream, PHP_STREAM_AS_STDIO, (void**)&in_fp, REPORT_ERRORS)) { if (FAILURE == php_stream_cast(instream, PHP_STREAM_AS_STDIO, (void**)&in_fp, REPORT_ERRORS)) {
RETURN_FALSE; 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)) { if (FAILURE == php_stream_cast(outstream, PHP_STREAM_AS_STDIO, (void**)&out_fp, REPORT_ERRORS)) {
RETURN_FALSE; RETURN_FALSE;
} }

View file

@ -732,7 +732,7 @@ PHP_FUNCTION(proc_open)
php_stream *stream; php_stream *stream;
int fd; 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)) { if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **)&fd, REPORT_ERRORS)) {
goto exit_fail; goto exit_fail;

View 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() */ Implements a mostly ANSI compatible fscanf() */
PHP_FUNCTION(fscanf) PHP_FUNCTION(fscanf)
{ {