Commit 83d33207 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

OpenBSDish strlcpy()

parent 0a930be2
......@@ -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)
......
......@@ -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 ) );
......
......@@ -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; \
......
......@@ -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 );
......
/*****************************************************************************
* 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 <jon-vl@nanocrew.net>
......@@ -9,6 +9,7 @@
* Gildas Bazin <gbazin@videolan.org>
* Derk-Jan Hartman <hartman at videolan dot org>
* Christophe Massiot <massiot@via.ecp.fr>
* Rémi Denis-Courmont <rem à videolan.org>
*
* 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 '\'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment