From 818639153101c70514bc001d465485d23899a320 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Fri, 10 Apr 2009 22:17:13 +0300 Subject: [PATCH] Move remaining replacement to static import library --- compat/gmtime_r.c | 35 ++++++++++ compat/localtime_r.c | 37 ++++++++++ compat/rewind.c | 31 +++++++++ compat/strcasecmp.c | 42 +++++++++++ compat/strcasestr.c | 52 ++++++++++++++ compat/strncasecmp.c | 43 ++++++++++++ configure.ac | 8 +-- include/vlc_common.h | 1 - include/vlc_fixups.h | 73 ++++---------------- modules/demux/mkv/matroska_segment_parse.cpp | 2 - src/extras/libc.c | 33 --------- src/libvlccore.sym | 1 - 12 files changed, 256 insertions(+), 102 deletions(-) create mode 100644 compat/gmtime_r.c create mode 100644 compat/localtime_r.c create mode 100644 compat/rewind.c create mode 100644 compat/strcasecmp.c create mode 100644 compat/strcasestr.c create mode 100644 compat/strncasecmp.c diff --git a/compat/gmtime_r.c b/compat/gmtime_r.c new file mode 100644 index 0000000000..94d312309c --- /dev/null +++ b/compat/gmtime_r.c @@ -0,0 +1,35 @@ +/***************************************************************************** + * gmtime_r.c: POSIX gmtime_r() 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 + +struct tm *gmtime_r (const time_t *timep, struct tm *result) +{ + struct tm *s = gmtime (timep); + if (s == NULL) + return NULL; + + *result = *s; + return result; +} diff --git a/compat/localtime_r.c b/compat/localtime_r.c new file mode 100644 index 0000000000..f3e2811dfe --- /dev/null +++ b/compat/localtime_r.c @@ -0,0 +1,37 @@ +/***************************************************************************** + * localtime_r.c: POSIX localtime_r() 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 + +/* If localtime_r() is not provided, we assume localtime() uses + * thread-specific storage. */ +struct tm *localtime_r (const time_t *timep, struct tm *result) +{ + struct tm *s = localtime (timep); + if (s == NULL) + return NULL; + + *result = *s; + return result; +} diff --git a/compat/rewind.c b/compat/rewind.c new file mode 100644 index 0000000000..c27323a0e4 --- /dev/null +++ b/compat/rewind.c @@ -0,0 +1,31 @@ +/***************************************************************************** + * rewind.c: C rewind 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 + +void rewind (FILE *stream) +{ + fseek (stream, 0L, SEEK_SET); + clearerr (stream); +} diff --git a/compat/strcasecmp.c b/compat/strcasecmp.c new file mode 100644 index 0000000000..7ef670c55c --- /dev/null +++ b/compat/strcasecmp.c @@ -0,0 +1,42 @@ +/***************************************************************************** + * strcasecmp.c: POSIX strcasecmp() 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 strcasecmp (const char *s1, const char *s2) +{ +#ifdef HAVE_STRICMP + return stricmp (s1, s2); +#else + for (size_t i = 0;; i++) + { + int d = tolower (s1[i]) - tolower (s2[i]); + if (d || !s1[i]) + return d; + assert (s2[i]); + } +#endif +} diff --git a/compat/strcasestr.c b/compat/strcasestr.c new file mode 100644 index 0000000000..45b8830b51 --- /dev/null +++ b/compat/strcasestr.c @@ -0,0 +1,52 @@ +/***************************************************************************** + * strcasestr.c: GNU strcasestr() replacement + ***************************************************************************** + * Copyright © 2002-2006 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 strcasecmp (const char *psz_big, const char *psz_little) +{ + char *p_pos = (char *)psz_big; + + if( !*psz_little ) return p_pos; + + while( *p_pos ) + { + if( toupper( *p_pos ) == toupper( *psz_little ) ) + { + char * psz_cur1 = p_pos + 1; + char * psz_cur2 = (char *)psz_little + 1; + while( *psz_cur1 && *psz_cur2 && + toupper( *psz_cur1 ) == toupper( *psz_cur2 ) ) + { + psz_cur1++; + psz_cur2++; + } + if( !*psz_cur2 ) return p_pos; + } + p_pos++; + } + return NULL; +} diff --git a/compat/strncasecmp.c b/compat/strncasecmp.c new file mode 100644 index 0000000000..b834b4831f --- /dev/null +++ b/compat/strncasecmp.c @@ -0,0 +1,43 @@ +/***************************************************************************** + * strncasecmp.c: POSIX strncasecmp() 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 strncasecmp (const char *s1, const char *s2) +{ +#ifdef HAVE_STRNICMP + return strnicmp (s1, s2); +#else + for (size_t i = 0; i < n; i++) + { + int d = tolower (s1[i]) - tolower (s2[i]); + if (d || !s1[i]) + return d; + assert (s2[i]); + } + return 0; +#endif +} diff --git a/configure.ac b/configure.ac index 85fe3ebce2..d0fe51fc81 100644 --- a/configure.ac +++ b/configure.ac @@ -551,13 +551,11 @@ dnl Check for system libs needed need_libc=false dnl Check for usual libc functions -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 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_CHECK_FUNCS([gettimeofday isatty swab sigrelse getpwuid_r memalign posix_memalign if_nametoindex getenv putenv setenv ctime_r lrintf daemon fork lstat posix_fadvise posix_madvise uselocale]) AC_FUNC_ALLOCA AC_CHECK_FUNCS(fcntl) -AC_REPLACE_FUNCS([asprintf atof atoll lldiv strdup strlcpy strndup strnlen strsep strtof strtoll vasprintf]) +AC_REPLACE_FUNCS([asprintf atof atoll gmtime_r lldiv localtime_r rewind strcasecmp strcasestr strdup strlcpy strncasecmp strndup strnlen strsep strtof strtoll vasprintf]) +AC_CHECK_FUNCS([stricmp strnicmp]) dnl Check for Linux system calls AC_CHECK_FUNCS([vmsplice]) diff --git a/include/vlc_common.h b/include/vlc_common.h index 2c7ef61967..2ca14508c0 100644 --- a/include/vlc_common.h +++ b/include/vlc_common.h @@ -731,7 +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( char *, vlc_strcasestr, ( const char *s1, const char *s2 ) LIBVLC_USED ); #if defined(WIN32) || defined(UNDER_CE) /* win32, cl and icl support */ diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h index 25d5f10d34..b433834bbf 100644 --- a/include/vlc_fixups.h +++ b/include/vlc_fixups.h @@ -105,69 +105,30 @@ static inline char *getenv (const char *name) #endif #ifndef HAVE_STRCASECMP -# ifndef HAVE_STRICMP -# include -static inline int strcasecmp (const char *s1, const char *s2) -{ - for (size_t i = 0;; i++) - { - int d = tolower (s1[i]) - tolower (s2[i]); - if (d || !s1[i]) return d; - } - return 0; -} -# else -# define strcasecmp stricmp -# endif +int strcasecmp (const char *, const char *); #endif #ifndef HAVE_STRNCASECMP -# ifndef HAVE_STRNICMP -# include -static inline int strncasecmp (const char *s1, const char *s2, size_t n) -{ - for (size_t i = 0; i < n; i++) - { - int d = tolower (s1[i]) - tolower (s2[i]); - if (d || !s1[i]) return d; - } - return 0; -} -# else -# define strncasecmp strnicmp -# endif +int strncasecmp (const char *, const char *, size_t); #endif #ifndef HAVE_STRCASESTR -# ifndef HAVE_STRISTR -# define strcasestr vlc_strcasestr -# else -# define strcasestr stristr -# endif +char *strcasestr (const char *, const char * #endif -#ifndef HAVE_LOCALTIME_R -/* If localtime_r() is not provided, we assume localtime() uses - * thread-specific storage. */ +#ifndef HAVE_GMTIME_R # include -static inline struct tm *localtime_r (const time_t *timep, struct tm *result) -{ - struct tm *s = localtime (timep); - if (s == NULL) - return NULL; +struct tm *gmtime_r (const time_t *, struct tm *); +#endif - *result = *s; - return result; -} -static inline struct tm *gmtime_r (const time_t *timep, struct tm *result) -{ - struct tm *s = gmtime (timep); - if (s == NULL) - return NULL; +#ifndef HAVE_LOCALTIME_R +# include +struct tm *localtime_r (const time_t *, struct tm *); +#endif - *result = *s; - return result; -} +#ifndef HAVE_REWIND +# include +void rewind (FILE *); #endif /* Alignment of critical static data structures */ @@ -201,12 +162,4 @@ typedef void *locale_t; #define N_(str) gettext_noop (str) #define gettext_noop(str) (str) -#ifdef UNDER_CE -static inline void rewind ( FILE *stream ) -{ - fseek(stream, 0L, SEEK_SET); - clearerr(stream); -} -#endif - #endif /* !LIBVLC_FIXUPS_H */ diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp index fb1b23376a..db889db1db 100644 --- a/modules/demux/mkv/matroska_segment_parse.cpp +++ b/modules/demux/mkv/matroska_segment_parse.cpp @@ -767,7 +767,6 @@ void matroska_segment_c::ParseInfo( KaxInfo *info ) msg_Dbg( &sys.demuxer, "| | + family=%d", *(uint32*)uid->GetBuffer() ); } -#if defined( HAVE_GMTIME_R ) else if( MKV_IS_ID( l, KaxDateUTC ) ) { KaxDateUTC &date = *(KaxDateUTC*)l; @@ -785,7 +784,6 @@ void matroska_segment_c::ParseInfo( KaxInfo *info ) msg_Dbg( &sys.demuxer, "| | + Date=%s", psz_date_utc ); } } -#endif else if( MKV_IS_ID( l, KaxChapterTranslate ) ) { KaxChapterTranslate *p_trans = static_cast( l ); diff --git a/src/extras/libc.c b/src/extras/libc.c index 6dc1dd137e..3bb0b5654b 100644 --- a/src/extras/libc.c +++ b/src/extras/libc.c @@ -68,39 +68,6 @@ # include #endif -/****************************************************************************** - * strcasestr: find a substring (little) in another substring (big) - * Case sensitive. Return NULL if not found, return big if little == null - *****************************************************************************/ -char * vlc_strcasestr( const char *psz_big, const char *psz_little ) -{ -#if defined (HAVE_STRCASESTR) || defined (HAVE_STRISTR) - return strcasestr (psz_big, psz_little); -#else - char *p_pos = (char *)psz_big; - - if( !psz_big || !psz_little || !*psz_little ) return p_pos; - - while( *p_pos ) - { - if( toupper( *p_pos ) == toupper( *psz_little ) ) - { - char * psz_cur1 = p_pos + 1; - char * psz_cur2 = (char *)psz_little + 1; - while( *psz_cur1 && *psz_cur2 && - toupper( *psz_cur1 ) == toupper( *psz_cur2 ) ) - { - psz_cur1++; - psz_cur2++; - } - if( !*psz_cur2 ) return p_pos; - } - p_pos++; - } - return NULL; -#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 6773ac349a..b14b8d48f9 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -485,7 +485,6 @@ vlc_sdp_Start vlc_sd_Start vlc_sd_Stop vlc_sendmsg -vlc_strcasestr vlc_testcancel vlc_thread_create __vlc_thread_join -- 2.39.2