2222#include <unistd.h>
2323#include "ext/standard/info.h"
2424#include "php_posix.h"
25+ #include "main/php_network.h"
2526
2627#ifdef HAVE_POSIX
2728
@@ -415,7 +416,7 @@ PHP_FUNCTION(posix_ctermid)
415416/* }}} */
416417
417418/* Checks if the provides resource is a stream and if it provides a file descriptor */
418- static zend_result php_posix_stream_get_fd (zval * zfp , zend_long * fd ) /* {{{ */
419+ static zend_result php_posix_stream_get_fd (zval * zfp , zend_long * ret ) /* {{{ */
419420{
420421 php_stream * stream ;
421422
@@ -425,19 +426,21 @@ static zend_result php_posix_stream_get_fd(zval *zfp, zend_long *fd) /* {{{ */
425426 return FAILURE ;
426427 }
427428
428- /* get the fd.
429+ /* get the fd. php_socket_t is used for FDs, and is shorter than zend_long.
429430 * NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag when casting.
430431 * It is only used here so that the buffered data warning is not displayed.
431432 */
433+ php_socket_t fd = -1 ;
432434 if (php_stream_can_cast (stream , PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL ) == SUCCESS ) {
433- php_stream_cast (stream , PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL , (void * ) fd , 0 );
435+ php_stream_cast (stream , PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL , (void * * ) & fd , 0 );
434436 } else if (php_stream_can_cast (stream , PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL ) == SUCCESS ) {
435- php_stream_cast (stream , PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL , (void * ) fd , 0 );
437+ php_stream_cast (stream , PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL , (void * * ) & fd , 0 );
436438 } else {
437439 php_error_docref (NULL , E_WARNING , "Could not use stream of type '%s'" ,
438440 stream -> ops -> label );
439441 return FAILURE ;
440442 }
443+ * ret = fd ;
441444 return SUCCESS ;
442445}
443446/* }}} */
0 commit comments