summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>2002-11-27 22:19:15 (GMT)
committerGreg Ward <gward@python.net>2002-11-27 22:19:15 (GMT)
commita34b1a074929c1ca1b8458bd26563b2385a1fe6b (patch)
treede2ade0fc9a412812fab5e498ce97ddaafedf758 /Modules
parentef786ae1a53d40107a6e7f9640a5029c1d663737 (diff)
downloadcpython-a34b1a074929c1ca1b8458bd26563b2385a1fe6b.zip
cpython-a34b1a074929c1ca1b8458bd26563b2385a1fe6b.tar.gz
cpython-a34b1a074929c1ca1b8458bd26563b2385a1fe6b.tar.bz2
Allow the device name to be passed to linuxaudiodev.open(), for
consistency with the built-in open() (and every other sane open() function, for that matter). The two valid ways to call this open() are now open(mode) and open(device, mode). For backwards compatibility, retain the old open(mode) calling syntax -- this makes the error message when you call open(device) a bit confusing, but oh well. This is the first half of SF patch #644977.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/linuxaudiodev.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/Modules/linuxaudiodev.c b/Modules/linuxaudiodev.c
index 74cfdee..5aac51a 100644
--- a/Modules/linuxaudiodev.c
+++ b/Modules/linuxaudiodev.c
@@ -79,11 +79,21 @@ newladobject(PyObject *arg)
{
lad_t *xp;
int fd, afmts, imode;
- char *mode;
- char *basedev;
+ char *basedev = NULL;
+ char *mode = NULL;
+
+ /* Two ways to call linuxaudiodev.open():
+ open(device, mode) (for consistency with builtin open())
+ open(mode) (for backwards compatibility)
+ because the *first* argument is optional, parsing args is
+ a wee bit tricky. */
+ if (!PyArg_ParseTuple(arg, "s|s:open", &basedev, &mode))
+ return NULL;
+ if (mode == NULL) { /* only one arg supplied */
+ mode = basedev;
+ basedev = NULL;
+ }
- /* Check arg for r/w/rw */
- if (!PyArg_ParseTuple(arg, "s:open", &mode)) return NULL;
if (strcmp(mode, "r") == 0)
imode = O_RDONLY;
else if (strcmp(mode, "w") == 0)
@@ -102,9 +112,11 @@ newladobject(PyObject *arg)
* latter uses 8-bit unsigned encoding.
*/
- basedev = getenv("AUDIODEV");
- if (!basedev)
- basedev = "/dev/dsp";
+ if (basedev == NULL) { /* called with one arg */
+ basedev = getenv("AUDIODEV");
+ if (basedev == NULL) /* $AUDIODEV not set */
+ basedev = "/dev/dsp";
+ }
if ((fd = open(basedev, imode)) == -1) {
PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);