diff options
Diffstat (limited to 'librt/mq_open.c')
-rw-r--r-- | librt/mq_open.c | 52 |
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 |