From: Johannes Schlüter Date: Tue, 20 Nov 2007 21:25:10 +0000 (+0000) Subject: MFH: Add msg_queue_exists() function (Benjamin Schulz) [DOC] X-Git-Tag: RELEASE_1_3_1~607 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=611a56fababe4a74297161b1827c13c0a1c67846;p=php MFH: Add msg_queue_exists() function (Benjamin Schulz) [DOC] --- diff --git a/NEWS b/NEWS index 35a4ab7ec3..be25ce2d99 100644 --- 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. 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-- + +--FILE-- + +--EXPECTF-- +bool(false) +resource(%d) of type (sysvmsg queue) +bool(true) +bool(true) +bool(false) +Done