#include #include #include #include #include #include #include #include #include #include #include #define __NR_mq_open 277 #define __NR_mq_unlink 278 #define __NR_mq_timedsend 279 #define __NR_mq_timedreceive 280 #define __NR_mq_notify 281 #define __NR_mq_getsetattr 282 typedef int mdq_t; struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __reserved[4]; }; static inline int __mq_open (const char *name, int oflag, mode_t mode, struct mq_attr *attr) { return syscall(__NR_mq_open, name, oflag, mode, attr); } static inline int __mq_timedsend(mdq_t mqdes, const char *msg_ptr, size_t msglen, unsigned int msgprio, const struct timespec *abs_timeout) { return syscall( __NR_mq_timedsend, mqdes, msg_ptr, msglen, msgprio, abs_timeout); } static int mq_send(mdq_t des, const char *msgptr, size_t msglen, unsigned int msgprio) { return __mq_timedsend(des, msgptr, msglen, msgprio, NULL); } mdq_t mq_open(const char *name, int oflag, ...) { unsigned long mode; struct mq_attr *attr; va_list ap; va_start(ap, oflag); mode = va_arg(ap, unsigned long); attr = va_arg(ap, struct mq_attr *); va_end(ap); return __mq_open(name, oflag, mode, attr); } #define PRIO 1 #define QUEUE "/mnt/example_queue" void main() { mdq_t ds; char text[] = "Our message body!"; ds = open(QUEUE, O_WRONLY|O_CREAT); if (ds == -1) { perror("Opening queue error\n"); exit(1); } if (mq_send(ds, text, strlen(text), PRIO) == -1) perror("Sendong message error"); else puts("Message sent to queue"); return 0; }