From e1a78b744b324b4dec1e8f5f2c41c95c5b00433a Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Fri, 10 Apr 2009 20:14:10 +0300 Subject: [PATCH] Start moving replacement functions to a static import library --- Makefile.am | 4 +- compat/Makefile.am | 4 ++ compat/asprintf.c | 37 +++++++++++++++ compat/atof.c | 30 +++++++++++++ compat/atoll.c | 30 +++++++++++++ compat/lldiv.c | 29 ++++++++++++ compat/strdup.c | 35 +++++++++++++++ compat/strlcpy.c | 52 +++++++++++++++++++++ compat/strndup.c | 38 ++++++++++++++++ compat/strnlen.c | 31 +++++++++++++ compat/strsep.c | 43 ++++++++++++++++++ compat/strtof.c | 30 +++++++++++++ compat/strtoll.c | 92 +++++++++++++++++++++++++++++++++++++ compat/vasprintf.c | 37 +++++++++++++++ configure.ac | 5 ++- include/vlc_common.h | 3 -- include/vlc_fixups.h | 92 +++++++------------------------------ modules/common.am | 3 +- src/Makefile.am | 4 +- src/extras/libc.c | 105 ------------------------------------------- src/libvlccore.sym | 2 - 21 files changed, 514 insertions(+), 192 deletions(-) create mode 100644 compat/Makefile.am create mode 100644 compat/asprintf.c create mode 100644 compat/atof.c create mode 100644 compat/atoll.c create mode 100644 compat/lldiv.c create mode 100644 compat/strdup.c create mode 100644 compat/strlcpy.c create mode 100644 compat/strndup.c create mode 100644 compat/strnlen.c create mode 100644 compat/strsep.c create mode 100644 compat/strtof.c create mode 100644 compat/strtoll.c create mode 100644 compat/vasprintf.c diff --git a/Makefile.am b/Makefile.am index 26df232f38..4224ba7a2a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,13 +7,13 @@ # which have makefiles with distribution information. # - src (libvlc) is nedeed by modules, mozilla and bindings # - 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 \ libs/loader libs/srtp libs/unzip \ projects/mozilla projects/activex DIST_SUBDIRS = $(BASE_SUBDIRS) $(EXTRA_SUBDIRS) -SUBDIRS = po src +SUBDIRS = po compat src if LOADER SUBDIRS += libs/loader endif diff --git a/compat/Makefile.am b/compat/Makefile.am new file mode 100644 index 0000000000..225ce39aeb --- /dev/null +++ b/compat/Makefile.am @@ -0,0 +1,4 @@ +noinst_LTLIBRARIES = libcompat.la +libcompat_la_SOURCES = +libcompat_la_LIBADD = $(LTLIBOBJS) +libcompat_la_LDFLAGS = -no-undefined diff --git a/compat/asprintf.c b/compat/asprintf.c new file mode 100644 index 0000000000..e3b319d203 --- /dev/null +++ b/compat/asprintf.c @@ -0,0 +1,37 @@ +/***************************************************************************** + * 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 +#endif + +#include +#include + +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; +} diff --git a/compat/atof.c b/compat/atof.c new file mode 100644 index 0000000000..c658dc6e4b --- /dev/null +++ b/compat/atof.c @@ -0,0 +1,30 @@ +/***************************************************************************** + * 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 +#endif + +#include + +double atof (const char *str) +{ + return strtod (str, NULL); +} diff --git a/compat/atoll.c b/compat/atoll.c new file mode 100644 index 0000000000..6c6a347dde --- /dev/null +++ b/compat/atoll.c @@ -0,0 +1,30 @@ +/***************************************************************************** + * 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 +#endif + +#include + +long long atoll (const char *str) +{ + return strtoll (str, NULL, 10); +} diff --git a/compat/lldiv.c b/compat/lldiv.c new file mode 100644 index 0000000000..25f4abc8e6 --- /dev/null +++ b/compat/lldiv.c @@ -0,0 +1,29 @@ +/***************************************************************************** + * 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 +#endif + +lldiv_t lldiv (long long num, long long denom) +{ + lldiv_t d = { num / denom, num % demon, }; + return d; +} diff --git a/compat/strdup.c b/compat/strdup.c new file mode 100644 index 0000000000..7e3765cfc9 --- /dev/null +++ b/compat/strdup.c @@ -0,0 +1,35 @@ +/***************************************************************************** + * 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 +#endif + +#include +#include + +char *strdup (const char *str) +{ + size_t len = strlen (str) + 1; + char *res = malloc (len); + if (res) + memcpy (res, str, len); + return res; +} diff --git a/compat/strlcpy.c b/compat/strlcpy.c new file mode 100644 index 0000000000..bc815ea577 --- /dev/null +++ b/compat/strlcpy.c @@ -0,0 +1,52 @@ +/***************************************************************************** + * 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 +#endif + +#include + +/** + * 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; +} diff --git a/compat/strndup.c b/compat/strndup.c new file mode 100644 index 0000000000..863b075cb9 --- /dev/null +++ b/compat/strndup.c @@ -0,0 +1,38 @@ +/***************************************************************************** + * 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 +#endif + +#include +#include + +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; +} diff --git a/compat/strnlen.c b/compat/strnlen.c new file mode 100644 index 0000000000..96be3d2c11 --- /dev/null +++ b/compat/strnlen.c @@ -0,0 +1,31 @@ +/***************************************************************************** + * 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 +#endif + +#include + +size_t strnlen (const char *str, size_t max) +{ + const char *end = memchr (str, 0, max); + return end ? (size_t)(end - str) : max; +} diff --git a/compat/strsep.c b/compat/strsep.c new file mode 100644 index 0000000000..1163f46599 --- /dev/null +++ b/compat/strsep.c @@ -0,0 +1,43 @@ +/***************************************************************************** + * 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 +#endif + +#include + +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; +} diff --git a/compat/strtof.c b/compat/strtof.c new file mode 100644 index 0000000000..807db0e39f --- /dev/null +++ b/compat/strtof.c @@ -0,0 +1,30 @@ +/***************************************************************************** + * 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 +#endif + +#include + +float strtof (const char *str, char **end) +{ + return strtod (str, end); +} diff --git a/compat/strtoll.c b/compat/strtoll.c new file mode 100644 index 0000000000..1f0a71de82 --- /dev/null +++ b/compat/strtoll.c @@ -0,0 +1,92 @@ +/***************************************************************************** + * 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 +#endif + +#include +#include + +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; +} diff --git a/compat/vasprintf.c b/compat/vasprintf.c new file mode 100644 index 0000000000..98d7e72beb --- /dev/null +++ b/compat/vasprintf.c @@ -0,0 +1,37 @@ +/***************************************************************************** + * 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 +#endif + +#include +#include +#include + +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); +} diff --git a/configure.ac b/configure.ac index 8795978746..3dc383eadb 100644 --- a/configure.ac +++ b/configure.ac @@ -18,6 +18,7 @@ AC_PREREQ(2.59c) AC_CONFIG_SRCDIR(src/libvlc.c) AC_CONFIG_AUX_DIR(autotools) AC_CONFIG_MACRO_DIR(m4) +AC_CONFIG_LIBOBJ_DIR(compat) AC_CANONICAL_BUILD AC_CANONICAL_HOST @@ -550,12 +551,13 @@ dnl Check for system libs needed need_libc=false 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(strncasecmp,,[AC_CHECK_FUNCS(strnicmp)]) AC_CHECK_FUNCS(strcasestr,,[AC_CHECK_FUNCS(stristr)]) AC_FUNC_ALLOCA 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 AC_CHECK_FUNCS([vmsplice]) @@ -5964,6 +5966,7 @@ AC_CONFIG_FILES([ share/Makefile share/vlc_win32_rc.rc share/libvlc_win32_rc.rc + compat/Makefile src/Makefile src/test/Makefile bin/Makefile diff --git a/include/vlc_common.h b/include/vlc_common.h index 77881158cf..2c7ef61967 100644 --- a/include/vlc_common.h +++ b/include/vlc_common.h @@ -731,9 +731,6 @@ static inline uint64_t ntoh64 (uint64_t ll) #define VLC_UNUSED(x) (void)(x) /* 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 ); #if defined(WIN32) || defined(UNDER_CE) diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h index d9872d7b6c..25d5f10d34 100644 --- a/include/vlc_fixups.h +++ b/include/vlc_fixups.h @@ -40,109 +40,51 @@ #endif #ifndef HAVE_STRDUP -# include -# include -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; -} +char *strdup (const char *); #endif #ifndef HAVE_VASPRINTF -# include -# include # include -static inline int vasprintf (char **strp, const char *fmt, va_list ap) -{ - 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); -} +int vasprintf (char **, const char *, va_list); #endif #ifndef HAVE_ASPRINTF -# include -# include -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; -} +int asprintf (char **, const char *, ...); #endif #ifndef HAVE_STRNLEN -# include -static inline size_t strnlen (const char *str, size_t max) -{ - const char *end = (const char *) memchr (str, 0, max); - return end ? (size_t)(end - str) : max; -} +# include +size_t strnlen (const char *, size_t); #endif #ifndef HAVE_STRNDUP -# include -# include -static inline char *strndup (const char *str, size_t max) -{ - size_t len = strnlen (str, max); - char *res = (char *) malloc (len + 1); - if (res) - { - memcpy (res, str, len); - res[len] = '\0'; - } - return res; -} +# include +char *strndup (const char *, size_t); #endif #ifndef HAVE_STRLCPY -# define strlcpy vlc_strlcpy +# include +size_t strlcpy (char *, const char *, size_t); #endif #ifndef HAVE_STRTOF -# define strtof( a, b ) ((float)strtod (a, b)) +float strtof (const char *, char **); #endif #ifndef HAVE_ATOF -# define atof( str ) (strtod ((str), (char **)NULL, 10)) +double atof (const char *); #endif #ifndef HAVE_STRTOLL -# define strtoll vlc_strtoll +long long int strtoll (const char *, char **, int); #endif #ifndef HAVE_STRSEP -static inline 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; -} +char *strsep (char **, const char *); #endif #ifndef HAVE_ATOLL -# define atoll( str ) (strtoll ((str), (char **)NULL, 10)) +long long atoll (const char *); #endif #ifndef HAVE_LLDIV @@ -151,11 +93,7 @@ typedef struct { long long rem; /* Remainder. */ } lldiv_t; -static inline lldiv_t lldiv (long long numer, long long denom) -{ - lldiv_t d = { .quot = numer / denom, .rem = numer % denom }; - return d; -} +lldiv_t lldiv (long long, long long); #endif #ifndef HAVE_GETENV diff --git a/modules/common.am b/modules/common.am index caa5659062..7fbf430c52 100644 --- a/modules/common.am +++ b/modules/common.am @@ -23,7 +23,8 @@ AM_LDFLAGS = -rpath '$(libvlcdir)' \ -shrext $(LIBEXT) \ -no-undefined \ `$(VLC_CONFIG) --ldflags plugin $@` -AM_LIBADD = `$(VLC_CONFIG) -libs plugin $@` $(LTLIBVLCCORE) +AM_LIBADD = `$(VLC_CONFIG) -libs plugin $@` \ + $(LTLIBVLCCORE) $(top_builddir)/compat/libcompat.la include $(srcdir)/Modules.am diff --git a/src/Makefile.am b/src/Makefile.am index eabdb6c909..84f79d094f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -157,9 +157,11 @@ libvlccore_la_CFLAGS = `$(VLC_CONFIG) --cflags libvlc` \ -DLIBDIR=\"$(libdir)\" \ -DPLUGIN_PATH=\"$(vlclibdir)\" libvlccore_la_LDFLAGS = `$(VLC_CONFIG) --ldflags libvlc` $(AM_LDFLAGS) \ + -no-undefined \ -export-symbols $(srcdir)/libvlccore.sym \ -version-info 2:0:0 -libvlccore_la_LIBADD = `$(VLC_CONFIG) -libs libvlc` $(AM_LIBADD) $(LTLIBINTL) +libvlccore_la_LIBADD = `$(VLC_CONFIG) -libs libvlc` $(AM_LIBADD) \ + $(LTLIBINTL) ../compat/libcompat.la libvlccore_la_DEPENDENCIES = libvlccore.sym if HAVE_WIN32 libvlccore_la_DEPENDENCIES += libvlc_win32_rc.$(OBJEXT) diff --git a/src/extras/libc.c b/src/extras/libc.c index acd0924027..6dc1dd137e 100644 --- a/src/extras/libc.c +++ b/src/extras/libc.c @@ -101,111 +101,6 @@ char * vlc_strcasestr( const char *psz_big, const char *psz_little ) #endif } -/***************************************************************************** - * strtoll: convert a string to a 64 bits int. - *****************************************************************************/ -long long vlc_strtoll( const char *nptr, char **endptr, int base ) -{ -#if defined( HAVE_STRTOLL ) - return strtoll( nptr, endptr, base ); -#else - long long i_value = 0; - int sign = 1, newbase = base ? base : 10; - - while( isspace(*nptr) ) nptr++; - - 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; -#endif -} - -/** - * 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) - */ -extern size_t vlc_strlcpy (char *tgt, const char *src, size_t bufsize) -{ -#ifdef HAVE_STRLCPY - return strlcpy (tgt, src, bufsize); -#else - size_t length; - - for (length = 1; (length < bufsize) && *src; length++) - *tgt++ = *src++; - - if (bufsize) - *tgt = '\0'; - - while (*src++) - length++; - - return length - 1; -#endif -} - /***************************************************************************** * vlc_*dir_wrapper: wrapper under Windows to return the list of drive letters * when called with an empty argument or just '\' diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 1ef453b27d..6773ac349a 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -486,8 +486,6 @@ vlc_sd_Start vlc_sd_Stop vlc_sendmsg vlc_strcasestr -vlc_strlcpy -vlc_strtoll vlc_testcancel vlc_thread_create __vlc_thread_join -- 2.39.2