summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2011-04-12 21:40:22 +0000
committerratchov <ratchov@openbsd.org>2011-04-12 21:40:22 +0000
commitdd964a889cf8922473a69d35b78f2faa280d4c12 (patch)
treebc1c643dfbada373acbc6ba7ffb8c63d82d0a0ad
parentNo longer special-case NULL as a long for kernel and bootblocks. (diff)
downloadwireguard-openbsd-dd964a889cf8922473a69d35b78f2faa280d4c12.tar.xz
wireguard-openbsd-dd964a889cf8922473a69d35b78f2faa280d4c12.zip
Use mio_<backend>_ prefix for private midi-related functions and put
them in files named mio_<backend>.c No behaviour change.
-rw-r--r--lib/libsndio/Makefile4
-rw-r--r--lib/libsndio/mio.c14
-rw-r--r--lib/libsndio/mio_aucat.c (renamed from lib/libsndio/mio_thru.c)90
-rw-r--r--lib/libsndio/mio_priv.h8
-rw-r--r--lib/libsndio/mio_rmidi.c62
5 files changed, 87 insertions, 91 deletions
diff --git a/lib/libsndio/Makefile b/lib/libsndio/Makefile
index 667f6826313..83426f85226 100644
--- a/lib/libsndio/Makefile
+++ b/lib/libsndio/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.5 2011/04/08 11:18:07 ratchov Exp $
+# $OpenBSD: Makefile,v 1.6 2011/04/12 21:40:22 ratchov Exp $
LIB= sndio
MAN= sio_open.3 mio_open.3 sndio.7
-SRCS= sio_aucat.c sio_sun.c sio.c mio_rmidi.c mio_thru.c mio.c
+SRCS= sio_aucat.c sio_sun.c sio.c mio_rmidi.c mio_aucat.c mio.c
CFLAGS+=-Wall -Wstrict-prototypes -Werror -Wundef -DDEBUG \
-I${.CURDIR} -I${.CURDIR}/../../usr.bin/aucat
diff --git a/lib/libsndio/mio.c b/lib/libsndio/mio.c
index d94f32c7fbe..8c8d2c69edc 100644
--- a/lib/libsndio/mio.c
+++ b/lib/libsndio/mio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio.c,v 1.8 2010/04/24 06:15:54 ratchov Exp $ */
+/* $OpenBSD: mio.c,v 1.9 2011/04/12 21:40:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -61,10 +61,10 @@ mio_open(const char *str, unsigned mode, int nbio)
if (str == NULL && !issetugid())
str = getenv("MIDIDEVICE");
if (str == NULL) {
- hdl = mio_open_thru("0", mode, nbio);
+ hdl = mio_midithru_open("0", mode, nbio);
if (hdl != NULL)
return hdl;
- return mio_open_rmidi("0", mode, nbio);
+ return mio_rmidi_open("0", mode, nbio);
}
sep = strchr(str, ':');
if (sep == NULL) {
@@ -76,19 +76,19 @@ mio_open(const char *str, unsigned mode, int nbio)
return NULL;
}
snprintf(buf, sizeof(buf), "%u", minor(sb.st_rdev));
- return mio_open_rmidi(buf, mode, nbio);
+ return mio_rmidi_open(buf, mode, nbio);
}
len = sep - str;
if (len == (sizeof(prefix_midithru) - 1) &&
memcmp(str, prefix_midithru, len) == 0)
- return mio_open_thru(sep + 1, mode, nbio);
+ return mio_midithru_open(sep + 1, mode, nbio);
if (len == (sizeof(prefix_aucat) - 1) &&
memcmp(str, prefix_aucat, len) == 0)
- return mio_open_aucat(sep + 1, mode, nbio);
+ return mio_aucat_open(sep + 1, mode, nbio);
if (len == (sizeof(prefix_rmidi) - 1) &&
memcmp(str, prefix_rmidi, len) == 0)
- return mio_open_rmidi(sep + 1, mode, nbio);
+ return mio_rmidi_open(sep + 1, mode, nbio);
DPRINTF("mio_open: %s: unknown device type\n", str);
return NULL;
}
diff --git a/lib/libsndio/mio_thru.c b/lib/libsndio/mio_aucat.c
index 8ca5aa944b9..c2748b78ec3 100644
--- a/lib/libsndio/mio_thru.c
+++ b/lib/libsndio/mio_aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio_thru.c,v 1.12 2010/10/23 10:48:55 ratchov Exp $ */
+/* $OpenBSD: mio_aucat.c,v 1.1 2011/04/12 21:40:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -30,36 +30,34 @@
#include "amsg.h"
#include "mio_priv.h"
-#define THRU_SOCKET "midithru"
-
-struct thru_hdl {
+struct mio_aucat_hdl {
struct mio_hdl mio;
int fd;
};
-static void thru_close(struct mio_hdl *);
-static size_t thru_read(struct mio_hdl *, void *, size_t);
-static size_t thru_write(struct mio_hdl *, const void *, size_t);
-static int thru_pollfd(struct mio_hdl *, struct pollfd *, int);
-static int thru_revents(struct mio_hdl *, struct pollfd *);
-
-static struct mio_ops thru_ops = {
- thru_close,
- thru_write,
- thru_read,
- thru_pollfd,
- thru_revents,
+static void mio_aucat_close(struct mio_hdl *);
+static size_t mio_aucat_read(struct mio_hdl *, void *, size_t);
+static size_t mio_aucat_write(struct mio_hdl *, const void *, size_t);
+static int mio_aucat_pollfd(struct mio_hdl *, struct pollfd *, int);
+static int mio_aucat_revents(struct mio_hdl *, struct pollfd *);
+
+static struct mio_ops mio_aucat_ops = {
+ mio_aucat_close,
+ mio_aucat_write,
+ mio_aucat_read,
+ mio_aucat_pollfd,
+ mio_aucat_revents,
};
static struct mio_hdl *
-thru_open(const char *str, char *sock, unsigned mode, int nbio)
+mio_xxx_open(const char *str, char *sock, unsigned mode, int nbio)
{
extern char *__progname;
char unit[4], *sep, *opt;
struct amsg msg;
int s, n, todo;
unsigned char *data;
- struct thru_hdl *hdl;
+ struct mio_aucat_hdl *hdl;
struct sockaddr_un ca;
socklen_t len = sizeof(struct sockaddr_un);
uid_t uid;
@@ -71,12 +69,12 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
} else {
opt = sep + 1;
if (sep - str >= sizeof(unit)) {
- DPRINTF("thru_open: %s: too long\n", str);
+ DPRINTF("mio_aucat_open: %s: too long\n", str);
return NULL;
}
strlcpy(unit, str, opt - str);
}
- DPRINTF("thru_open: trying %s -> %s.%s\n", str, unit, opt);
+ DPRINTF("mio_aucat_open: trying %s -> %s.%s\n", str, unit, opt);
uid = geteuid();
if (strchr(str, '/') != NULL)
return NULL;
@@ -84,10 +82,10 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
"/tmp/aucat-%u/%s%s", uid, sock, unit);
ca.sun_family = AF_UNIX;
- hdl = malloc(sizeof(struct thru_hdl));
+ hdl = malloc(sizeof(struct mio_aucat_hdl));
if (hdl == NULL)
return NULL;
- mio_create(&hdl->mio, &thru_ops, mode, nbio);
+ mio_create(&hdl->mio, &mio_aucat_ops, mode, nbio);
s = socket(AF_UNIX, SOCK_STREAM, 0);
if (s < 0)
@@ -95,14 +93,14 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR)
continue;
- DPERROR("thru_open: connect");
+ DPERROR("mio_aucat_open: connect");
/* try shared server */
snprintf(ca.sun_path, sizeof(ca.sun_path),
"/tmp/aucat/%s%s", sock, unit);
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR)
continue;
- DPERROR("thru_open: connect");
+ DPERROR("mio_aucat_open: connect");
goto bad_connect;
}
break;
@@ -124,11 +122,11 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
strlcpy(msg.u.hello.who, __progname, sizeof(msg.u.hello.who));
n = write(s, &msg, sizeof(struct amsg));
if (n < 0) {
- DPERROR("thru_open");
+ DPERROR("mio_aucat_open");
goto bad_connect;
}
if (n != sizeof(struct amsg)) {
- DPRINTF("thru_open: short write\n");
+ DPRINTF("mio_aucat_open: short write\n");
goto bad_connect;
}
todo = sizeof(struct amsg);
@@ -136,22 +134,22 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
while (todo > 0) {
n = read(s, data, todo);
if (n < 0) {
- DPERROR("thru_open");
+ DPERROR("mio_aucat_open");
goto bad_connect;
}
if (n == 0) {
- DPRINTF("thru_open: eof\n");
+ DPRINTF("mio_aucat_open: eof\n");
goto bad_connect;
}
todo -= n;
data += n;
}
if (msg.cmd != AMSG_ACK) {
- DPRINTF("thru_open: proto error\n");
+ DPRINTF("mio_aucat_open: proto error\n");
goto bad_connect;
}
if (nbio && fcntl(hdl->fd, F_SETFL, O_NONBLOCK) < 0) {
- DPERROR("thru_open: fcntl(NONBLOCK)");
+ DPERROR("mio_aucat_open: fcntl(NONBLOCK)");
goto bad_connect;
}
return (struct mio_hdl *)hdl;
@@ -164,21 +162,21 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
}
struct mio_hdl *
-mio_open_thru(const char *str, unsigned mode, int nbio)
+mio_midithru_open(const char *str, unsigned mode, int nbio)
{
- return thru_open(str, "midithru", mode, nbio);
+ return mio_xxx_open(str, "midithru", mode, nbio);
}
struct mio_hdl *
-mio_open_aucat(const char *str, unsigned mode, int nbio)
+mio_aucat_open(const char *str, unsigned mode, int nbio)
{
- return thru_open(str, "softaudio", mode, nbio);
+ return mio_xxx_open(str, "softaudio", mode, nbio);
}
static void
-thru_close(struct mio_hdl *sh)
+mio_aucat_close(struct mio_hdl *sh)
{
- struct thru_hdl *hdl = (struct thru_hdl *)sh;
+ struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
int rc;
do {
@@ -188,22 +186,22 @@ thru_close(struct mio_hdl *sh)
}
static size_t
-thru_read(struct mio_hdl *sh, void *buf, size_t len)
+mio_aucat_read(struct mio_hdl *sh, void *buf, size_t len)
{
- struct thru_hdl *hdl = (struct thru_hdl *)sh;
+ struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
ssize_t n;
while ((n = read(hdl->fd, buf, len)) < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
- DPERROR("thru_read: read");
+ DPERROR("mio_aucat_read: read");
hdl->mio.eof = 1;
}
return 0;
}
if (n == 0) {
- DPRINTF("thru_read: eof\n");
+ DPRINTF("mio_aucat_read: eof\n");
hdl->mio.eof = 1;
return 0;
}
@@ -211,16 +209,16 @@ thru_read(struct mio_hdl *sh, void *buf, size_t len)
}
static size_t
-thru_write(struct mio_hdl *sh, const void *buf, size_t len)
+mio_aucat_write(struct mio_hdl *sh, const void *buf, size_t len)
{
- struct thru_hdl *hdl = (struct thru_hdl *)sh;
+ struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
ssize_t n;
while ((n = write(hdl->fd, buf, len)) < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
- DPERROR("thru_write: write");
+ DPERROR("mio_aucat_write: write");
hdl->mio.eof = 1;
}
return 0;
@@ -229,9 +227,9 @@ thru_write(struct mio_hdl *sh, const void *buf, size_t len)
}
static int
-thru_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
+mio_aucat_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
{
- struct thru_hdl *hdl = (struct thru_hdl *)sh;
+ struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
pfd->fd = hdl->fd;
pfd->events = events;
@@ -239,7 +237,7 @@ thru_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
}
static int
-thru_revents(struct mio_hdl *sh, struct pollfd *pfd)
+mio_aucat_revents(struct mio_hdl *sh, struct pollfd *pfd)
{
return pfd->revents;
}
diff --git a/lib/libsndio/mio_priv.h b/lib/libsndio/mio_priv.h
index f5022dc6839..07d86684ab4 100644
--- a/lib/libsndio/mio_priv.h
+++ b/lib/libsndio/mio_priv.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio_priv.h,v 1.4 2009/08/21 16:48:03 ratchov Exp $ */
+/* $OpenBSD: mio_priv.h,v 1.5 2011/04/12 21:40:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -57,9 +57,9 @@ struct mio_ops {
int (*revents)(struct mio_hdl *, struct pollfd *);
};
-struct mio_hdl *mio_open_rmidi(const char *, unsigned, int);
-struct mio_hdl *mio_open_thru(const char *, unsigned, int);
-struct mio_hdl *mio_open_aucat(const char *, unsigned, int);
+struct mio_hdl *mio_rmidi_open(const char *, unsigned, int);
+struct mio_hdl *mio_midithru_open(const char *, unsigned, int);
+struct mio_hdl *mio_aucat_open(const char *, unsigned, int);
void mio_create(struct mio_hdl *, struct mio_ops *, unsigned, int);
void mio_destroy(struct mio_hdl *);
diff --git a/lib/libsndio/mio_rmidi.c b/lib/libsndio/mio_rmidi.c
index 194863ca070..d311fe4452c 100644
--- a/lib/libsndio/mio_rmidi.c
+++ b/lib/libsndio/mio_rmidi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio_rmidi.c,v 1.7 2010/07/21 23:00:16 ratchov Exp $ */
+/* $OpenBSD: mio_rmidi.c,v 1.8 2011/04/12 21:40:22 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -29,38 +29,36 @@
#include "mio_priv.h"
-#define RMIDI_PATH "/dev/rmidi0"
-
-struct rmidi_hdl {
+struct mio_rmidi_hdl {
struct mio_hdl mio;
int fd;
};
-static void rmidi_close(struct mio_hdl *);
-static size_t rmidi_read(struct mio_hdl *, void *, size_t);
-static size_t rmidi_write(struct mio_hdl *, const void *, size_t);
-static int rmidi_pollfd(struct mio_hdl *, struct pollfd *, int);
-static int rmidi_revents(struct mio_hdl *, struct pollfd *);
-
-static struct mio_ops rmidi_ops = {
- rmidi_close,
- rmidi_write,
- rmidi_read,
- rmidi_pollfd,
- rmidi_revents,
+static void mio_rmidi_close(struct mio_hdl *);
+static size_t mio_rmidi_read(struct mio_hdl *, void *, size_t);
+static size_t mio_rmidi_write(struct mio_hdl *, const void *, size_t);
+static int mio_rmidi_pollfd(struct mio_hdl *, struct pollfd *, int);
+static int mio_rmidi_revents(struct mio_hdl *, struct pollfd *);
+
+static struct mio_ops mio_rmidi_ops = {
+ mio_rmidi_close,
+ mio_rmidi_write,
+ mio_rmidi_read,
+ mio_rmidi_pollfd,
+ mio_rmidi_revents,
};
struct mio_hdl *
-mio_open_rmidi(const char *str, unsigned mode, int nbio)
+mio_rmidi_open(const char *str, unsigned mode, int nbio)
{
int fd, flags;
- struct rmidi_hdl *hdl;
+ struct mio_rmidi_hdl *hdl;
char path[PATH_MAX];
- hdl = malloc(sizeof(struct rmidi_hdl));
+ hdl = malloc(sizeof(struct mio_rmidi_hdl));
if (hdl == NULL)
return NULL;
- mio_create(&hdl->mio, &rmidi_ops, mode, nbio);
+ mio_create(&hdl->mio, &mio_rmidi_ops, mode, nbio);
snprintf(path, sizeof(path), "/dev/rmidi%s", str);
if (mode == (MIO_OUT | MIO_IN))
@@ -90,9 +88,9 @@ mio_open_rmidi(const char *str, unsigned mode, int nbio)
}
static void
-rmidi_close(struct mio_hdl *sh)
+mio_rmidi_close(struct mio_hdl *sh)
{
- struct rmidi_hdl *hdl = (struct rmidi_hdl *)sh;
+ struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
int rc;
do {
@@ -102,22 +100,22 @@ rmidi_close(struct mio_hdl *sh)
}
static size_t
-rmidi_read(struct mio_hdl *sh, void *buf, size_t len)
+mio_rmidi_read(struct mio_hdl *sh, void *buf, size_t len)
{
- struct rmidi_hdl *hdl = (struct rmidi_hdl *)sh;
+ struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
ssize_t n;
while ((n = read(hdl->fd, buf, len)) < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
- DPERROR("rmidi_read: read");
+ DPERROR("mio_rmidi_read: read");
hdl->mio.eof = 1;
}
return 0;
}
if (n == 0) {
- DPRINTF("rmidi_read: eof\n");
+ DPRINTF("mio_rmidi_read: eof\n");
hdl->mio.eof = 1;
return 0;
}
@@ -125,16 +123,16 @@ rmidi_read(struct mio_hdl *sh, void *buf, size_t len)
}
static size_t
-rmidi_write(struct mio_hdl *sh, const void *buf, size_t len)
+mio_rmidi_write(struct mio_hdl *sh, const void *buf, size_t len)
{
- struct rmidi_hdl *hdl = (struct rmidi_hdl *)sh;
+ struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
ssize_t n;
while ((n = write(hdl->fd, buf, len)) < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
- DPERROR("rmidi_write: write");
+ DPERROR("mio_rmidi_write: write");
hdl->mio.eof = 1;
}
return 0;
@@ -143,9 +141,9 @@ rmidi_write(struct mio_hdl *sh, const void *buf, size_t len)
}
static int
-rmidi_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
+mio_rmidi_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
{
- struct rmidi_hdl *hdl = (struct rmidi_hdl *)sh;
+ struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
pfd->fd = hdl->fd;
pfd->events = events;
@@ -153,7 +151,7 @@ rmidi_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
}
static int
-rmidi_revents(struct mio_hdl *sh, struct pollfd *pfd)
+mio_rmidi_revents(struct mio_hdl *sh, struct pollfd *pfd)
{
return pfd->revents;
}