]> git.alsa-project.org Git - alsa-oss.git/commitdiff
added 64-bit fopen support (sox works now)
authorMike Hearn <mike@navi.cx>
Tue, 5 Apr 2005 10:51:36 +0000 (10:51 +0000)
committerJaroslav Kysela <perex@perex.cz>
Tue, 5 Apr 2005 10:51:36 +0000 (10:51 +0000)
Signed-off-by: Mike Hearn <mike@navi.cx>
alsa/alsa-oss.c
alsa/pcm.c
alsa/stdioemu.c

index 8aa74d3ec450b983b7025ab318a3942a4e7fea7b..ca620e7a88cabe470c0e9a59e21348516f0d690a 100644 (file)
 #endif
 #endif
 
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0100000
+#endif
+
 int (*_select)(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
 int (*_poll)(struct pollfd *ufds, unsigned int nfds, int timeout);
 int (*_open)(const char *file, int oflag, ...);
@@ -689,32 +693,28 @@ int select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds,
 
 #include "stdioemu.c"
 
-FILE *fopen(const char* path, const char *mode) {
-
+FILE *fopen(const char* path, const char *mode)
+{
        if (!initialized)
                initialize();
 
        if(!is_dsp_device(path)) 
                return _fopen (path, mode);
        
-       return fake_fopen(path, mode);
+       return fake_fopen(path, mode, 0);
+}
+
+FILE *fopen64(const char* path, const char *mode)
+{
+       if (!initialized)   
+               initialize(); 
+
+       if(!is_dsp_device(path))
+               return _fopen (path, mode);
+
+       return fake_fopen(path, mode, O_LARGEFILE);
 }
 
-#if 1
-# define strong_alias(name, aliasname) \
-  extern __typeof (name) aliasname __attribute__ ((alias (#name)));
-strong_alias(open, __open);
-strong_alias(close, __close);
-strong_alias(write, __write);
-strong_alias(read, __read);
-strong_alias(ioctl, __ioctl);
-strong_alias(fcntl, __fcntl);
-strong_alias(mmap, __mmap);
-strong_alias(munmap, __munmap);
-strong_alias(poll, __poll);
-strong_alias(select, __select);
-strong_alias(fopen, __fopen);
-#else
 int dup(int fd)
 {
        return fcntl(fd, F_DUPFD, 0);
@@ -742,10 +742,6 @@ int dup2(int fd, int fd2)
        return fcntl(fd, F_DUPFD, fd2);
 }
 
-#ifndef O_LARGEFILE
-#define O_LARGEFILE 0100000
-#endif
-
 int open64(const char *file, int oflag, ...)
 {
        va_list args;
@@ -758,10 +754,25 @@ int open64(const char *file, int oflag, ...)
        }
        return open(file, oflag | O_LARGEFILE, mode);
 }
-#endif
 
-static void initialize() __attribute__ ((constructor));
+# define strong_alias(name, aliasname) \
+  extern __typeof (name) aliasname __attribute__ ((alias (#name)));
+
+strong_alias(open, __open);
+strong_alias(open64, __open64);
+strong_alias(close, __close);
+strong_alias(write, __write);
+strong_alias(read, __read);
+strong_alias(ioctl, __ioctl);
+strong_alias(fcntl, __fcntl);
+strong_alias(mmap, __mmap);
+strong_alias(munmap, __munmap);
+strong_alias(poll, __poll);
+strong_alias(select, __select);
+strong_alias(fopen, __fopen);
+strong_alias(fopen64, __fopen64);
 
+/* called by each override if needed */
 static void initialize()
 {
        char *s = getenv("ALSA_OSS_DEBUG");
index dc4695b267434be864cbf14f4ee6e8fdc9b57288..27ceaff39703f22a8cfe10938deedea867614008 100644 (file)
@@ -496,7 +496,7 @@ static int open_pcm(oss_dsp_t *dsp, const char *name, unsigned int pcm_mode,
        return result;
 }
 
-static int oss_dsp_open(int card, int device, int oflag, mode_t mode)
+static int oss_dsp_open(int card, int device, int oflag, mode_t mode ATTRIBUTE_UNUSED)
 {
        oss_dsp_t *dsp;
        unsigned int pcm_mode = 0;
index 2b3bc1c18cb188790116857c80f873d3a5faed39..bf1bb5edb13b9d450a59e5e06de8ec5a92e7868e 100644 (file)
@@ -1,4 +1,4 @@
-    /*
+/*
 
     Copyright (C) 2000 Stefan Westerfeld
                        stefan@space.twc.de
@@ -18,7 +18,8 @@
     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
 
-    */
+    Modified to add support for 64 bit fopen by Mike Hearn <mike@navi.cx>
+*/
 
 /*
  * This source only exists because some very special programs think that
@@ -67,28 +68,34 @@ static int fdc_clean (void *cookie)
        return result;
 }
 
-static FILE *fake_fopen(const char *path, const char *mode)
+static FILE *fake_fopen(const char *path, const char *mode, int flags)
 {
        cookie_io_functions_t fns = { fdc_read, fdc_write, fdc_seek, fdc_clean };
-       struct fd_cookie *fdc =
-               (struct fd_cookie *)malloc(sizeof(struct fd_cookie));
+       struct fd_cookie *fdc = (struct fd_cookie *)malloc(sizeof(struct fd_cookie));
        const char *mptr;
        int open_mode = 0;
        FILE *result = 0;
 
-       for(mptr = mode; *mptr; mptr++)
-       {
+       for(mptr = mode; *mptr; mptr++) {
                if(*mptr == 'r') open_mode |= 1; /* 1 = read */
                if(*mptr == 'w') open_mode |= 2; /* 2 = write */
                if(*mptr == '+') open_mode |= 3; /* 3 = readwrite */
                if(*mptr == 'a') open_mode |= 2; /* append -> write */
        }
-       if(open_mode == 1) fdc->fd = open(path,O_RDONLY,0666);
-       if(open_mode == 2) fdc->fd = open(path,O_WRONLY,0666);
-       if(open_mode == 3) fdc->fd = open(path,O_RDWR,0666);
 
-       if(open_mode && fdc->fd > 0)
-       {
+       switch (open_mode) {
+       case 1:
+               fdc->fd = open(path, O_RDONLY | flags, 0666);
+               break;
+       case 2:
+               fdc->fd = open(path, O_WRONLY | flags, 0666);
+               break;
+       default:
+               fdc->fd = open(path, O_RDWR | flags, 0666);
+               break;
+       }
+
+       if (open_mode && fdc->fd > 0) {
                result = fopencookie (fdc,"w", fns);
                result->_fileno = fdc->fd;              /* ugly patchy slimy kludgy hack */
        }