From: Rémi Denis-Courmont Date: Sat, 29 Apr 2006 14:30:49 +0000 (+0000) Subject: OpenBSDish strlcpy() X-Git-Tag: 0.9.0-test0~11381 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=83d3320758201fc208b3a0e011af10c5e26bd7fe;p=vlc OpenBSDish strlcpy() --- diff --git a/configure.ac b/configure.ac index 415ad7687c..89af1e26cd 100644 --- a/configure.ac +++ b/configure.ac @@ -404,7 +404,7 @@ CPPFLAGS_save="${CPPFLAGS_save} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcd dnl Check for system libs needed need_libc=false -AC_CHECK_FUNCS(gettimeofday strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch lstat) +AC_CHECK_FUNCS(gettimeofday strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch lstat strlcpy) dnl Check for usual libc functions AC_CHECK_FUNCS(strdup strndup atof) diff --git a/include/vlc_common.h b/include/vlc_common.h index 2a4554a95f..75bafe91ae 100644 --- a/include/vlc_common.h +++ b/include/vlc_common.h @@ -846,6 +846,13 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw ) # define vlc_strndup NULL #endif +#ifndef HAVE_STRLCPY +# define strlcpy vlc_strlcpy + VLC_EXPORT( size_t, vlc_strlcpy, ( char *, const char *, size_t ) ); +#elif !defined(__PLUGIN__) +# define vlc_strlcpy NULL +#endif + #ifndef HAVE_ATOF # define atof vlc_atof VLC_EXPORT( double, vlc_atof, ( const char *nptr ) ); diff --git a/include/vlc_symbols.h b/include/vlc_symbols.h index a9b95722c8..5bff63cbcc 100644 --- a/include/vlc_symbols.h +++ b/include/vlc_symbols.h @@ -491,6 +491,7 @@ struct module_symbols_t char * (*decode_URI_duplicate_inner) (const char *psz); void (*decode_URI_inner) (char *psz); char * (*encode_URI_component_inner) (const char *psz); + size_t (*vlc_strlcpy_inner) (char *, const char *, size_t); }; # if defined (__PLUGIN__) # define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner @@ -962,6 +963,7 @@ struct module_symbols_t # define decode_URI_duplicate (p_symbols)->decode_URI_duplicate_inner # define decode_URI (p_symbols)->decode_URI_inner # define encode_URI_component (p_symbols)->encode_URI_component_inner +# define vlc_strlcpy (p_symbols)->vlc_strlcpy_inner # elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__) /****************************************************************** * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access. @@ -1436,6 +1438,7 @@ struct module_symbols_t ((p_symbols)->decode_URI_duplicate_inner) = decode_URI_duplicate; \ ((p_symbols)->decode_URI_inner) = decode_URI; \ ((p_symbols)->encode_URI_component_inner) = encode_URI_component; \ + ((p_symbols)->vlc_strlcpy_inner) = vlc_strlcpy; \ (p_symbols)->net_ConvertIPv4_deprecated = NULL; \ (p_symbols)->__stats_CounterGet_deprecated = NULL; \ (p_symbols)->__stats_TimerDumpAll_deprecated = NULL; \ diff --git a/modules/access/smb.c b/modules/access/smb.c index 5d889e012f..727fa1343c 100644 --- a/modules/access/smb.c +++ b/modules/access/smb.c @@ -457,18 +457,14 @@ static void Win32AddConnection( access_t *p_access, char *psz_path, net_resource.dwType = RESOURCETYPE_DISK; /* Find out server and share names */ - strncpy( psz_server, psz_path, sizeof( psz_server ) ); - psz_server[sizeof (psz_server) - 1] = '\0'; + strlcpy( psz_server, psz_path, sizeof( psz_server ) ); psz_share[0] = 0; psz_parser = strchr( psz_path, '/' ); if( psz_parser ) { char *psz_parser2 = strchr( ++psz_parser, '/' ); if( psz_parser2 ) - { - strncpy( psz_share, psz_parser, sizeof( psz_share ) ); - psz_parse[sizeof (psz_parse) - 1] = '\0'; - } + strlcpy( psz_share, psz_parser, sizeof( psz_share ) ); } sprintf( psz_remote, "\\\\%s\\%s", psz_server, psz_share ); diff --git a/src/extras/libc.c b/src/extras/libc.c index 6d48b12cad..90604f5689 100644 --- a/src/extras/libc.c +++ b/src/extras/libc.c @@ -1,7 +1,7 @@ /***************************************************************************** * libc.c: Extra libc function for some systems. ***************************************************************************** - * Copyright (C) 2002 the VideoLAN team + * Copyright (C) 2002-2006 the VideoLAN team * $Id$ * * Authors: Jon Lech Johansen @@ -9,6 +9,7 @@ * Gildas Bazin * Derk-Jan Hartman * Christophe Massiot + * 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 @@ -356,6 +357,36 @@ lldiv_t vlc_lldiv( long long numer, long long denom ) } #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) + */ +#ifndef HAVE_STRLCPY +extern size_t vlc_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; +} +#endif + /***************************************************************************** * vlc_*dir_wrapper: wrapper under Windows to return the list of drive letters * when called with an empty argument or just '\'