summaryrefslogtreecommitdiff
path: root/librt/mq_open.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2005-01-11 09:41:40 +0000
committerEric Andersen <andersen@codepoet.org>2005-01-11 09:41:40 +0000
commit50a6ac7fb90ad4008b354ff8e72c6ce511dbeb3a (patch)
treebbfa2262a83889c6aeed9e9017df8517536e3b4a /librt/mq_open.c
parent45a95a466117aee2cd60f97be8310b6a04197244 (diff)
Patch from Paul Mundt (lethal) adding an initial librt implementation.
I then reworked the syscall handling and made minor cleanups. With luck I've not completely broken his patch...
Diffstat (limited to 'librt/mq_open.c')
-rw-r--r--librt/mq_open.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/librt/mq_open.c b/librt/mq_open.c
new file mode 100644
index 000000000..3648b5aa7
--- /dev/null
+++ b/librt/mq_open.c
@@ -0,0 +1,52 @@
+/*
+ * mq_open.c - open a message queue.
+ */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <sys/syscall.h>
+
+#include <mqueue.h>
+
+#ifdef __NR_mq_open
+
+#define __NR___syscall_mq_open __NR_mq_open
+static inline _syscall4(int, __syscall_mq_open, const char *, name,
+ int, oflag, __kernel_mode_t, mode, void *, attr);
+/*
+ * Establish connection between a process and a message queue and
+ * return message queue descriptor or (mqd_t) -1 on error.
+ * oflag determines the type of access used. If O_CREAT is on oflag, the
+ * third argument is taken as a `mode_t', the mode of the created
+ * message queue, and the fourth argument is taken as `struct mq_attr *',
+ * pointer to message queue attributes.
+ * If the fourth argument is NULL, default attributes are used.
+ */
+mqd_t mq_open(const char *name, int oflag, ...)
+{
+ mode_t mode;
+ struct mq_attr *attr;
+
+ if (name[0] != '/') {
+ __set_errno(EINVAL);
+ return -1;
+ }
+
+ mode = 0;
+ attr = NULL;
+
+ if (oflag & O_CREAT) {
+ va_list ap;
+
+ va_start(ap, oflag);
+ mode = va_arg(ap, mode_t);
+ attr = va_arg(ap, struct mq_attr *);
+
+ va_end(ap);
+ }
+
+ return __syscall_mq_open(name + 1, oflag, mode, attr);
+}
+
+#endif