add support for POSIX message queues, except mq_notify

This commit is contained in:
Rich Felker 2011-06-07 01:52:27 -04:00
parent cbf35978a9
commit ab11386aaa
11 changed files with 133 additions and 0 deletions

34
include/mqueue.h Normal file
View File

@ -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 <bits/alltypes.h>
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

7
src/mq/mq_close.c Normal file
View File

@ -0,0 +1,7 @@
#include <mqueue.h>
#include "syscall.h"
int mq_close(mqd_t mqd)
{
return syscall(SYS_close, mqd);
}

7
src/mq/mq_getattr.c Normal file
View File

@ -0,0 +1,7 @@
#include <mqueue.h>
#include "syscall.h"
int mq_getattr(mqd_t mqd, struct mq_attr *attr)
{
return mq_setattr(mqd, 0, attr);
}

10
src/mq/mq_notify.c Normal file
View File

@ -0,0 +1,10 @@
#include <mqueue.h>
#include <pthread.h>
#include <errno.h>
#include "syscall.h"
int mq_notify(mqd_t mqd, const struct sigevent *sev)
{
errno = ENOSYS;
return -1;
}

23
src/mq/mq_open.c Normal file
View File

@ -0,0 +1,23 @@
#include <mqueue.h>
#include <fcntl.h>
#include <errno.h>
#include <stdarg.h>
#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);
}

6
src/mq/mq_receive.c Normal file
View File

@ -0,0 +1,6 @@
#include <mqueue.h>
ssize_t mq_receive(mqd_t mqd, char *msg, size_t len, unsigned *prio)
{
return mq_timedreceive(mqd, msg, len, prio, 0);
}

6
src/mq/mq_send.c Normal file
View File

@ -0,0 +1,6 @@
#include <mqueue.h>
int mq_send(mqd_t mqd, const char *msg, size_t len, unsigned prio)
{
return mq_timedsend(mqd, msg, len, prio, 0);
}

7
src/mq/mq_setattr.c Normal file
View File

@ -0,0 +1,7 @@
#include <mqueue.h>
#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);
}

7
src/mq/mq_timedreceive.c Normal file
View File

@ -0,0 +1,7 @@
#include <mqueue.h>
#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);
}

7
src/mq/mq_timedsend.c Normal file
View File

@ -0,0 +1,7 @@
#include <mqueue.h>
#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);
}

19
src/mq/mq_unlink.c Normal file
View File

@ -0,0 +1,19 @@
#include <mqueue.h>
#include <errno.h>
#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;
}