1 // RUN: %clang -O1 %s -o %t && %run %t
2 // UNSUPPORTED: android
3 #include <assert.h>
4 #include <errno.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <sys/msg.h>
8 
9 #define CHECK_STRING "hello, world!"
10 #define MSG_BUFLEN 0x100
11 
12 int main() {
13   int msgq = msgget(IPC_PRIVATE, 0666);
14   assert(msgq != -1);
15 
16   struct msg_s {
17     long mtype;
18     char string[MSG_BUFLEN];
19   };
20 
21   struct msg_s msg = {
22       .mtype = 1};
23   strcpy(msg.string, CHECK_STRING);
24   int res = msgsnd(msgq, &msg, MSG_BUFLEN, IPC_NOWAIT);
25   if (res) {
26     fprintf(stderr, "Error sending message! %s\n", strerror(errno));
27     return -1;
28   }
29 
30   struct msg_s rcv_msg;
31   ssize_t len = msgrcv(msgq, &rcv_msg, MSG_BUFLEN, msg.mtype, IPC_NOWAIT);
32   assert(len == MSG_BUFLEN);
33   assert(msg.mtype == rcv_msg.mtype);
34   assert(!memcmp(msg.string, rcv_msg.string, MSG_BUFLEN));
35   return 0;
36 }
37