summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2015-11-22 12:01:24 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2015-11-22 12:01:24 +0000
commit7f65a787ac4a5023bff23f325cfba5890541bc8d (patch)
tree0fd623cf200087c73afe4be30893c1f7f66dc46e
parentf03acee44c3badd17aefb5d177430c9dd06fba63 (diff)
Don't remove the type component from the device string before passing
it to the *_open() functions. It's more flexible this way. No behaviour change.
-rw-r--r--lib/libsndio/aucat.c23
-rw-r--r--lib/libsndio/aucat.h2
-rw-r--r--lib/libsndio/mio.c23
-rw-r--r--lib/libsndio/mio_aucat.c7
-rw-r--r--lib/libsndio/mio_priv.h4
-rw-r--r--lib/libsndio/mio_rmidi.c71
-rw-r--r--lib/libsndio/sio.c18
-rw-r--r--lib/libsndio/sio_aucat.c4
-rw-r--r--lib/libsndio/sio_sun.c20
9 files changed, 102 insertions, 70 deletions
diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c
index 14b72e8afa8..074ab211635 100644
--- a/lib/libsndio/aucat.c
+++ b/lib/libsndio/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.68 2015/10/05 07:18:03 ratchov Exp $ */
+/* $OpenBSD: aucat.c,v 1.69 2015/11/22 12:01:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -421,15 +421,24 @@ parsestr(const char *str, char *rstr, unsigned int max)
}
int
-_aucat_open(struct aucat *hdl, const char *str, unsigned int mode,
- unsigned int type)
+_aucat_open(struct aucat *hdl, const char *str, unsigned int mode)
{
extern char *__progname;
int eof;
char host[NI_MAXHOST], opt[AMSG_OPTMAX];
- const char *p = str;
- unsigned int unit, devnum;
-
+ const char *p;
+ unsigned int unit, devnum, type;
+
+ if ((p = _sndio_parsetype(str, "snd")) != NULL)
+ type = 0;
+ else if ((p = _sndio_parsetype(str, "midithru")) != NULL)
+ type = 1;
+ else if ((p = _sndio_parsetype(str, "midi")) != NULL)
+ type = 2;
+ else {
+ DPRINTF("%s: unsupported device type\n", str);
+ return -1;
+ }
if (*p == '@') {
p = parsestr(++p, host, NI_MAXHOST);
if (p == NULL)
@@ -442,7 +451,7 @@ _aucat_open(struct aucat *hdl, const char *str, unsigned int mode,
return 0;
} else
unit = 0;
- if (*p != '/' && *p != ':') {
+ if (*p != '/') {
DPRINTF("%s: '/' expected\n", str);
return 0;
}
diff --git a/lib/libsndio/aucat.h b/lib/libsndio/aucat.h
index 8c3966cadde..e9d8e6954b7 100644
--- a/lib/libsndio/aucat.h
+++ b/lib/libsndio/aucat.h
@@ -21,7 +21,7 @@ int _aucat_rmsg(struct aucat *, int *);
int _aucat_wmsg(struct aucat *, int *);
size_t _aucat_rdata(struct aucat *, void *, size_t, int *);
size_t _aucat_wdata(struct aucat *, const void *, size_t, unsigned, int *);
-int _aucat_open(struct aucat *, const char *, unsigned, unsigned);
+int _aucat_open(struct aucat *, const char *, unsigned);
void _aucat_close(struct aucat *, int);
int _aucat_pollfd(struct aucat *, struct pollfd *, int);
int _aucat_revents(struct aucat *, struct pollfd *);
diff --git a/lib/libsndio/mio.c b/lib/libsndio/mio.c
index ffdd5714290..9f41661e4dc 100644
--- a/lib/libsndio/mio.c
+++ b/lib/libsndio/mio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio.c,v 1.19 2015/01/16 16:48:52 deraadt Exp $ */
+/* $OpenBSD: mio.c,v 1.20 2015/11/22 12:01:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -35,7 +35,6 @@ mio_open(const char *str, unsigned int mode, int nbio)
{
static char portany[] = MIO_PORTANY;
struct mio_hdl *hdl;
- const char *p;
#ifdef DEBUG
_sndio_debug_init();
@@ -50,21 +49,17 @@ mio_open(const char *str, unsigned int mode, int nbio)
str = portany;
}
if (strcmp(str, portany) == 0) {
- hdl = _mio_aucat_open("/0", mode, nbio, 1);
+ hdl = _mio_aucat_open("midithru/0", mode, nbio);
if (hdl != NULL)
return hdl;
- return _mio_rmidi_open("/0", mode, nbio);
- }
- if ((p = _sndio_parsetype(str, "snd")) != NULL ||
- (p = _sndio_parsetype(str, "aucat")) != NULL)
- return _mio_aucat_open(p, mode, nbio, 0);
- if ((p = _sndio_parsetype(str, "midithru")) != NULL)
- return _mio_aucat_open(p, mode, nbio, 1);
- if ((p = _sndio_parsetype(str, "midi")) != NULL)
- return _mio_aucat_open(p, mode, nbio, 2);
- if ((p = _sndio_parsetype(str, "rmidi")) != NULL) {
- return _mio_rmidi_open(p, mode, nbio);
+ return _mio_rmidi_open("rmidi/0", mode, nbio);
}
+ if (_sndio_parsetype(str, "snd") ||
+ _sndio_parsetype(str, "midithru") ||
+ _sndio_parsetype(str, "midi"))
+ return _mio_aucat_open(str, mode, nbio);
+ if (_sndio_parsetype(str, "rmidi"))
+ return _mio_rmidi_open(str, mode, nbio);
DPRINTF("mio_open: %s: unknown device type\n", str);
return NULL;
}
diff --git a/lib/libsndio/mio_aucat.c b/lib/libsndio/mio_aucat.c
index 59a20b31535..9cef7b6fa61 100644
--- a/lib/libsndio/mio_aucat.c
+++ b/lib/libsndio/mio_aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio_aucat.c,v 1.10 2013/11/13 22:38:22 ratchov Exp $ */
+/* $OpenBSD: mio_aucat.c,v 1.11 2015/11/22 12:01:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -84,15 +84,14 @@ mio_aucat_runmsg(struct mio_aucat_hdl *hdl)
}
struct mio_hdl *
-_mio_aucat_open(const char *str, unsigned int mode,
- int nbio, unsigned int type)
+_mio_aucat_open(const char *str, unsigned int mode, int nbio)
{
struct mio_aucat_hdl *hdl;
hdl = malloc(sizeof(struct mio_aucat_hdl));
if (hdl == NULL)
return NULL;
- if (!_aucat_open(&hdl->aucat, str, mode, type))
+ if (!_aucat_open(&hdl->aucat, str, mode))
goto bad;
_mio_create(&hdl->mio, &mio_aucat_ops, mode, nbio);
if (!_aucat_setfl(&hdl->aucat, 1, &hdl->mio.eof))
diff --git a/lib/libsndio/mio_priv.h b/lib/libsndio/mio_priv.h
index 7b3c39fecc1..7373a50b764 100644
--- a/lib/libsndio/mio_priv.h
+++ b/lib/libsndio/mio_priv.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio_priv.h,v 1.11 2015/01/16 16:48:52 deraadt Exp $ */
+/* $OpenBSD: mio_priv.h,v 1.12 2015/11/22 12:01:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -44,7 +44,7 @@ struct mio_ops {
};
struct mio_hdl *_mio_rmidi_open(const char *, unsigned, int);
-struct mio_hdl *_mio_aucat_open(const char *, unsigned, int, unsigned);
+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 53f92d9e551..43fef7c4af7 100644
--- a/lib/libsndio/mio_rmidi.c
+++ b/lib/libsndio/mio_rmidi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio_rmidi.c,v 1.19 2015/10/02 09:48:22 ratchov Exp $ */
+/* $OpenBSD: mio_rmidi.c,v 1.20 2015/11/22 12:01:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -56,46 +56,73 @@ static struct mio_ops mio_rmidi_ops = {
mio_rmidi_revents
};
-struct mio_hdl *
-_mio_rmidi_open(const char *str, unsigned int mode, int nbio)
+static int
+mio_rmidi_getfd(const char *str, unsigned int mode, int nbio)
{
- int fd, flags;
- struct mio_rmidi_hdl *hdl;
+ const char *p;
char path[DEVPATH_MAX];
unsigned int devnum;
+ int fd, flags;
- switch (*str) {
+ p = _sndio_parsetype(str, "rmidi");
+ if (p == NULL) {
+ DPRINTF("mio_rmidi_getfd: %s: \"rsnd\" expected\n", str);
+ return -1;
+ }
+ switch (*p) {
case '/':
- str++;
+ p++;
break;
default:
- DPRINTF("_mio_rmidi_open: %s: '/<devnum>' expected\n", str);
- return NULL;
+ DPRINTF("mio_rmidi_getfd: %s: '/' expected\n", str);
+ return -1;
}
- str = _sndio_parsenum(str, &devnum, 255);
- if (str == NULL || *str != '\0') {
- DPRINTF("_mio_rmidi_open: can't determine device number\n");
- return NULL;
+ p = _sndio_parsenum(p, &devnum, 255);
+ if (p == NULL || *p != '\0') {
+ DPRINTF("mio_rmidi_getfd: %s: number expected after '/'\n", str);
+ return -1;
}
- hdl = malloc(sizeof(struct mio_rmidi_hdl));
- if (hdl == NULL)
- return NULL;
- _mio_create(&hdl->mio, &mio_rmidi_ops, mode, nbio);
snprintf(path, sizeof(path), DEVPATH_PREFIX "%u", devnum);
- if (mode == (MIO_OUT | MIO_IN))
+ if (mode == (SIO_PLAY | SIO_REC))
flags = O_RDWR;
else
- flags = (mode & MIO_OUT) ? O_WRONLY : O_RDONLY;
+ flags = (mode & SIO_PLAY) ? O_WRONLY : O_RDONLY;
while ((fd = open(path, flags | O_NONBLOCK | O_CLOEXEC)) < 0) {
if (errno == EINTR)
continue;
DPERROR(path);
- goto bad_free;
+ return -1;
}
+ return fd;
+}
+
+static struct mio_hdl *
+mio_rmidi_fdopen(int fd, unsigned int mode, int nbio)
+{
+ struct mio_rmidi_hdl *hdl;
+
+ hdl = malloc(sizeof(struct mio_rmidi_hdl));
+ if (hdl == NULL)
+ return NULL;
+ _mio_create(&hdl->mio, &mio_rmidi_ops, mode, nbio);
hdl->fd = fd;
return (struct mio_hdl *)hdl;
- bad_free:
- free(hdl);
+}
+
+struct mio_hdl *
+_mio_rmidi_open(const char *str, unsigned int mode, int nbio)
+{
+ struct mio_hdl *hdl;
+ int fd;
+
+ fd = mio_rmidi_getfd(str, mode, nbio);
+ if (fd < 0)
+ return NULL;
+ hdl = mio_rmidi_fdopen(fd, mode, nbio);
+ if (hdl != NULL)
+ return hdl;
+ while (close(fd) < 0 && errno == EINTR)
+ ; /* retry */
return NULL;
}
diff --git a/lib/libsndio/sio.c b/lib/libsndio/sio.c
index 576da94ee3e..1e4f965c862 100644
--- a/lib/libsndio/sio.c
+++ b/lib/libsndio/sio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sio.c,v 1.19 2015/01/16 16:48:52 deraadt Exp $ */
+/* $OpenBSD: sio.c,v 1.20 2015/11/22 12:01:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -44,7 +44,6 @@ sio_open(const char *str, unsigned int mode, int nbio)
{
static char devany[] = SIO_DEVANY;
struct sio_hdl *hdl;
- const char *p;
#ifdef DEBUG
_sndio_debug_init();
@@ -59,18 +58,15 @@ sio_open(const char *str, unsigned int mode, int nbio)
str = devany;
}
if (strcmp(str, devany) == 0) {
- hdl = _sio_aucat_open("/0", mode, nbio);
+ hdl = _sio_aucat_open("snd/0", mode, nbio);
if (hdl != NULL)
return hdl;
- return _sio_sun_open("/0", mode, nbio);
- }
- if ((p = _sndio_parsetype(str, "snd")) != NULL ||
- (p = _sndio_parsetype(str, "aucat")) != NULL)
- return _sio_aucat_open(p, mode, nbio);
- if ((p = _sndio_parsetype(str, "rsnd")) != NULL ||
- (p = _sndio_parsetype(str, "sun")) != NULL) {
- return _sio_sun_open(p, mode, nbio);
+ return _sio_sun_open("rsnd/0", mode, nbio);
}
+ if (_sndio_parsetype(str, "snd"))
+ return _sio_aucat_open(str, mode, nbio);
+ if (_sndio_parsetype(str, "rsnd"))
+ return _sio_sun_open(str, mode, nbio);
DPRINTF("sio_open: %s: unknown device type\n", str);
return NULL;
}
diff --git a/lib/libsndio/sio_aucat.c b/lib/libsndio/sio_aucat.c
index 6364368e558..d05c042c555 100644
--- a/lib/libsndio/sio_aucat.c
+++ b/lib/libsndio/sio_aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sio_aucat.c,v 1.18 2014/03/07 10:17:18 ratchov Exp $ */
+/* $OpenBSD: sio_aucat.c,v 1.19 2015/11/22 12:01:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -155,7 +155,7 @@ _sio_aucat_open(const char *str, unsigned int mode, int nbio)
hdl = malloc(sizeof(struct sio_aucat_hdl));
if (hdl == NULL)
return NULL;
- if (!_aucat_open(&hdl->aucat, str, mode, 0)) {
+ if (!_aucat_open(&hdl->aucat, str, mode)) {
free(hdl);
return NULL;
}
diff --git a/lib/libsndio/sio_sun.c b/lib/libsndio/sio_sun.c
index 8487db07019..791251001b3 100644
--- a/lib/libsndio/sio_sun.c
+++ b/lib/libsndio/sio_sun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sio_sun.c,v 1.21 2015/11/18 09:35:59 ratchov Exp $ */
+/* $OpenBSD: sio_sun.c,v 1.22 2015/11/22 12:01:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -333,21 +333,27 @@ sio_sun_getcap(struct sio_hdl *sh, struct sio_cap *cap)
static int
sio_sun_getfd(const char *str, unsigned int mode, int nbio)
{
+ const char *p;
char path[DEVPATH_MAX];
unsigned int devnum;
int fd, flags;
- switch (*str) {
+ p = _sndio_parsetype(str, "rsnd");
+ if (p == NULL) {
+ DPRINTF("sio_sun_getfd: %s: \"rsnd\" expected\n", str);
+ return -1;
+ }
+ switch (*p) {
case '/':
- str++;
+ p++;
break;
default:
- DPRINTF("sio_sun_getfd: %s: '/<devnum>' expected\n", str);
+ DPRINTF("sio_sun_getfd: %s: '/' expected\n", str);
return -1;
}
- str = _sndio_parsenum(str, &devnum, 255);
- if (str == NULL || *str != '\0') {
- DPRINTF("sio_sun_getfd: can't determine device number\n");
+ p = _sndio_parsenum(p, &devnum, 255);
+ if (p == NULL || *p != '\0') {
+ DPRINTF("sio_sun_getfd: %s: number expected after '/'\n", str);
return -1;
}
snprintf(path, sizeof(path), DEVPATH_PREFIX "%u", devnum);