Creating Posix message queue with attribute get error (invalidargument)

H

Hill

Why not Following code always get "Invalid argument" error? Who can
help me out?

$ ./a.out /tmp.333

Wrong!
: Invalid argument

#include <mqueue.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <iostream>
using namespace std;

#define FILE_MODE S_IRUSR|S_IWUSR

struct mq_attr attr;

int main(int argc, char** argv){
int c, flags;
mqd_t mqd;
flags = O_RDWR|O_CREAT;

if( argc != 2){

printf("usage: mqcreate <name>\n");
return -1;
}

attr.mq_maxmsg = 512;
attr.mq_msgsize = 512;

mqd = mq_open( argv[argc -1 ], flags, FILE_MODE, &attr);

if(mqd < 0){
perror("Wrong!\n");
return -1;
}

mq_close(mqd);
exit(0);



}
 
R

red floyd

Hill said:
Why not Following code always get "Invalid argument" error? Who can
help me out?

$ ./a.out /tmp.333

Wrong!
: Invalid argument

#include <mqueue.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <iostream>
using namespace std;

#define FILE_MODE S_IRUSR|S_IWUSR

struct mq_attr attr;

int main(int argc, char** argv){
int c, flags;
mqd_t mqd;
flags = O_RDWR|O_CREAT;

if( argc != 2){

printf("usage: mqcreate <name>\n");
return -1;
}

attr.mq_maxmsg = 512;
attr.mq_msgsize = 512;

mqd = mq_open( argv[argc -1 ], flags, FILE_MODE, &attr);

if(mqd < 0){
perror("Wrong!\n");
return -1;
}

mq_close(mqd);
exit(0);



}

Did you have a C++ language question? Unix syscalls are not part of
the C++ language. Please try comp.unix.programmer.

Replied to there, and followup set to there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top