]> git.sesse.net Git - vlc/commitdiff
Inline strdup, strndup, lldiv and getenv
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 24 May 2008 08:55:05 +0000 (11:55 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 24 May 2008 08:55:05 +0000 (11:55 +0300)
Also fix an overflow in strndup().

include/vlc_common.h
include/vlc_fixups.h
src/extras/libc.c
src/libvlccore.sym

index 0ba6de4982e2c2ae75ad683acb4706f4f0ab1a23..5206dbe38dc5469891535b0fadd9a319ab75d644 100644 (file)
@@ -719,31 +719,18 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw )
 #define VLC_UNUSED(x) (void)(x)
 
 /* Stuff defined in src/extras/libc.c */
 #define VLC_UNUSED(x) (void)(x)
 
 /* Stuff defined in src/extras/libc.c */
-VLC_EXPORT( char *, vlc_strdup, ( const char *s ) );
 VLC_EXPORT( int, vlc_vasprintf, (char **, const char *, va_list ) );
 VLC_EXPORT( int, vlc_asprintf, (char **, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
 VLC_EXPORT( int, vlc_vasprintf, (char **, const char *, va_list ) );
 VLC_EXPORT( int, vlc_asprintf, (char **, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
-VLC_EXPORT( char *, vlc_strndup, ( const char *s, size_t n ) );
 VLC_EXPORT( size_t, vlc_strlcpy, ( char *, const char *, size_t ) );
 VLC_EXPORT( double, vlc_atof, ( const char *nptr ) );
 VLC_EXPORT( int64_t, vlc_atoll, ( const char *nptr ) );
 VLC_EXPORT( int64_t, vlc_strtoll, ( const char *nptr, char **endptr, int base ) );
 VLC_EXPORT( size_t, vlc_strnlen, ( const char *, size_t ) );
 
 VLC_EXPORT( size_t, vlc_strlcpy, ( char *, const char *, size_t ) );
 VLC_EXPORT( double, vlc_atof, ( const char *nptr ) );
 VLC_EXPORT( int64_t, vlc_atoll, ( const char *nptr ) );
 VLC_EXPORT( int64_t, vlc_strtoll, ( const char *nptr, char **endptr, int base ) );
 VLC_EXPORT( size_t, vlc_strnlen, ( const char *, size_t ) );
 
-#if defined(SYS_BEOS) \
- || (defined (__FreeBSD__) && (__FreeBSD__ < 5))
-    typedef struct {
-        long long quot; /* Quotient. */
-        long long rem;  /* Remainder. */
-    } lldiv_t;
-#endif
-VLC_EXPORT( lldiv_t, vlc_lldiv, ( long long numer, long long denom ) );
-
 struct dirent;
 VLC_EXPORT( int, vlc_scandir, ( const char *name, struct dirent ***namelist, int (*filter) ( const struct dirent * ), int (*compar) ( const struct dirent **, const struct dirent ** ) ) );
 VLC_EXPORT( int, vlc_alphasort, ( const struct dirent **a, const struct dirent **b ) );
 
 struct dirent;
 VLC_EXPORT( int, vlc_scandir, ( const char *name, struct dirent ***namelist, int (*filter) ( const struct dirent * ), int (*compar) ( const struct dirent **, const struct dirent ** ) ) );
 VLC_EXPORT( int, vlc_alphasort, ( const struct dirent **a, const struct dirent **b ) );
 
-VLC_EXPORT( char *, vlc_getenv, ( const char *name ) );
-
 VLC_EXPORT( int, vlc_strcasecmp, ( const char *s1, const char *s2 ) );
 VLC_EXPORT( int, vlc_strncasecmp, ( const char *s1, const char *s2, size_t n ) );
 VLC_EXPORT( char *, vlc_strcasestr, ( const char *s1, const char *s2 ) );
 VLC_EXPORT( int, vlc_strcasecmp, ( const char *s1, const char *s2 ) );
 VLC_EXPORT( int, vlc_strncasecmp, ( const char *s1, const char *s2, size_t n ) );
 VLC_EXPORT( char *, vlc_strcasestr, ( const char *s1, const char *s2 ) );
index 15d9d637de4f4617866845cbd80c88360511c452..8045ed56b71549b68720113af67510256fe48798 100644 (file)
 #ifndef LIBVLC_FIXUPS_H
 # define LIBVLC_FIXUPS_H 1
 
 #ifndef LIBVLC_FIXUPS_H
 # define LIBVLC_FIXUPS_H 1
 
+# include <string.h>
+# include <stdlib.h>
+
 #ifndef HAVE_STRDUP
 #ifndef HAVE_STRDUP
-# define strdup vlc_strdup
+static inline char *strdup (const char *str)
+{
+    size_t len = strlen (str) + 1;
+    char *res = malloc (len);
+    if (res) memcpy (res, str, len);
+    return res;
+}
 #endif
 
 #ifndef HAVE_VASPRINTF
 #endif
 
 #ifndef HAVE_VASPRINTF
 #endif
 
 #ifndef HAVE_STRNDUP
 #endif
 
 #ifndef HAVE_STRNDUP
-# define strndup vlc_strndup
+static inline char *strndup (const char *str, size_t max)
+{
+    const char *end = memchr (str, '\0', max);
+    size_t len = end ? (size_t)(end - str) : max;
+    char *res = malloc (len + 1);
+    if (res)
+    {
+        memcpy (res, str, len);
+        res[len] = '\0';
+    }
+    return res;
+}
 #endif
 
 #ifndef HAVE_STRNLEN
 #endif
 
 #ifndef HAVE_STRNLEN
 #endif
 
 #ifndef HAVE_LLDIV
 #endif
 
 #ifndef HAVE_LLDIV
-# define lldiv vlc_lldiv
+typedef struct {
+    long long quot; /* Quotient. */
+    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;
+}
 #endif
 
 #ifndef HAVE_SCANDIR
 #endif
 
 #ifndef HAVE_SCANDIR
 #endif
 
 #ifndef HAVE_GETENV
 #endif
 
 #ifndef HAVE_GETENV
-# define getenv vlc_getenv
+static inline getenv (const char *name)
+{
+    (void)name;
+    return NULL;
+}
 #endif
 
 #ifndef HAVE_STRCASECMP
 #endif
 
 #ifndef HAVE_STRCASECMP
index 4e091bc8c815b02d59949f90e5c7f943ce2fee11..e9bb77bfc32a742d3dce328b6b1464a694eec81e 100644 (file)
 #   define strcoll strcmp
 #endif
 
 #   define strcoll strcmp
 #endif
 
-/*****************************************************************************
- * getenv: just in case, but it should never be called
- *****************************************************************************/
-#if !defined( HAVE_GETENV )
-char *vlc_getenv( const char *name )
-{
-    return NULL;
-}
-#endif
-
-/*****************************************************************************
- * strdup: returns a malloc'd copy of a string
- *****************************************************************************/
-#if !defined( HAVE_STRDUP )
-char *vlc_strdup( const char *string )
-{
-    return strndup( string, strlen( string ) );
-}
-#endif
-
-/*****************************************************************************
- * strndup: returns a malloc'd copy of at most n bytes of string
- * Does anyone know whether or not it will be present in Jaguar?
- *****************************************************************************/
-#if !defined( HAVE_STRNDUP )
-char *vlc_strndup( const char *string, size_t n )
-{
-    char *psz;
-    size_t len = strlen( string );
-
-    len = __MIN( len, n );
-    psz = (char*)malloc( len + 1 );
-    if( psz != NULL )
-    {
-        memcpy( (void*)psz, (const void*)string, len );
-        psz[ len ] = 0;
-    }
-
-    return psz;
-}
-#endif
-
 /*****************************************************************************
  * strnlen:
  *****************************************************************************/
 /*****************************************************************************
  * strnlen:
  *****************************************************************************/
@@ -370,20 +328,6 @@ int64_t vlc_atoll( const char *nptr )
 }
 #endif
 
 }
 #endif
 
-/*****************************************************************************
- * lldiv: returns quotient and remainder
- *****************************************************************************/
-#if !defined( HAVE_LLDIV )
-lldiv_t vlc_lldiv( long long numer, long long denom )
-{
-    lldiv_t d;
-    d.quot = numer / denom;
-    d.rem  = numer % denom;
-    return d;
-}
-#endif
-
-
 /**
  * Copy a string to a sized buffer. The result is always nul-terminated
  * (contrary to strncpy()).
 /**
  * Copy a string to a sized buffer. The result is always nul-terminated
  * (contrary to strncpy()).
index 88a80dead5c19b73c807257e49974bcf52fe8849..ca14d71211a4432459e8ec1193f487f1e452cbfb 100644 (file)
@@ -401,7 +401,6 @@ vlc_fastmem_register
 vlc_freeaddrinfo
 vlc_gai_strerror
 vlc_getaddrinfo
 vlc_freeaddrinfo
 vlc_gai_strerror
 vlc_getaddrinfo
-vlc_getenv
 vlc_getnameinfo
 vlc_gettext
 vlc_iconv
 vlc_getnameinfo
 vlc_gettext
 vlc_iconv
@@ -410,7 +409,6 @@ vlc_iconv_open
 __vlc_list_children
 __vlc_list_find
 vlc_list_release
 __vlc_list_children
 __vlc_list_find
 vlc_list_release
-vlc_lldiv
 vlc_memcpy
 vlc_memset
 vlc_module_create
 vlc_memcpy
 vlc_memset
 vlc_module_create
@@ -444,10 +442,8 @@ vlc_sdp_Start
 vlc_sendmsg
 vlc_strcasecmp
 vlc_strcasestr
 vlc_sendmsg
 vlc_strcasecmp
 vlc_strcasestr
-vlc_strdup
 vlc_strlcpy
 vlc_strncasecmp
 vlc_strlcpy
 vlc_strncasecmp
-vlc_strndup
 vlc_strnlen
 vlc_strtoll
 vlc_submodule_create
 vlc_strnlen
 vlc_strtoll
 vlc_submodule_create