From 89712f1f02ee082325b665a37bd22aa0d2492234 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 5 Apr 2005 10:51:36 +0000 Subject: [PATCH] added 64-bit fopen support (sox works now) Signed-off-by: Mike Hearn --- alsa/alsa-oss.c | 59 +++++++++++++++++++++++++++++-------------------- alsa/pcm.c | 2 +- alsa/stdioemu.c | 31 ++++++++++++++++---------- 3 files changed, 55 insertions(+), 37 deletions(-) diff --git a/alsa/alsa-oss.c b/alsa/alsa-oss.c index 8aa74d3..ca620e7 100644 --- a/alsa/alsa-oss.c +++ b/alsa/alsa-oss.c @@ -62,6 +62,10 @@ #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"); diff --git a/alsa/pcm.c b/alsa/pcm.c index dc4695b..27ceaff 100644 --- a/alsa/pcm.c +++ b/alsa/pcm.c @@ -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; diff --git a/alsa/stdioemu.c b/alsa/stdioemu.c index 2b3bc1c..bf1bb5e 100644 --- a/alsa/stdioemu.c +++ b/alsa/stdioemu.c @@ -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 +*/ /* * 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 */ } -- 2.47.1