Avoid possible clash with mysql, but still make it work for BSD's.

Struct verified to be compatible with Linux, FreeBSD, BSDi, AIX 4.3.3 and
Solaris 5.7.
This commit is contained in:
Melvyn Sopacua 2002-10-27 11:56:06 +00:00
parent eef8649fa4
commit d95b71973e
3 changed files with 11 additions and 32 deletions

View file

@ -4,32 +4,6 @@ PHP_ARG_ENABLE(sysvmsg,whether to enable System V IPC support,
[ --enable-sysvmsg Enable sysvmsg support]) [ --enable-sysvmsg Enable sysvmsg support])
if test "$PHP_SYSVMSG" != "no"; then if test "$PHP_SYSVMSG" != "no"; then
AC_MSG_CHECKING([whether sys/msg.h defines struct msgbuf or mymsg])
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>],
[size_t i;
i = sizeof(struct msgbuf);
return 1;],
[AC_MSG_RESULT(msgbuf)],
[AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
],
[size_t i;
i = sizeof(struct mymsg);
return 1;
],
[AC_DEFINE(msgbuf, mymsg, [msgbuf is called mymsg])
AC_MSG_RESULT(mymsg)
],
[AC_MSG_ERROR([none. Cannot make sysvmsg module])
])
])
AC_DEFINE(HAVE_SYSVMSG, 1, [ ]) AC_DEFINE(HAVE_SYSVMSG, 1, [ ])
PHP_NEW_EXTENSION(sysvmsg, sysvmsg.c, $ext_shared) PHP_NEW_EXTENSION(sysvmsg, sysvmsg.c, $ext_shared)
fi fi

View file

@ -55,6 +55,11 @@ typedef struct {
long id; long id;
} sysvmsg_queue_t; } sysvmsg_queue_t;
struct php_msgbuf {
long mtype;
char mtext[1];
};
#endif /* HAVE_SYSVMSG */ #endif /* HAVE_SYSVMSG */
#endif /* PHP_SYSVMSG_H */ #endif /* PHP_SYSVMSG_H */

View file

@ -262,7 +262,7 @@ PHP_FUNCTION(msg_receive)
long realflags = 0; long realflags = 0;
zend_bool do_unserialize = 1; zend_bool do_unserialize = 1;
sysvmsg_queue_t *mq = NULL; sysvmsg_queue_t *mq = NULL;
struct msgbuf *messagebuffer = NULL; /* buffer to transmit */ struct php_msgbuf *messagebuffer = NULL; /* buffer to transmit */
int result; int result;
RETVAL_FALSE; RETVAL_FALSE;
@ -289,7 +289,7 @@ PHP_FUNCTION(msg_receive)
ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, &queue, -1, "sysvmsg queue", le_sysvmsg); ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, &queue, -1, "sysvmsg queue", le_sysvmsg);
messagebuffer = (struct msgbuf*)emalloc(sizeof(struct msgbuf) + maxsize); messagebuffer = (struct php_msgbuf*)emalloc(sizeof(struct php_msgbuf) + maxsize);
result = msgrcv(mq->id, messagebuffer, maxsize, desiredmsgtype, realflags); result = msgrcv(mq->id, messagebuffer, maxsize, desiredmsgtype, realflags);
@ -340,7 +340,7 @@ PHP_FUNCTION(msg_send)
long msgtype; long msgtype;
zend_bool do_serialize = 1, blocking = 1; zend_bool do_serialize = 1, blocking = 1;
sysvmsg_queue_t * mq = NULL; sysvmsg_queue_t * mq = NULL;
struct msgbuf * messagebuffer = NULL; /* buffer to transmit */ struct php_msgbuf * messagebuffer = NULL; /* buffer to transmit */
int result; int result;
int message_len = 0; int message_len = 0;
@ -360,15 +360,15 @@ PHP_FUNCTION(msg_send)
php_var_serialize(&msg_var, &message, &var_hash TSRMLS_CC); php_var_serialize(&msg_var, &message, &var_hash TSRMLS_CC);
PHP_VAR_SERIALIZE_DESTROY(var_hash); PHP_VAR_SERIALIZE_DESTROY(var_hash);
/* NB: msgbuf is 1 char bigger than a long, so there is no need to /* NB: php_msgbuf is 1 char bigger than a long, so there is no need to
* allocate the extra byte. */ * allocate the extra byte. */
messagebuffer = emalloc(sizeof(struct msgbuf) + msg_var.len); messagebuffer = emalloc(sizeof(struct php_msgbuf) + msg_var.len);
memcpy(messagebuffer->mtext, msg_var.c, msg_var.len + 1); memcpy(messagebuffer->mtext, msg_var.c, msg_var.len + 1);
message_len = msg_var.len; message_len = msg_var.len;
smart_str_free(&msg_var); smart_str_free(&msg_var);
} else { } else {
convert_to_string_ex(&message); convert_to_string_ex(&message);
messagebuffer = emalloc(sizeof(struct msgbuf) + Z_STRLEN_P(message)); messagebuffer = emalloc(sizeof(struct php_msgbuf) + Z_STRLEN_P(message));
memcpy(messagebuffer->mtext, Z_STRVAL_P(message), Z_STRLEN_P(message) + 1); memcpy(messagebuffer->mtext, Z_STRVAL_P(message), Z_STRLEN_P(message) + 1);
message_len = Z_STRLEN_P(message); message_len = Z_STRLEN_P(message);
} }