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