Move remaining replacement to static import library

This commit is contained in:
Rémi Denis-Courmont 2009-04-10 22:17:13 +03:00
parent 003bdf4a18
commit 8186391531
12 changed files with 256 additions and 102 deletions

35
compat/gmtime_r.c Normal file
View File

@ -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 <config.h>
#endif
#include <time.h>
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;
}

37
compat/localtime_r.c Normal file
View File

@ -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 <config.h>
#endif
#include <time.h>
/* 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;
}

31
compat/rewind.c Normal file
View File

@ -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 <config.h>
#endif
#include <stdio.h>
void rewind (FILE *stream)
{
fseek (stream, 0L, SEEK_SET);
clearerr (stream);
}

42
compat/strcasecmp.c Normal file
View File

@ -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 <config.h>
#endif
#include <string.h>
#include <ctype.h>
#include <assert.h>
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
}

52
compat/strcasestr.c Normal file
View File

@ -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 <config.h>
#endif
#include <string.h>
#include <ctype.h>
#include <assert.h>
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;
}

43
compat/strncasecmp.c Normal file
View File

@ -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 <config.h>
#endif
#include <string.h>
#include <ctype.h>
#include <assert.h>
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
}

View File

@ -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])

View File

@ -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 */

View File

@ -105,69 +105,30 @@ static inline char *getenv (const char *name)
#endif
#ifndef HAVE_STRCASECMP
# ifndef HAVE_STRICMP
# include <ctype.h>
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 <ctype.h>
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_GMTIME_R
# include <time.h>
struct tm *gmtime_r (const time_t *, struct tm *);
#endif
#ifndef HAVE_LOCALTIME_R
/* If localtime_r() is not provided, we assume localtime() uses
* thread-specific storage. */
# include <time.h>
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 *localtime_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;
*result = *s;
return result;
}
#ifndef HAVE_REWIND
# include <stdio.h>
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 */

View File

@ -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<KaxChapterTranslate*>( l );

View File

@ -68,39 +68,6 @@
# include <windows.h>
#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 '\'

View File

@ -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