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(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 */

View 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];

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)
{
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 (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;
}
@ -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));
}

View 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);
}

View 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;

View 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;
}

View 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;

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() */
PHP_FUNCTION(fscanf)
{