From: Johannes Schlüter Date: Tue, 20 Nov 2007 22:17:01 +0000 (+0000) Subject: MFH: Add stream_supports_lock() function (Benjamin Schulz) X-Git-Tag: RELEASE_1_3_1~605 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbf466a9530d7c2ff0a522c0c17c9d826824b1f9;p=php MFH: Add stream_supports_lock() function (Benjamin Schulz) --- diff --git a/NEWS b/NEWS index be25ce2d99..ec7285a906 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 20??, PHP 5.3.0 +- Added stream_supports_lock() function (Benjamin Schulz) - Added msg_queue_exists() function (Benjamin Schulz) - Added 3 Firebird specific attributes that can be set via PDO::setAttribute() to control formatting of date/timestamp columns: PDO::FB_ATTR_DATE_FORMAT, diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 93057d9e09..09db3e3566 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2318,6 +2318,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_stream_is_local, 0) ZEND_ARG_INFO(0, stream) ZEND_END_ARG_INFO() +static +ZEND_BEGIN_ARG_INFO_EX(arginfo_stream_supports_lock, 0, 0, 1) + ZEND_ARG_INFO(0, stream) +ZEND_END_ARG_INFO() + static ZEND_BEGIN_ARG_INFO_EX(arginfo_stream_select, 0, 0, 4) ZEND_ARG_INFO(1, read_streams) /* ARRAY_INFO(1, read_streams, 1) */ @@ -3493,6 +3498,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */ #endif PHP_FE(stream_copy_to_stream, arginfo_stream_copy_to_stream) PHP_FE(stream_get_contents, arginfo_stream_get_contents) + PHP_FE(stream_supports_lock, arginfo_stream_supports_lock) PHP_FE(fgetcsv, arginfo_fgetcsv) PHP_FE(fputcsv, arginfo_fputcsv) PHP_FE(flock, arginfo_flock) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 456e6579a8..6fd18012c9 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1375,6 +1375,26 @@ PHP_FUNCTION(stream_is_local) } /* }}} */ +/* {{{ proto bool stream_supports_lock(resource stream) + Tells wether the stream supports locking through flock(). */ +PHP_FUNCTION(stream_supports_lock) +{ + php_stream *stream; + zval *zsrc; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsrc) == FAILURE) { + RETURN_FALSE; + } + + php_stream_from_zval(stream, &zsrc); + + if (!php_stream_supports_lock(stream)) { + RETURN_FALSE; + } + + RETURN_TRUE; +} + #ifdef HAVE_SHUTDOWN /* {{{ proto int stream_socket_shutdown(resource stream, int how) causes all or part of a full-duplex connection on the socket associated diff --git a/ext/standard/streamsfuncs.h b/ext/standard/streamsfuncs.h index 16b4a7eca8..4c85ae0772 100644 --- a/ext/standard/streamsfuncs.h +++ b/ext/standard/streamsfuncs.h @@ -56,6 +56,7 @@ PHP_FUNCTION(stream_socket_enable_crypto); PHP_FUNCTION(stream_socket_shutdown); PHP_FUNCTION(stream_socket_pair); PHP_FUNCTION(stream_is_local); +PHP_FUNCTION(stream_supports_lock); /* * Local variables: diff --git a/ext/standard/tests/file/stream_supports_lock.phpt b/ext/standard/tests/file/stream_supports_lock.phpt new file mode 100644 index 0000000000..8b199032de --- /dev/null +++ b/ext/standard/tests/file/stream_supports_lock.phpt @@ -0,0 +1,44 @@ +--TEST-- +stream_supports_lock +--FILE-- + +--EXPECTF-- +resource(%d) of type (stream) +bool(true) +resource(%d) of type (stream) +bool(true) +resource(%d) of type (stream) +bool(false) +resource(%d) of type (stream) +bool(false) +resource(%d) of type (stream-context) + +Warning: stream_supports_lock(): supplied resource is not a valid stream resource in %s on line %d +bool(false) +Done