免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 12840 | 回复: 0
打印 上一主题 下一主题

mq_open的问题 [复制链接]

论坛徽章:
0
1 [报告]
发表于 2007-12-24 23:21 |显示全部楼层
根据标准:
http://www.opengroup.org/onlinep ... ctions/mq_open.html

  1. 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"的形式,

  1. #include <stdio.h>
  2. #include <string.h>

  3. #include <limits.h>
  4. #include <fcntl.h>
  5. #include <sys/stat.h>

  6. #include <mqueue.h>

  7. #define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)

  8. int main(void)
  9. {
  10.         mqd_t mqd;
  11.         int oflag;
  12.         char name[PATH_MAX + 1];

  13.         oflag = O_CREAT | O_RDWR;
  14.         strcpy(name, "/mq_mymtom");
  15.         mqd = mq_open(name, oflag, FILE_MODE, NULL);
  16.         if ((mqd_t)-1 == mqd)
  17.                 perror("mq_open()");
  18.         else
  19.                 printf("mq_open(): success.\n");

  20.         strcpy(name, "mq_mymtom");
  21.         mqd = mq_open(name, oflag, FILE_MODE, NULL);
  22.         if ((mqd_t)-1 == mqd)
  23.                 perror("mq_open()");
  24.         else
  25.                 printf("mq_open(): success.\n");

  26.         return 0;
  27. }
复制代码

评分

参与人数 1可用积分 +9 收起 理由
MMMIX + 9 精品文章

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP