From 6e7ba5ba5f6817f2f897c034a730091c46172af0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Schl=C3=BCter?= Date: Tue, 20 Nov 2007 22:16:20 +0000 Subject: [PATCH] Add stream_supports_lock() function (Benjamin Schulz) --- ext/standard/basic_functions.c | 6 +++ ext/standard/streamsfuncs.c | 20 +++++++++ ext/standard/streamsfuncs.h | 1 + .../tests/file/stream_supports_lock.phpt | 44 +++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 ext/standard/tests/file/stream_supports_lock.phpt diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 49bc6113d8..24fa301298 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2309,6 +2309,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) */ @@ -3532,6 +3537,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(stream_resolve_include_path, arginfo_stream_resolve_include_path) PHP_FE(fgetcsv, arginfo_fgetcsv) PHP_FE(fputcsv, arginfo_fputcsv) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 7f0effed92..95c04883d9 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1677,6 +1677,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) U 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 5350d0fe81..ef7833203a 100644 --- a/ext/standard/streamsfuncs.h +++ b/ext/standard/streamsfuncs.h @@ -58,6 +58,7 @@ PHP_FUNCTION(stream_socket_shutdown); PHP_FUNCTION(stream_socket_pair); PHP_FUNCTION(stream_resolve_include_path); 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 -- 2.50.1