Commit e1a78b74 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Start moving replacement functions to a static import library

parent 6c3b2898
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
# which have makefiles with distribution information. # which have makefiles with distribution information.
# - src (libvlc) is nedeed by modules, mozilla and bindings # - src (libvlc) is nedeed by modules, mozilla and bindings
# - libs/* are needed by modules # - libs/* are needed by modules
BASE_SUBDIRS = po src bin modules share doc test BASE_SUBDIRS = po compat src bin modules share doc test
EXTRA_SUBDIRS = m4 extras/package/ipkg \ EXTRA_SUBDIRS = m4 extras/package/ipkg \
libs/loader libs/srtp libs/unzip \ libs/loader libs/srtp libs/unzip \
projects/mozilla projects/activex projects/mozilla projects/activex
DIST_SUBDIRS = $(BASE_SUBDIRS) $(EXTRA_SUBDIRS) DIST_SUBDIRS = $(BASE_SUBDIRS) $(EXTRA_SUBDIRS)
SUBDIRS = po src SUBDIRS = po compat src
if LOADER if LOADER
SUBDIRS += libs/loader SUBDIRS += libs/loader
endif endif
......
noinst_LTLIBRARIES = libcompat.la
libcompat_la_SOURCES =
libcompat_la_LIBADD = $(LTLIBOBJS)
libcompat_la_LDFLAGS = -no-undefined
/*****************************************************************************
* asprintf.c: asprintf() replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdarg.h>
int asprintf (char **strp, const char *fmt, ...)
{
va_list ap;
int ret;
va_start (ap, fmt);
ret = vasprintf (strp, fmt, ap);
va_end (ap);
return ret;
}
/*****************************************************************************
* atof.c: atof replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
double atof (const char *str)
{
return strtod (str, NULL);
}
/*****************************************************************************
* atoll.c: atoll replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
long long atoll (const char *str)
{
return strtoll (str, NULL, 10);
}
/*****************************************************************************
* lldiv.c: lldiv replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
lldiv_t lldiv (long long num, long long denom)
{
lldiv_t d = { num / denom, num % demon, };
return d;
}
/*****************************************************************************
* strdup.c: strdup replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include <stdlib.h>
char *strdup (const char *str)
{
size_t len = strlen (str) + 1;
char *res = malloc (len);
if (res)
memcpy (res, str, len);
return res;
}
/*****************************************************************************
* strlcpy.c: BSD strlcpy replacement
*****************************************************************************
* Copyright © 2006 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stddef.h>
/**
* Copy a string to a sized buffer. The result is always nul-terminated
* (contrary to strncpy()).
*
* @param dest destination buffer
* @param src string to be copied
* @param len maximum number of characters to be copied plus one for the
* terminating nul.
*
* @return strlen(src)
*/
size_t strlcpy (char *tgt, const char *src, size_t bufsize)
{
size_t length;
for (length = 1; (length < bufsize) && *src; length++)
*tgt++ = *src++;
if (bufsize)
*tgt = '\0';
while (*src++)
length++;
return length - 1;
}
/*****************************************************************************
* strndup.c: strndup replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include <stdlib.h>
char *strndup (const char *str, size_t max)
{
size_t len = strnlen (str, max);
char *res = malloc (len + 1);
if (res)
{
memcpy (res, str, len);
res[len] = '\0';
}
return res;
}
/*****************************************************************************
* strnlen.c: strnlen replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
size_t strnlen (const char *str, size_t max)
{
const char *end = memchr (str, 0, max);
return end ? (size_t)(end - str) : max;
}
/*****************************************************************************
* strsep.c: BSD strsep replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
char *strsep( char **ppsz_string, const char *psz_delimiters )
{
char *psz_string = *ppsz_string;
if( !psz_string )
return NULL;
char *p = strpbrk( psz_string, psz_delimiters );
if( !p )
{
*ppsz_string = NULL;
return psz_string;
}
*p++ = '\0';
*ppsz_string = p;
return psz_string;
}
/*****************************************************************************
* strtof.c: strtof replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
float strtof (const char *str, char **end)
{
return strtod (str, end);
}
/*****************************************************************************
* strtoll.c: strtoll replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
long long int strtof( const char *nptr, char **endptr, int base )
{
long long i_value = 0;
int sign = 1, newbase = base ? base : 10;
nptr += strspn( nptr, "\t " );
if( *nptr == '-' )
{
sign = -1;
nptr++;
}
/* Try to detect base */
if( *nptr == '0' )
{
newbase = 8;
nptr++;
if( *nptr == 'x' )
{
newbase = 16;
nptr++;
}
}
if( base && newbase != base )
{
if( endptr ) *endptr = (char *)nptr;
return i_value;
}
switch( newbase )
{
case 10:
while( *nptr >= '0' && *nptr <= '9' )
{
i_value *= 10;
i_value += ( *nptr++ - '0' );
}
if( endptr ) *endptr = (char *)nptr;
break;
case 16:
while( (*nptr >= '0' && *nptr <= '9') ||
(*nptr >= 'a' && *nptr <= 'f') ||
(*nptr >= 'A' && *nptr <= 'F') )
{
int i_valc = 0;
if(*nptr >= '0' && *nptr <= '9') i_valc = *nptr - '0';
else if(*nptr >= 'a' && *nptr <= 'f') i_valc = *nptr - 'a' +10;
else if(*nptr >= 'A' && *nptr <= 'F') i_valc = *nptr - 'A' +10;
i_value *= 16;
i_value += i_valc;
nptr++;
}
if( endptr ) *endptr = (char *)nptr;
break;
default:
i_value = strtol( nptr, endptr, newbase );
break;
}
return i_value * sign;
}
/*****************************************************************************
* vasprintf.c: vasprintf replacement
*****************************************************************************
* Copyright © 1998-2008 the VideoLAN project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vasprintf (char **strp, const char *fmt, va_list ap)
{
ssize_t len = vsnprintf (NULL, 0, fmt, ap) + 1;
char *res = malloc (len);
if (res == NULL)
return -1;
*strp = res;
return vsnprintf (res, len, fmt, ap);
}
...@@ -18,6 +18,7 @@ AC_PREREQ(2.59c) ...@@ -18,6 +18,7 @@ AC_PREREQ(2.59c)
AC_CONFIG_SRCDIR(src/libvlc.c) AC_CONFIG_SRCDIR(src/libvlc.c)
AC_CONFIG_AUX_DIR(autotools) AC_CONFIG_AUX_DIR(autotools)
AC_CONFIG_MACRO_DIR(m4) AC_CONFIG_MACRO_DIR(m4)
AC_CONFIG_LIBOBJ_DIR(compat)
AC_CANONICAL_BUILD AC_CANONICAL_BUILD
AC_CANONICAL_HOST AC_CANONICAL_HOST
...@@ -550,12 +551,13 @@ dnl Check for system libs needed ...@@ -550,12 +551,13 @@ dnl Check for system libs needed
need_libc=false need_libc=false
dnl Check for usual libc functions dnl Check for usual libc functions
AC_CHECK_FUNCS([gettimeofday strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid_r memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon fork bsearch lstat strlcpy strdup strndup strnlen atof lldiv posix_fadvise posix_madvise uselocale]) AC_CHECK_FUNCS([gettimeofday isatty swab sigrelse getpwuid_r memalign posix_memalign if_nametoindex getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon fork bsearch lstat posix_fadvise posix_madvise uselocale])
AC_CHECK_FUNCS(strcasecmp,,[AC_CHECK_FUNCS(stricmp)]) AC_CHECK_FUNCS(strcasecmp,,[AC_CHECK_FUNCS(stricmp)])
AC_CHECK_FUNCS(strncasecmp,,[AC_CHECK_FUNCS(strnicmp)]) AC_CHECK_FUNCS(strncasecmp,,[AC_CHECK_FUNCS(strnicmp)])
AC_CHECK_FUNCS(strcasestr,,[AC_CHECK_FUNCS(stristr)]) AC_CHECK_FUNCS(strcasestr,,[AC_CHECK_FUNCS(stristr)])
AC_FUNC_ALLOCA AC_FUNC_ALLOCA
AC_CHECK_FUNCS(fcntl) AC_CHECK_FUNCS(fcntl)
AC_REPLACE_FUNCS([asprintf atof atoll lldiv strdup strlcpy strndup strnlen strsep strtof strtoll vasprintf])
dnl Check for Linux system calls dnl Check for Linux system calls
AC_CHECK_FUNCS([vmsplice]) AC_CHECK_FUNCS([vmsplice])
...@@ -5964,6 +5966,7 @@ AC_CONFIG_FILES([ ...@@ -5964,6 +5966,7 @@ AC_CONFIG_FILES([
share/Makefile share/Makefile
share/vlc_win32_rc.rc share/vlc_win32_rc.rc
share/libvlc_win32_rc.rc share/libvlc_win32_rc.rc
compat/Makefile
src/Makefile src/Makefile
src/test/Makefile src/test/Makefile
bin/Makefile bin/Makefile
......
...@@ -731,9 +731,6 @@ static inline uint64_t ntoh64 (uint64_t ll) ...@@ -731,9 +731,6 @@ static inline uint64_t ntoh64 (uint64_t ll)
#define VLC_UNUSED(x) (void)(x) #define VLC_UNUSED(x) (void)(x)
/* Stuff defined in src/extras/libc.c */ /* Stuff defined in src/extras/libc.c */
VLC_EXPORT( size_t, vlc_strlcpy, ( char *, const char *, size_t ) );
VLC_EXPORT( long long, vlc_strtoll, ( const char *nptr, char **endptr, int base ) LIBVLC_USED );
VLC_EXPORT( char *, vlc_strcasestr, ( const char *s1, const char *s2 ) LIBVLC_USED ); VLC_EXPORT( char *, vlc_strcasestr, ( const char *s1, const char *s2 ) LIBVLC_USED );
#if defined(WIN32) || defined(UNDER_CE) #if defined(WIN32) || defined(UNDER_CE)
......
...@@ -40,109 +40,51 @@ ...@@ -40,109 +40,51 @@
#endif #endif
#ifndef HAVE_STRDUP #ifndef HAVE_STRDUP
# include <string.h> char *strdup (const char *);
# include <stdlib.h>
static inline char *strdup (const char *str)
{
size_t len = strlen (str) + 1;
char *res = (char *)malloc (len);
if (res) memcpy (res, str, len);
return res;
}
#endif #endif
#ifndef HAVE_VASPRINTF #ifndef HAVE_VASPRINTF
# include <stdio.h>
# include <stdlib.h>
# include <stdarg.h> # include <stdarg.h>
static inline int vasprintf (char **strp, const char *fmt, va_list ap) int vasprintf (char **, const char *, va_list);
{
int len = vsnprintf (NULL, 0, fmt, ap) + 1;
char *res = (char *)malloc (len);
if (res == NULL)
return -1;
*strp = res;
return vsnprintf (res, len, fmt, ap);
}
#endif #endif
#ifndef HAVE_ASPRINTF #ifndef HAVE_ASPRINTF
# include <stdio.h> int asprintf (char **, const char *, ...);
# include <stdarg.h>
static inline int asprintf (char **strp, const char *fmt, ...)
{
va_list ap;
int ret;
va_start (ap, fmt);
ret = vasprintf (strp, fmt, ap);
va_end (ap);
return ret;
}
#endif #endif
#ifndef HAVE_STRNLEN #ifndef HAVE_STRNLEN
# include <string.h> # include <stddef.h>
static inline size_t strnlen (const char *str, size_t max) size_t strnlen (const char *, size_t);
{
const char *end = (const char *) memchr (str, 0, max);
return end ? (size_t)(end - str) : max;
}
#endif #endif
#ifndef HAVE_STRNDUP #ifndef HAVE_STRNDUP
# include <string.h> # include <stddef.h>
# include <stdlib.h> char *strndup (const char *, size_t);
static inline char *strndup (const char *str, size_t max)
{
size_t len = strnlen (str, max);