]> The Tcpdump Group git mirrors - libpcap/commitdiff
Have a strlcat() macro for UN*X platforms that lack it.
authorGuy Harris <[email protected]>
Mon, 13 Mar 2017 22:47:56 +0000 (15:47 -0700)
committerGuy Harris <[email protected]>
Mon, 13 Mar 2017 22:47:56 +0000 (15:47 -0700)
config.h.in
configure
configure.ac
portability.h

index fdb32745349b4b7ebf0e28805fc2bdaf90717050..290aba28f1795c2c043a565c99c48f833bf64eb2 100644 (file)
 /* Define to 1 if you have the <string.h> header file. */
 #undef HAVE_STRING_H
 
 /* Define to 1 if you have the <string.h> header file. */
 #undef HAVE_STRING_H
 
+/* Define to 1 if you have the `strlcat' function. */
+#undef HAVE_STRLCAT
+
 /* Define to 1 if you have the `strlcpy' function. */
 #undef HAVE_STRLCPY
 
 /* Define to 1 if you have the `strlcpy' function. */
 #undef HAVE_STRLCPY
 
index b1f360308f4389caae1b9ce028d83c07dfd5a665..b04cec7dcbedfc33b76fe359503500959f9be075 100755 (executable)
--- a/configure
+++ b/configure
@@ -4937,7 +4937,7 @@ $as_echo "$ac_cv_lbl_gcc_fixincludes" >&6; }
            fi
     fi
 
            fi
     fi
 
-for ac_func in strerror strlcpy
+for ac_func in strerror strlcpy strlcat
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
index c48c07fa5c21ae43c5f67715a316d6c092e8f641..1d098799c89b376d6ea7b3708e95853a3db0e700 100644 (file)
@@ -160,7 +160,7 @@ esac
 
 AC_LBL_FIXINCLUDES
 
 
 AC_LBL_FIXINCLUDES
 
-AC_CHECK_FUNCS(strerror strlcpy)
+AC_CHECK_FUNCS(strerror strlcpy strlcat)
 
 needsnprintf=no
 AC_CHECK_FUNCS(vsnprintf snprintf,,
 
 needsnprintf=no
 AC_CHECK_FUNCS(vsnprintf snprintf,,
index 8a6bf40e8bb4c5ef8c1cc9563edf1a88fef45810..117fe4dd41e53028c28b32e53c3a3f146c006df0 100644 (file)
@@ -47,7 +47,7 @@ extern "C" {
  /*
   * Macro that does the same thing as strlcpy().
   */
  /*
   * Macro that does the same thing as strlcpy().
   */
- #ifdef _MSC_VER
+ #if defined(_MSC_VER) || defined(__MINGW32__)
   /*
    * strncpy_s() is supported at least back to Visual
    * Studio 2005.
   /*
    * strncpy_s() is supported at least back to Visual
    * Studio 2005.
@@ -63,6 +63,28 @@ extern "C" {
  #endif
 #endif
 
  #endif
 #endif
 
+#ifndef HAVE_STRLCAT
+ /*
+  * Macro that does the same thing as strlcat().
+  */
+ #if defined(_MSC_VER) || defined(__MINGW32__)
+  /*
+   * strncat_s() is supported at least back to Visual
+   * Studio 2005.
+   */
+  #define strlcat(x, y, z) \
+       strncat_s((x), (z), (y), _TRUNCATE)
+ #else
+  /*
+   * ANSI C says strncat() always null-terminates its first argument,
+   * so 1) we don't need to explicitly null-terminate the string
+   * ourselves and 2) we need to leave room for the null terminator.
+   */
+  #define strlcat(x, y, z) \
+       strncat((x), (y), (z) - strlen((x)) - 1)
+ #endif
+#endif
+
 /*
  * For flagging arguments as format strings in MSVC.
  */
 /*
  * For flagging arguments as format strings in MSVC.
  */
@@ -87,11 +109,6 @@ extern "C" {
   FILE *fopen_safe(const char *filename, const char* mode);
 #endif
 
   FILE *fopen_safe(const char *filename, const char* mode);
 #endif
 
-#if defined(_MSC_VER) || defined(__MINGW32__)
-  #define strlcat(x, y, z) \
-       strncat_s((x), (z), (y), _TRUNCATE)
-#endif
-
 #ifdef _MSC_VER
   /*
    * MSVC.
 #ifdef _MSC_VER
   /*
    * MSVC.