From e630ee25d6e756c31ebdd4112d0acd783279b155 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Schl=C3=BCter?= Date: Tue, 20 Nov 2007 21:24:35 +0000 Subject: [PATCH] Add msg_queue_exists() function (Benjamin Schulz) --- ext/sysvmsg/php_sysvmsg.h | 1 + ext/sysvmsg/sysvmsg.c | 19 +++++++++++++++++++ ext/sysvmsg/tests/003.phpt | 25 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 ext/sysvmsg/tests/003.phpt 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 ca76101641..09b196537f 100644 --- a/ext/sysvmsg/sysvmsg.c +++ b/ext/sysvmsg/sysvmsg.c @@ -73,6 +73,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[] */ }; /* }}} */ @@ -217,6 +218,24 @@ 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]) U 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-- + +--FILE-- + +--EXPECTF-- +bool(false) +resource(%d) of type (sysvmsg queue) +bool(true) +bool(true) +bool(false) +Done -- 2.50.1