{
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)
* 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);