Hi all,
I'm using a piece of code from a book (Linux Programming) which includes some IPC related excerpts I'd like to use (queue stuff).
Here's some code that I'm using from the book, which produces the below compiler warnings.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <string.h>
#include <sys/ipc.h>
/* Get a queue DS record */
int getQueueDs( int qid, struct msgqid_ds *qbuf ) {
if( msgctl( qid, IPC_STAT, qbuf) == -1) {
return(0);
}
return(1);
}
/* Change queue Permissions */
int changeQueuePerms( int qid, char *mode ) {
struct msqid_ds tmpbuf;
/* Retrieve a current copy of the internal data structure */
getQueueDs(qid, &tmpbuf);
/* Change the permissions using an old trick */
sscanf(mode, "%ho", &tmpbuf.msg_perm.mode);
/* Update the internal data structure */
if( msgctl( qid, IPC_SET, &tmpbuf) == -1) {
return(0);
}
return(1);
}
/* Change queue Size */
int changeQueueSize( int qid, ushort newSize ) {
struct msqid_ds tmpbuf;
/* Retrieve a current copy of the internal data structure */
getQueueDs(qid, &tmpbuf);
/* Change the size value */
tmpbuf.msg_qbytes = newSize;
/* Update the internal data structure */
if( msgctl( qid, IPC_SET, &tmpbuf) == -1) {
return(0);
}
return(1);
}
/* Get queue info */
int getQueueNumberOfMessages( int qid ) {
struct msqid_ds tmpbuf;
/* Retrieve a current copy of the internal data structure */
if ( getQueueDs( qid, &tmpbuf) ) {
return(tmpbuf.msg_qnum);
}
return(-1);
}
Compiler Warnings:-
includes/queues.h:47: warning: `struct msgqid_ds' declared inside parameter list
includes/queues.h:47: warning: its scope is only this definition or declaration, which is probably not what you want
includes/queues.h: In function `getQueueDs':
includes/queues.h:48: warning: passing arg 3 of `msgctl' from incompatible pointer type
includes/queues.h: In function `changeQueuePerms':
includes/queues.h:59: warning: passing arg 2 of `getQueueDs' from incompatible pointer type
includes/queues.h: In function `changeQueueSize':
includes/queues.h:77: warning: passing arg 2 of `getQueueDs' from incompatible pointer type
includes/queues.h: In function `getQueueNumberOfMessages':
includes/queues.h:95: warning: passing arg 2 of `getQueueDs' from incompatible pointer type
I don't understand the incompatible pointer type warning as the man page tells me that these are the correct types for the msgctl function:-
int msgctl(int msqid, int cmd, struct msqid_ds *buf);
The "struct declared inside parameter list" warning I just don't follow at all.
Any thoughts?
Many thanks.