cvs: php4 /ext/posix posix.c

From: Date: Mon, 03 Jun 2002 20:52:08 +0000
Subject: cvs: php4 /ext/posix posix.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-12214@lists.php.net to get a copy of this message
mfischer Mon Jun 3 16:52:08 2002 EDT Modified files: /php4/ext/posix posix.c Log: - Move macro code into distinct function for easier debugging as suggested by Andi. Index: php4/ext/posix/posix.c diff -u php4/ext/posix/posix.c:1.48 php4/ext/posix/posix.c:1.49 --- php4/ext/posix/posix.c:1.48 Mon Jun 3 11:49:38 2002 +++ php4/ext/posix/posix.c Mon Jun 3 16:52:07 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: posix.c,v 1.48 2002/06/03 15:49:38 mfischer Exp $ */ +/* $Id: posix.c,v 1.49 2002/06/03 20:52:07 mfischer Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -25,7 +25,7 @@ #include "php.h" #include "ext/standard/info.h" #include "ext/standard/php_string.h" -#include "ext/standard/file.h" +#include "ext/standard/file.h" /* Provides php_file_le_stream() */ #include "php_posix.h" #if HAVE_POSIX @@ -131,7 +131,7 @@ static PHP_MINFO_FUNCTION(posix) { php_info_print_table_start(); - php_info_print_table_row(2, "Revision", "$Revision: 1.48 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.49 $"); php_info_print_table_end(); } /* }}} */ @@ -581,21 +581,27 @@ #endif /* }}} */ -#define STREAM_GET_FD() \ - stream = zend_list_find(Z_LVAL_P(z_fd), &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)); \ - return; \ - } \ - 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); \ - return; \ - } +/* 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) +{ + 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)); + 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); + return 0; + } + return 1; +} /* {{{ proto string posix_ttyname(int fd) Determine terminal device name (POSIX.1, 4.7.2) */ @@ -603,15 +609,16 @@ { zval *z_fd; char *p; - php_stream *stream; - int rsrc_type, fd; + int fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_fd) == FAILURE) return; switch (Z_TYPE_P(z_fd)) { case IS_RESOURCE: - STREAM_GET_FD(); + if (!php_posix_stream_get_fd(Z_RESVAL_P(z_fd), &fd)) { + RETURN_FALSE; + } break; default: convert_to_long(z_fd); @@ -632,15 +639,16 @@ PHP_FUNCTION(posix_isatty) { zval *z_fd; - php_stream *stream; - int rsrc_type, fd; + int fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_fd) == FAILURE) return; switch (Z_TYPE_P(z_fd)) { case IS_RESOURCE: - STREAM_GET_FD(); + if (!php_posix_stream_get_fd(Z_RESVAL_P(z_fd), &fd)) { + RETURN_FALSE; + } break; default: convert_to_long(z_fd);

« previous php.cvs (#12214) next »