1
0
mirror of http://mpg123.de/trunk/.git synced 2025-10-29 14:09:21 +03:00

Add alias functions for the native large file bitness, that is functions with _32 suffix on 32 bit systems, with _64 bit suffix on 64 bit systems.

That should help people that define _LARGE_FILE_BITS where it doesn't really make sense, but glibc supports it nevertheless.



git-svn-id: svn://scm.orgis.org/mpg123/trunk@2678 35dc7657-300d-0410-a2e5-dc2837fedb53
This commit is contained in:
thor
2010-05-16 14:17:20 +00:00
parent 692d34e8f6
commit b3b3ce2d84
2 changed files with 167 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ AC_PREREQ(2.57)
dnl ############# Initialisation dnl ############# Initialisation
d
AC_INIT([mpg123], [1.12.x-dev], [mpg123-devel@lists.sourceforge.net]) AC_INIT([mpg123], [1.12.x-dev], [mpg123-devel@lists.sourceforge.net])
dnl Increment API_VERSION when the API gets changes (new functions). dnl Increment API_VERSION when the API gets changes (new functions).
API_VERSION=25 API_VERSION=25
@@ -868,25 +868,12 @@ dnl Note: I started writing this with with multiline replacements.
dnl Does not work. Automake insists on putting these into Makefiles where they break things. dnl Does not work. Automake insists on putting these into Makefiles where they break things.
if test "x$ac_cv_sys_file_offset_bits" = x || echo "$ac_cv_sys_file_offset_bits" | grep '@<:@^0-9@:>@' > /dev/null; then if test "x$ac_cv_sys_file_offset_bits" = x || echo "$ac_cv_sys_file_offset_bits" | grep '@<:@^0-9@:>@' > /dev/null; then
dnl if it has non-numeric chars or is empty... ignore... dnl if it has non-numeric chars or is empty... ignore...
LARGEFILE_BITS=
LARGEFILE_SUFFIX=
LFS_LOBJ= LFS_LOBJ=
else else
LARGEFILE_BITS="$ac_cv_sys_file_offset_bits"
LARGEFILE_SUFFIX="_$ac_cv_sys_file_offset_bits"
# Add dual-mode wrapper code. # Add dual-mode wrapper code.
LFS_LOBJ=lfs_wrap.lo LFS_LOBJ=lfs_wrap.lo
fi fi
AC_SUBST(LFS_LOBJ)
dnl Insert the function name redefinitions and export symbols as needed.
dnl ...based on these two variables and manual work in src/libmpg123/mpg123.h.in .
AC_SUBST(LARGEFILE_BITS)
AC_SUBST(LARGEFILE_SUFFIX)
AC_SUBST(LARGEFILE_SWITCH)
# Using the lower level macros instead of AC_TYPE_* for compatibility with not freshest autoconf. # Using the lower level macros instead of AC_TYPE_* for compatibility with not freshest autoconf.
AC_CHECK_TYPE(size_t, unsigned long) AC_CHECK_TYPE(size_t, unsigned long)
AC_CHECK_TYPE(ssize_t, long) AC_CHECK_TYPE(ssize_t, long)
@@ -901,6 +888,32 @@ AC_CHECK_SIZEOF(off_t,4)
AC_CHECK_SIZEOF(int32_t) AC_CHECK_SIZEOF(int32_t)
AC_CHECK_SIZEOF(long,4) AC_CHECK_SIZEOF(long,4)
# The alias functions want to know the native off_t bits.
# "Native" also means large file offsets, if enabled, it's what is native to the mpg123 library.
if test "x$ac_cv_sizeof_long" = "x"; then
AC_MSG_ERROR([Cannot determine sizeof(long)?])
else
LFS_ALIAS_BITS=`expr "$ac_cv_sizeof_long" "*" "8"`
AC_DEFINE_UNQUOTED([LFS_ALIAS_BITS], $LFS_ALIAS_BITS,
[Define this to the size of long type in bits, used for LFS small/native alias functions.])
fi
lfs_alias=enabled
AC_ARG_ENABLE(lfs-alias,
[ --disable-lfs-alias disable alias wrappers for largefile bitness (mpg123_seek_32 in addition to mpg123_seek, mpg123_seek_64 as alias onx86-64) ],
[
if test "x$enableval" = xno; then
lfs_alias="disabled"
fi
], [])
if test "x$lfs_alias" = "xenabled"; then
LFS_LOBJ="$LFS_LOBJ lfs_alias.lo"
fi
AC_SUBST(LFS_LOBJ)
dnl ############## Function Checks dnl ############## Function Checks
AC_FUNC_MMAP AC_FUNC_MMAP
@@ -2014,6 +2027,8 @@ else
echo " File offsets ............ $LARGEFILE_BITS" echo " File offsets ............ $LARGEFILE_BITS"
echo " The lib will (try to) support default offset size, too." echo " The lib will (try to) support default offset size, too."
fi fi
echo " LFS alias symbols ....... $lfs_alias ($LFS_ALIAS_BITS)"
echo " Alignment checks ........ $aligncheck" echo " Alignment checks ........ $aligncheck"
if test x"$aligncheck" = xenabled; then if test x"$aligncheck" = xenabled; then
if test x"$ccalign" != xyes; then if test x"$ccalign" != xyes; then

138
src/libmpg123/lfs_alias.c Normal file
View File

@@ -0,0 +1,138 @@
/*
lfs_alias: Aliases to the small/native API functions with the size of long int as suffix.
copyright 2010 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Thomas Orgis
Use case: Client code on Linux/x86-64 that defines _FILE_OFFSET_BITS to 64, which is the only choice on that platform anyway. It should be no-op, but prompts the platform-agnostic header of mpg123 to define API calls with the corresponding suffix.
This file provides the names for this case. It's cruft, but glibc does it, too -- so people rely on it.
Oh, and it also caters for the lunatics that define _FILE_OFFSET_BITS=32 on 32 bit platforms.
*/
#include "config.h"
#ifndef LFS_ALIAS_BITS
#error "I need the count of alias bits here."
#endif
/* Use the plain function names. */
#define MPG123_NO_LARGENAME MPG123_MACROCAT(_, LFS_ALIAS_BITS)
#include "mpg123.h"
/* Now get the rest of the infrastructure on speed, namely attribute_align_arg, to stay safe. */
#include "mpg123lib_intern.h"
#define MACROCAT_REALLY(a, b) a ## b
#define MACROCAT(a, b) MACROCAT_REALLY(a, b)
#define ALIAS_SUFFIX MACROCAT(_, LFS_ALIAS_BITS)
#define ALIAS_NAME(func) MACROCAT(func, ALIAS_SUFFIX)
/*
Extract the list of functions we need wrappers for, pregenerating the wrappers for simple cases:
perl -ne '
if(/^\s*EXPORT\s+(\S+)\s+(mpg123_\S+)\((.*)\);\s*$/)
{
my $type = $1;
my $name = $2;
my $args = $3;
next unless ($type =~ /off_t/ or $args =~ /off_t/);
$type =~ s/off_t/long/g;
my @nargs = ();
$args =~ s/off_t/long/g;
foreach my $a (split(/,/, $args))
{
$a =~ s/^.*\s\**([a-z_]+)$/$1/;
push(@nargs, $a);
}
my $nargs = join(", ", @nargs);
$nargs = "Human: figure me out." if($nargs =~ /\(/);
print <<EOT
$type attribute_align_arg ALIAS_NAME($name)($args)
{
return $name($nargs);
}
EOT
}' < mpg123.h.in
*/
int attribute_align_arg ALIAS_NAME(mpg123_decode_frame)(mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
{
return mpg123_decode_frame(mh, num, audio, bytes);
}
int attribute_align_arg ALIAS_NAME(mpg123_framebyframe_decode)(mpg123_handle *mh, long *num, unsigned char **audio, size_t *bytes)
{
return mpg123_framebyframe_decode(mh, num, audio, bytes);
}
long attribute_align_arg ALIAS_NAME(mpg123_tell)(mpg123_handle *mh)
{
return mpg123_tell(mh);
}
long attribute_align_arg ALIAS_NAME(mpg123_tellframe)(mpg123_handle *mh)
{
return mpg123_tellframe(mh);
}
long attribute_align_arg ALIAS_NAME(mpg123_tell_stream)(mpg123_handle *mh)
{
return mpg123_tell_stream(mh);
}
long attribute_align_arg ALIAS_NAME(mpg123_seek)(mpg123_handle *mh, long sampleoff, int whence)
{
return mpg123_seek(mh, sampleoff, whence);
}
long attribute_align_arg ALIAS_NAME(mpg123_feedseek)(mpg123_handle *mh, long sampleoff, int whence, long *input_offset)
{
return mpg123_feedseek(mh, sampleoff, whence, input_offset);
}
long attribute_align_arg ALIAS_NAME(mpg123_seek_frame)(mpg123_handle *mh, long frameoff, int whence)
{
return mpg123_seek_frame(mh, frameoff, whence);
}
long attribute_align_arg ALIAS_NAME(mpg123_timeframe)(mpg123_handle *mh, double sec)
{
return mpg123_timeframe(mh, sec);
}
int attribute_align_arg ALIAS_NAME(mpg123_index)(mpg123_handle *mh, long **offsets, long *step, size_t *fill)
{
return mpg123_index(mh, offsets, step, fill);
}
int attribute_align_arg ALIAS_NAME(mpg123_set_index)(mpg123_handle *mh, long *offsets, long step, size_t fill)
{
return mpg123_set_index(mh, offsets, step, fill);
}
int attribute_align_arg ALIAS_NAME(mpg123_position)( mpg123_handle *mh, long frame_offset, long buffered_bytes, long *current_frame, long *frames_left, double *current_seconds, double *seconds_left)
{
return mpg123_position(mh, frame_offset, buffered_bytes, current_frame, frames_left, current_seconds, seconds_left);
}
long attribute_align_arg ALIAS_NAME(mpg123_length)(mpg123_handle *mh)
{
return mpg123_length(mh);
}
int attribute_align_arg ALIAS_NAME(mpg123_set_filesize)(mpg123_handle *mh, long size)
{
return mpg123_set_filesize(mh, size);
}
int attribute_align_arg ALIAS_NAME(mpg123_replace_reader)(mpg123_handle *mh, ssize_t (*r_read) (int, void *, size_t), long (*r_lseek)(int, long, int))
{
return mpg123_replace_reader(mh, r_read, r_lseek);
}
int attribute_align_arg ALIAS_NAME(mpg123_replace_reader_handle)(mpg123_handle *mh, ssize_t (*r_read) (void *, void *, size_t), long (*r_lseek)(void *, long, int), void (*cleanup)(void*))
{
return mpg123_replace_reader_handle(mh, r_read, r_lseek, cleanup);
}