]> Savannah Git Hosting - gnulib.git/commitdiff
explicit_bzero: Use memset_s() when available.
authorBastien Roucariès <rouca@debian.org>
Sun, 12 Apr 2020 23:09:14 +0000 (01:09 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 13 Apr 2020 22:05:09 +0000 (00:05 +0200)
Some OS define memset_s instead of explicit_bzero. Use it.

* lib/explicit_bzero.c (__STDC_WANT_LIB_EXT1__): Define.
(explicit_bzero): Use memset_s when available.
* m4/explicit_bzero.m4 (gl_PREREQ_EXPLICIT_BZERO): Test for memset_s.

Signed-off-by: Bastien Roucariès <rouca@debian.org>
ChangeLog
lib/explicit_bzero.c
m4/explicit_bzero.m4

index 90fb56312355ceede1ee2fc44677b6f9214d839a..8bb1465d828819dfa8c06aa094d265460e93c749 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-04-13  Bastien Roucariès  <rouca@debian.org>
+
+       explicit_bzero: Use memset_s() when available.
+       * lib/explicit_bzero.c (__STDC_WANT_LIB_EXT1__): Define.
+       (explicit_bzero): Use memset_s when available.
+       * m4/explicit_bzero.m4 (gl_PREREQ_EXPLICIT_BZERO): Test for memset_s.
+
 2020-04-13  Bastien Roucariès  <rouca@debian.org>
 
        explicit_bzero tests: Fix test failure on OpenBSD 6.5.
index 51b79a891825eda728414cff7156fa9c95362e71..2168a52854f18db7e3945cce6746e4d20c194e05 100644 (file)
 # include <config.h>
 #endif
 
+/* memset_s need this define */
+#if HAVE_MEMSET_S
+# define __STDC_WANT_LIB_EXT1__ 1
+#endif
+
 #include <string.h>
 
 #if _LIBC
@@ -40,6 +45,8 @@ explicit_bzero (void *s, size_t len)
 {
 #ifdef HAVE_EXPLICIT_MEMSET
   explicit_memset (s, 0, len);
+#elif HAVE_MEMSET_S
+  (void) memset_s (s, len, '\0', len);
 #else
   memset (s, '\0', len);
 # if defined __GNUC__ && !defined __clang__
index 507816affdbcfc1e3a6f8882df09518dab4a0d03..a415e7b4f5edfc51918c295c15e41178ba66344d 100644 (file)
@@ -19,4 +19,5 @@ AC_DEFUN([gl_FUNC_EXPLICIT_BZERO],
 AC_DEFUN([gl_PREREQ_EXPLICIT_BZERO],
 [
   AC_CHECK_FUNCS([explicit_memset])
+  AC_CHECK_FUNCS_ONCE([memset_s])
 ])