]> granicus.if.org Git - php/commitdiff
Add stream_supports_lock() function (Benjamin Schulz)
authorJohannes Schlüter <johannes@php.net>
Tue, 20 Nov 2007 22:16:20 +0000 (22:16 +0000)
committerJohannes Schlüter <johannes@php.net>
Tue, 20 Nov 2007 22:16:20 +0000 (22:16 +0000)
ext/standard/basic_functions.c
ext/standard/streamsfuncs.c
ext/standard/streamsfuncs.h
ext/standard/tests/file/stream_supports_lock.phpt [new file with mode: 0644]

index 49bc6113d810533831261d39835b177077165ed7..24fa3012980f09be214cd1c2b4db2f340b184a13 100644 (file)
@@ -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)
index 7f0effed925910bbc49be4981a7af93eec64efbb..95c04883d9aa52427a2dc808e8f35126bce01652 100644 (file)
@@ -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
index 5350d0fe81996f1c2aa4842e38376eed65ea9685..ef7833203a08114fc7c8cf2d7e078a69c24ccd8b 100644 (file)
@@ -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 (file)
index 0000000..8b19903
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--
+stream_supports_lock
+--FILE--
+<?php
+$fp = fopen(__FILE__, "r");
+var_dump($fp);
+var_dump(stream_supports_lock($fp));
+fclose($fp);
+
+$fp = fopen("file://" . __FILE__, "r");
+var_dump($fp);
+var_dump(stream_supports_lock($fp));
+fclose($fp);
+
+$fp = fopen("php://memory", "r");
+var_dump($fp);
+var_dump(stream_supports_lock($fp));
+fclose($fp);
+
+$fp = fopen('data://text/plain,foobar', 'r');
+var_dump($fp);
+var_dump(stream_supports_lock($fp));
+fclose($fp);
+
+$sock = stream_context_create();
+var_dump($sock);
+var_dump(stream_supports_lock($sock));
+
+echo "Done\n";
+?>
+--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