]> granicus.if.org Git - php/commitdiff
MFH: Add msg_queue_exists() function (Benjamin Schulz) [DOC]
authorJohannes Schlüter <johannes@php.net>
Tue, 20 Nov 2007 21:25:10 +0000 (21:25 +0000)
committerJohannes Schlüter <johannes@php.net>
Tue, 20 Nov 2007 21:25:10 +0000 (21:25 +0000)
NEWS
ext/sysvmsg/php_sysvmsg.h
ext/sysvmsg/sysvmsg.c
ext/sysvmsg/tests/003.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 35a4ab7ec3e205effff81e5d8bbbf651ca6a73ca..be25ce2d9975fa7dc9009cf46762ea60f556e4e7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 20??, PHP 5.3.0
+- 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,
   PDO::FB_ATTR_TIME_FORMAT and PDO::FB_ATTR_TIMESTAMP_FORMAT. 
index 70be76720af409a461f4231f1477a12390f336fb..d98edd4da1720d4c7a08f5a86363c07ca0f6071b 100644 (file)
@@ -48,6 +48,7 @@ PHP_FUNCTION(msg_stat_queue);
 PHP_FUNCTION(msg_set_queue);
 PHP_FUNCTION(msg_send);
 PHP_FUNCTION(msg_receive);
+PHP_FUNCTION(msg_queue_exists);
 
 typedef struct {
        key_t key;
index 7ab5b387f29cd1f3f938fb74df470844b3aa80ae..778f275ccc090e509d946644c473b8e8c77b55f6 100644 (file)
@@ -72,6 +72,7 @@ const zend_function_entry sysvmsg_functions[] = {
        PHP_FE(msg_remove_queue,                        NULL)
        PHP_FE(msg_stat_queue,                          NULL)
        PHP_FE(msg_set_queue,                           NULL)
+       PHP_FE(msg_queue_exists,                        NULL)
        {NULL, NULL, NULL}      /* Must be the last line in sysvmsg_functions[] */
 };
 /* }}} */
@@ -206,6 +207,26 @@ PHP_FUNCTION(msg_stat_queue)
 }
 /* }}} */
 
+
+/* {{{ proto bool msg_queue_exists(int key)
+   Check wether a message queue exists */
+PHP_FUNCTION(msg_queue_exists)
+{
+       long key;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &key) == FAILURE)     {
+               return;
+       }
+
+       if (msgget(key, 0) < 0) {
+               RETURN_FALSE;
+       }
+
+       RETURN_TRUE;
+}
+/* }}} */
+
+
 /* {{{ proto resource msg_get_queue(int key [, int perms])
    Attach to a message queue */
 PHP_FUNCTION(msg_get_queue)
diff --git a/ext/sysvmsg/tests/003.phpt b/ext/sysvmsg/tests/003.phpt
new file mode 100644 (file)
index 0000000..66ff046
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+msg_queue_exists()
+--SKIPIF--
+<?php if (!extension_loaded("sysvmsg")) die("skip sysvmsg extension is not available")?>
+--FILE--
+<?php
+$id = ftok(__FILE__, 'r');
+
+msg_remove_queue(msg_get_queue($id, 0600));
+
+var_dump(msg_queue_exists($id));
+$res = msg_get_queue($id, 0600);
+var_dump($res);
+var_dump(msg_queue_exists($id));
+var_dump(msg_remove_queue($res));
+var_dump(msg_queue_exists($id));
+echo "Done\n";
+?>
+--EXPECTF--
+bool(false)
+resource(%d) of type (sysvmsg queue)
+bool(true)
+bool(true)
+bool(false)
+Done