summaryrefslogtreecommitdiff
path: root/ext/sysvmsg
diff options
context:
space:
mode:
authorJohannes Schlüter <johannes@php.net>2007-11-20 21:25:10 +0000
committerJohannes Schlüter <johannes@php.net>2007-11-20 21:25:10 +0000
commit611a56fababe4a74297161b1827c13c0a1c67846 (patch)
treef47cd54572915f5815c8987491598fe9c97781e2 /ext/sysvmsg
parente077331077fac8232259d4872008c2c5724f8eab (diff)
downloadphp-git-611a56fababe4a74297161b1827c13c0a1c67846.tar.gz
MFH: Add msg_queue_exists() function (Benjamin Schulz) [DOC]
Diffstat (limited to 'ext/sysvmsg')
-rw-r--r--ext/sysvmsg/php_sysvmsg.h1
-rw-r--r--ext/sysvmsg/sysvmsg.c21
-rw-r--r--ext/sysvmsg/tests/003.phpt25
3 files changed, 47 insertions, 0 deletions
diff --git a/ext/sysvmsg/php_sysvmsg.h b/ext/sysvmsg/php_sysvmsg.h
index 70be76720a..d98edd4da1 100644
--- a/ext/sysvmsg/php_sysvmsg.h
+++ b/ext/sysvmsg/php_sysvmsg.h
@@ -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;
diff --git a/ext/sysvmsg/sysvmsg.c b/ext/sysvmsg/sysvmsg.c
index 7ab5b387f2..778f275ccc 100644
--- a/ext/sysvmsg/sysvmsg.c
+++ b/ext/sysvmsg/sysvmsg.c
@@ -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
index 0000000000..66ff046dd0
--- /dev/null
+++ b/ext/sysvmsg/tests/003.phpt
@@ -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