Changeset 2b617e77c1f838066916c4a46de7c0e99b38105c

Show
Ignore:
Timestamp:
24/05/08 10:55:05 (5 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1211619305 +0300
git-parent:

[c4e0f18676bfbc37fe1504a719b51204e92de664]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1211619305 +0300
Message:

Inline strdup, strndup, lldiv and getenv

Also fix an overflow in strndup().

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_common.h

    rbb29acd r2b617e7  
    720720 
    721721/* Stuff defined in src/extras/libc.c */ 
    722 VLC_EXPORT( char *, vlc_strdup, ( const char *s ) ); 
    723722VLC_EXPORT( int, vlc_vasprintf, (char **, const char *, va_list ) ); 
    724723VLC_EXPORT( int, vlc_asprintf, (char **, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) ); 
    725 VLC_EXPORT( char *, vlc_strndup, ( const char *s, size_t n ) ); 
    726724VLC_EXPORT( size_t, vlc_strlcpy, ( char *, const char *, size_t ) ); 
    727725VLC_EXPORT( double, vlc_atof, ( const char *nptr ) ); 
     
    730728VLC_EXPORT( size_t, vlc_strnlen, ( const char *, size_t ) ); 
    731729 
    732 #if defined(SYS_BEOS) \ 
    733  || (defined (__FreeBSD__) && (__FreeBSD__ < 5)) 
    734     typedef struct { 
    735         long long quot; /* Quotient. */ 
    736         long long rem;  /* Remainder. */ 
    737     } lldiv_t; 
    738 #endif 
    739 VLC_EXPORT( lldiv_t, vlc_lldiv, ( long long numer, long long denom ) ); 
    740  
    741730struct dirent; 
    742731VLC_EXPORT( int, vlc_scandir, ( const char *name, struct dirent ***namelist, int (*filter) ( const struct dirent * ), int (*compar) ( const struct dirent **, const struct dirent ** ) ) ); 
    743732VLC_EXPORT( int, vlc_alphasort, ( const struct dirent **a, const struct dirent **b ) ); 
    744  
    745 VLC_EXPORT( char *, vlc_getenv, ( const char *name ) ); 
    746733 
    747734VLC_EXPORT( int, vlc_strcasecmp, ( const char *s1, const char *s2 ) ); 
  • include/vlc_fixups.h

    r3f68eb0 r2b617e7  
    2727# define LIBVLC_FIXUPS_H 1 
    2828 
     29# include <string.h> 
     30# include <stdlib.h> 
     31 
    2932#ifndef HAVE_STRDUP 
    30 # define strdup vlc_strdup 
     33static inline char *strdup (const char *str) 
     34
     35    size_t len = strlen (str) + 1; 
     36    char *res = malloc (len); 
     37    if (res) memcpy (res, str, len); 
     38    return res; 
     39
    3140#endif 
    3241 
     
    4049 
    4150#ifndef HAVE_STRNDUP 
    42 # define strndup vlc_strndup 
     51static inline char *strndup (const char *str, size_t max) 
     52
     53    const char *end = memchr (str, '\0', max); 
     54    size_t len = end ? (size_t)(end - str) : max; 
     55    char *res = malloc (len + 1); 
     56    if (res) 
     57    { 
     58        memcpy (res, str, len); 
     59        res[len] = '\0'; 
     60    } 
     61    return res; 
     62
    4363#endif 
    4464 
     
    7090 
    7191#ifndef HAVE_LLDIV 
    72 # define lldiv vlc_lldiv 
     92typedef struct { 
     93    long long quot; /* Quotient. */ 
     94    long long rem;  /* Remainder. */ 
     95} lldiv_t; 
     96 
     97static inline lldiv_t lldiv (long long numer, long long denom) 
     98
     99    lldiv_t d = { .quot = numer / denom, .rem = numer % denom }; 
     100    return d; 
     101
    73102#endif 
    74103 
     
    79108 
    80109#ifndef HAVE_GETENV 
    81 # define getenv vlc_getenv 
     110static inline getenv (const char *name) 
     111
     112    (void)name; 
     113    return NULL; 
     114
    82115#endif 
    83116 
  • src/extras/libc.c

    rff02bf9 r2b617e7  
    7676 
    7777/***************************************************************************** 
    78  * getenv: just in case, but it should never be called 
    79  *****************************************************************************/ 
    80 #if !defined( HAVE_GETENV ) 
    81 char *vlc_getenv( const char *name ) 
    82 { 
    83     return NULL; 
    84 } 
    85 #endif 
    86  
    87 /***************************************************************************** 
    88  * strdup: returns a malloc'd copy of a string 
    89  *****************************************************************************/ 
    90 #if !defined( HAVE_STRDUP ) 
    91 char *vlc_strdup( const char *string ) 
    92 { 
    93     return strndup( string, strlen( string ) ); 
    94 } 
    95 #endif 
    96  
    97 /***************************************************************************** 
    98  * strndup: returns a malloc'd copy of at most n bytes of string 
    99  * Does anyone know whether or not it will be present in Jaguar? 
    100  *****************************************************************************/ 
    101 #if !defined( HAVE_STRNDUP ) 
    102 char *vlc_strndup( const char *string, size_t n ) 
    103 { 
    104     char *psz; 
    105     size_t len = strlen( string ); 
    106  
    107     len = __MIN( len, n ); 
    108     psz = (char*)malloc( len + 1 ); 
    109     if( psz != NULL ) 
    110     { 
    111         memcpy( (void*)psz, (const void*)string, len ); 
    112         psz[ len ] = 0; 
    113     } 
    114  
    115     return psz; 
    116 } 
    117 #endif 
    118  
    119 /***************************************************************************** 
    12078 * strnlen: 
    12179 *****************************************************************************/ 
     
    371329#endif 
    372330 
    373 /***************************************************************************** 
    374  * lldiv: returns quotient and remainder 
    375  *****************************************************************************/ 
    376 #if !defined( HAVE_LLDIV ) 
    377 lldiv_t vlc_lldiv( long long numer, long long denom ) 
    378 { 
    379     lldiv_t d; 
    380     d.quot = numer / denom; 
    381     d.rem  = numer % denom; 
    382     return d; 
    383 } 
    384 #endif 
    385  
    386  
    387331/** 
    388332 * Copy a string to a sized buffer. The result is always nul-terminated 
  • src/libvlccore.sym

    re4c0e92 r2b617e7  
    402402vlc_gai_strerror 
    403403vlc_getaddrinfo 
    404 vlc_getenv 
    405404vlc_getnameinfo 
    406405vlc_gettext 
     
    411410__vlc_list_find 
    412411vlc_list_release 
    413 vlc_lldiv 
    414412vlc_memcpy 
    415413vlc_memset 
     
    445443vlc_strcasecmp 
    446444vlc_strcasestr 
    447 vlc_strdup 
    448445vlc_strlcpy 
    449446vlc_strncasecmp 
    450 vlc_strndup 
    451447vlc_strnlen 
    452448vlc_strtoll