]> git.sesse.net Git - vlc/commitdiff
OpenBSDish strlcpy()
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 29 Apr 2006 14:30:49 +0000 (14:30 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 29 Apr 2006 14:30:49 +0000 (14:30 +0000)
configure.ac
include/vlc_common.h
include/vlc_symbols.h
modules/access/smb.c
src/extras/libc.c

index 415ad7687c170908fe889a3786e31ffcb11e0675..89af1e26cd6d2b47ca848dc02bc4dbf5176a92ef 100644 (file)
@@ -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)
index 2a4554a95fc543ab7b7d2fa34c2df05a6acfca55..75bafe91ae12f5bef73bbd560e757bd6a4fc08e8 100644 (file)
@@ -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 ) );
index a9b95722c87197cc919d6417ccc1305f8f00aa8a..5bff63cbcc0e710f3a0844668c81c48873639731 100644 (file)
@@ -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; \
index 5d889e012fb0449befbe7d788f38523ca4126612..727fa1343c135b289debac585cf5a27e598e9584 100644 (file)
@@ -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 );
index 6d48b12cad13b9152b2c48dee6c888e49fde1aba..90604f56898d7bd4036d8218e3eb888cc511b537 100644 (file)
@@ -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 <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 '\'