mpg123-1.32.9

This commit is contained in:
Ozkan Sezer
2024-11-02 20:47:20 +03:00
parent 9102165ff5
commit fc1ca4a8f9
9 changed files with 107 additions and 30 deletions

View File

@@ -88,7 +88,7 @@ int INT123_compat_open(const char *filename, int flags)
open_fallback:
#endif
#if (defined(WIN32) && !defined (__CYGWIN__))
#if defined(MPG123_COMPAT_MSVCRT_IO)
/* MSDN says POSIX function is deprecated beginning in Visual C++ 2005 */
/* Try plain old _open(), if it fails, do nothing */
ret = _open(filename, flags|_O_BINARY, _S_IREAD | _S_IWRITE);
@@ -138,12 +138,16 @@ fopen_ok:
FILE* INT123_compat_fdopen(int fd, const char *mode)
{
#if defined(MPG123_COMPAT_MSVCRT_IO)
return _fdopen(fd, mode);
#else
return fdopen(fd, mode);
#endif
}
int INT123_compat_close(int infd)
{
#if (defined(WIN32) && !defined (__CYGWIN__)) /* MSDN says POSIX function is deprecated beginning in Visual C++ 2005 */
#if defined(MPG123_COMPAT_MSVCRT_IO)
return _close(infd);
#else
return close(infd);

View File

@@ -110,7 +110,42 @@
typedef unsigned char byte;
#if (defined(_UCRT) || defined(_MSC_VER) || (defined(__MINGW32__) || defined(__MINGW64__)) || (defined(__WATCOMC__) && defined(__NT__))) && !defined(__CYGWIN__)
#define MPG123_COMPAT_MSVCRT_IO
#endif
#if defined(MPG123_COMPAT_MSVCRT_IO)
#if defined(_UCRT)
// needs to get checked separately from MSVC and MinGW becuase it is also used by native Clang on Windows
#ifndef MPG123_COMPAT_MSVCRT_IO_64
#define MPG123_COMPAT_MSVCRT_IO_64
#endif
#endif
#if defined(_MSC_VER)
#if (_MSC_VER >= 1200)
// >= VC6
#ifndef MPG123_COMPAT_MSVCRT_IO_64
#define MPG123_COMPAT_MSVCRT_IO_64
#endif
#endif
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#if (defined(__MSVCRT__) || defined(_UCRT)) && !defined(__CRTDLL__)
#ifndef MPG123_COMPAT_MSVCRT_IO_64
#define MPG123_COMPAT_MSVCRT_IO_64
#endif
#endif
#endif
#if defined(__WATCOMC__) && defined(__NT__)
#if (__WATCOMC__ >= 1100)
#ifndef MPG123_COMPAT_MSVCRT_IO_64
#define MPG123_COMPAT_MSVCRT_IO_64
#endif
#endif
#endif
#endif
#if defined(HAVE__SETMODE) || defined(HAVE_SETMODE) || defined(MPG123_COMPAT_MSVCRT_IO)
// For _setmode(), at least.
#include <io.h>
#endif

View File

@@ -19,7 +19,7 @@
*/
#define MPG123_API_VERSION 48
/** library patch level at client build time */
#define MPG123_PATCHLEVEL 2
#define MPG123_PATCHLEVEL 3
#ifndef MPG123_EXPORT
/** Defines needed for MS Visual Studio(tm) DLL builds.

View File

@@ -137,7 +137,11 @@ static void wrap_io_cleanup(void *handle)
if(ioh->my_fd >= 0)
{
mdebug("closing my fd %d", ioh->my_fd);
#if defined(MPG123_COMPAT_MSVCRT_IO)
_close(ioh->my_fd);
#else
close(ioh->my_fd);
#endif
ioh->my_fd = -1;
}
}
@@ -699,6 +703,35 @@ static int64_t wrap_lseek(void *handle, int64_t offset, int whence)
return -1;
}
// Defining a wrapper to the native read to be sure the prototype matches.
// There are platforms where it is read(int, void*, unsigned int).
// We know that we read small chunks where the difference does not matter. Could
// apply specific hackery, use a common compat_read() (INT123_unintr_read()?) with system
// specifics.
static mpg123_ssize_t fallback_read(int fd, void *buf, size_t count)
{
#if defined(MPG123_COMPAT_MSVCRT_IO)
if(count > UINT_MAX)
{
errno = EOVERFLOW;
return -1;
}
return _read(fd, buf, (unsigned int)count);
#else
return read(fd, buf, count);
#endif
}
static off_t fallback_lseek(int fd, off_t offset, int whence)
{
#if defined(MPG123_COMPAT_MSVCRT_IO)
// Off_t is 32 bit and does fit into long. We know that.
return _lseek(fd, (long)offset, whence);
#else
return lseek(fd, offset, whence);
#endif
}
// This is assuming an internally opened file, which usually will be
// using 64 bit offsets. It keeps reading on on trivial interruptions.
// I guess any file descriptor that matches the libc should work fine.
@@ -730,7 +763,7 @@ static int internal_read64(void *handle, void *buf, size_t bytes, size_t *got_by
}
#endif
errno = 0;
ptrdiff_t part = read(fd, (char*)buf+got, bytes);
ptrdiff_t part = fallback_read(fd, (char*)buf+got, bytes);
if(part > 0) // == 0 is end of file
{
SATURATE_SUB(bytes, part, 0)
@@ -755,13 +788,15 @@ static int64_t internal_lseek64(void *handle, int64_t offset, int whence)
struct wrap_data* ioh = handle;
#ifdef LFS_LARGEFILE_64
return lseek64(ioh->fd, offset, whence);
#elif defined(MPG123_COMPAT_MSVCRT_IO_64)
return _lseeki64(ioh->fd, offset, whence);
#else
if(offset < OFF_MIN || offset > OFF_MAX)
{
errno = EOVERFLOW;
return -1;
}
return lseek(ioh->fd, (off_t)offset, whence);
return fallback_lseek(ioh->fd, (off_t)offset, whence);
#endif
}
@@ -861,16 +896,6 @@ int INT123_wrap_open(mpg123_handle *mh, void *handle, const char *path, int fd,
// So, native off_t reader replacement.
// Defining a wrapper to the native read to be sure the prototype matches.
// There are platforms where it is read(int, void*, unsigned int).
// We know that we read small chunks where the difference does not matter. Could
// apply specific hackery, use a common compat_read() (INT123_unintr_read()?) with system
// specifics.
static mpg123_ssize_t fallback_read(int fd, void *buf, size_t count)
{
return read(fd, buf, count);
}
// In forced 64 bit offset mode, the only definitions of these are
// the _64 ones.
#ifdef FORCED_OFF_64
@@ -902,7 +927,7 @@ int attribute_align_arg mpg123_replace_reader(mpg123_handle *mh, mpg123_ssize_t
ioh->iotype = IO_FD;
ioh->fd = -1; /* On next mpg123_open_fd(), this gets a value. */
ioh->r_read = r_read != NULL ? r_read : fallback_read;
ioh->r_lseek = r_lseek != NULL ? r_lseek : lseek;
ioh->r_lseek = r_lseek != NULL ? r_lseek : fallback_lseek;
}
/* The real reader replacement will happen while opening. */

View File

@@ -16,7 +16,7 @@
// only single spaces as separator to ease parsing by build scripts
#define MPG123_MAJOR 1
#define MPG123_MINOR 32
#define MPG123_PATCH 8
#define MPG123_PATCH 9
// Don't get too wild with that to avoid confusing m4. No brackets.
// Also, it should fit well into a sane file name for the tarball.
#define MPG123_SUFFIX ""