From ab11386aaaffc93755ff86199bf753a6d5ef4b45 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 7 Jun 2011 01:52:27 -0400 Subject: [PATCH] add support for POSIX message queues, except mq_notify --- include/mqueue.h | 34 ++++++++++++++++++++++++++++++++++ src/mq/mq_close.c | 7 +++++++ src/mq/mq_getattr.c | 7 +++++++ src/mq/mq_notify.c | 10 ++++++++++ src/mq/mq_open.c | 23 +++++++++++++++++++++++ src/mq/mq_receive.c | 6 ++++++ src/mq/mq_send.c | 6 ++++++ src/mq/mq_setattr.c | 7 +++++++ src/mq/mq_timedreceive.c | 7 +++++++ src/mq/mq_timedsend.c | 7 +++++++ src/mq/mq_unlink.c | 19 +++++++++++++++++++ 11 files changed, 133 insertions(+) create mode 100644 include/mqueue.h create mode 100644 src/mq/mq_close.c create mode 100644 src/mq/mq_getattr.c create mode 100644 src/mq/mq_notify.c create mode 100644 src/mq/mq_open.c create mode 100644 src/mq/mq_receive.c create mode 100644 src/mq/mq_send.c create mode 100644 src/mq/mq_setattr.c create mode 100644 src/mq/mq_timedreceive.c create mode 100644 src/mq/mq_timedsend.c create mode 100644 src/mq/mq_unlink.c diff --git a/include/mqueue.h b/include/mqueue.h new file mode 100644 index 00000000..ffbf4ae3 --- /dev/null +++ b/include/mqueue.h @@ -0,0 +1,34 @@ +#ifndef _SEMAPHORE_H +#define _SEMAPHORE_H +#ifdef __cplusplus +extern "C" { +#endif + +#define __NEED_size_t +#define __NEED_ssize_t +#define __NEED_pthread_attr_t +#define __NEED_time_t +#define __NEED_struct_timespec +#include + +typedef int mqd_t; +struct mq_attr { + long mq_flags, mq_maxmsg, mq_msgsize, mq_curmsgs, __unused[4]; +}; +struct sigevent; + +int mq_close(mqd_t); +int mq_getattr(mqd_t, struct mq_attr *); +int mq_notify(mqd_t, const struct sigevent *); +mqd_t mq_open(const char *, int, ...); +ssize_t mq_receive(mqd_t, char *, size_t, unsigned *); +int mq_send(mqd_t, const char *, size_t, unsigned); +int mq_setattr(mqd_t, const struct mq_attr *, struct mq_attr *); +ssize_t mq_timedreceive(mqd_t, char *, size_t, unsigned *, const struct timespec *); +int mq_timedsend(mqd_t, const char *, size_t, unsigned, const struct timespec *); +int mq_unlink(const char *); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/mq/mq_close.c b/src/mq/mq_close.c new file mode 100644 index 00000000..a61f094d --- /dev/null +++ b/src/mq/mq_close.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int mq_close(mqd_t mqd) +{ + return syscall(SYS_close, mqd); +} diff --git a/src/mq/mq_getattr.c b/src/mq/mq_getattr.c new file mode 100644 index 00000000..dce18069 --- /dev/null +++ b/src/mq/mq_getattr.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int mq_getattr(mqd_t mqd, struct mq_attr *attr) +{ + return mq_setattr(mqd, 0, attr); +} diff --git a/src/mq/mq_notify.c b/src/mq/mq_notify.c new file mode 100644 index 00000000..d85db1da --- /dev/null +++ b/src/mq/mq_notify.c @@ -0,0 +1,10 @@ +#include +#include +#include +#include "syscall.h" + +int mq_notify(mqd_t mqd, const struct sigevent *sev) +{ + errno = ENOSYS; + return -1; +} diff --git a/src/mq/mq_open.c b/src/mq/mq_open.c new file mode 100644 index 00000000..57220a2b --- /dev/null +++ b/src/mq/mq_open.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include "syscall.h" + +mqd_t mq_open(const char *name, int flags, ...) +{ + mode_t mode = 0; + struct mq_attr *attr = 0; + if (*name++ != '/') { + errno = EINVAL; + return -1; + } + if (flags & O_CREAT) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + attr = va_arg(ap, struct mq_attr *); + va_end(ap); + } + return syscall(SYS_mq_open, name, flags, mode, attr); +} diff --git a/src/mq/mq_receive.c b/src/mq/mq_receive.c new file mode 100644 index 00000000..0b1bb4e4 --- /dev/null +++ b/src/mq/mq_receive.c @@ -0,0 +1,6 @@ +#include + +ssize_t mq_receive(mqd_t mqd, char *msg, size_t len, unsigned *prio) +{ + return mq_timedreceive(mqd, msg, len, prio, 0); +} diff --git a/src/mq/mq_send.c b/src/mq/mq_send.c new file mode 100644 index 00000000..1acb1b78 --- /dev/null +++ b/src/mq/mq_send.c @@ -0,0 +1,6 @@ +#include + +int mq_send(mqd_t mqd, const char *msg, size_t len, unsigned prio) +{ + return mq_timedsend(mqd, msg, len, prio, 0); +} diff --git a/src/mq/mq_setattr.c b/src/mq/mq_setattr.c new file mode 100644 index 00000000..9064fa07 --- /dev/null +++ b/src/mq/mq_setattr.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int mq_setattr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old) +{ + return syscall(SYS_mq_getsetattr, mqd, new, old); +} diff --git a/src/mq/mq_timedreceive.c b/src/mq/mq_timedreceive.c new file mode 100644 index 00000000..ad705f8b --- /dev/null +++ b/src/mq/mq_timedreceive.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +ssize_t mq_timedreceive(mqd_t mqd, char *msg, size_t len, unsigned *prio, const struct timespec *at) +{ + return syscall(SYS_mq_timedreceive, mqd, msg, len, prio, at); +} diff --git a/src/mq/mq_timedsend.c b/src/mq/mq_timedsend.c new file mode 100644 index 00000000..edbaccf9 --- /dev/null +++ b/src/mq/mq_timedsend.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int mq_timedsend(mqd_t mqd, const char *msg, size_t len, unsigned prio, const struct timespec *at) +{ + return syscall(SYS_mq_timedsend, mqd, msg, len, prio, at); +} diff --git a/src/mq/mq_unlink.c b/src/mq/mq_unlink.c new file mode 100644 index 00000000..1bb92af1 --- /dev/null +++ b/src/mq/mq_unlink.c @@ -0,0 +1,19 @@ +#include +#include +#include "syscall.h" + +int mq_unlink(const char *name) +{ + int ret; + if (*name++ != '/') { + errno = EINVAL; + return -1; + } + ret = __syscall(SYS_mq_unlink, name); + if (ret < 0) { + if (ret == -EPERM) ret = -EACCES; + errno = -ret; + return -1; + } + return ret; +} -- GitLab