[Python-checkins] python/dist/src/Modules linuxaudiodev.c,2.19,2.20

gward@users.sourceforge.net gward@users.sourceforge.net
Wed, 27 Nov 2002 14:19:18 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv22157

Modified Files:
	linuxaudiodev.c 
Log Message:
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.


Index: linuxaudiodev.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/linuxaudiodev.c,v
retrieving revision 2.19
retrieving revision 2.20
diff -C2 -d -r2.19 -r2.20
*** linuxaudiodev.c	17 Jul 2002 16:30:36 -0000	2.19
--- linuxaudiodev.c	27 Nov 2002 22:19:15 -0000	2.20
***************
*** 80,88 ****
      lad_t *xp;
      int fd, afmts, imode;
!     char *mode;
!     char *basedev;
  
-     /* Check arg for r/w/rw */
-     if (!PyArg_ParseTuple(arg, "s:open", &mode)) return NULL;
      if (strcmp(mode, "r") == 0)
          imode = O_RDONLY;
--- 80,98 ----
      lad_t *xp;
      int fd, afmts, imode;
!     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;
!     }
  
      if (strcmp(mode, "r") == 0)
          imode = O_RDONLY;
***************
*** 103,109 ****
       */
  
!     basedev = getenv("AUDIODEV");
!     if (!basedev)
!         basedev = "/dev/dsp";
  
      if ((fd = open(basedev, imode)) == -1) {
--- 113,121 ----
       */
  
!     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) {