}
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 */
}
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 */
}
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 */
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];
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;
}
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));
}
/* }}} */
}
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));
}
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);
}
#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
/* }}} */
/* 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;
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;
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;
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;
}
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;
}
/* }}} */
-/* {{{ 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)
{