- 论坛徽章:
- 0
|
根据标准:
http://www.opengroup.org/onlinep ... ctions/mq_open.html
- If name begins with the slash character, then processes calling mq_open() with the same value of name shall refer to the same message queue object, as long as that name has not been removed. If name does not begin with the slash character, the effect is implementation-defined. The interpretation of slash characters other than the leading slash character in name is implementation-defined. If the name argument is not the name of an existing message queue and creation is not requested, mq_open() shall fail and return an error.
复制代码
所以可移植的方法是name使用类似"/your_mqueue"的形式,
- #include <stdio.h>
- #include <string.h>
- #include <limits.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <mqueue.h>
- #define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
- int main(void)
- {
- mqd_t mqd;
- int oflag;
- char name[PATH_MAX + 1];
- oflag = O_CREAT | O_RDWR;
- strcpy(name, "/mq_mymtom");
- mqd = mq_open(name, oflag, FILE_MODE, NULL);
- if ((mqd_t)-1 == mqd)
- perror("mq_open()");
- else
- printf("mq_open(): success.\n");
- strcpy(name, "mq_mymtom");
- mqd = mq_open(name, oflag, FILE_MODE, NULL);
- if ((mqd_t)-1 == mqd)
- perror("mq_open()");
- else
- printf("mq_open(): success.\n");
- return 0;
- }
复制代码 |
评分
-
查看全部评分
|