]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/compat: detect memset_s() using check_function_exists()
authorKefu Chai <kchai@redhat.com>
Mon, 26 Apr 2021 16:00:37 +0000 (00:00 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 2 May 2021 00:16:12 +0000 (08:16 +0800)
more robust this way.

Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/CephChecks.cmake
src/common/compat.cc
src/include/config-h.in.cmake

index 26a5d0bcd7ae32a7a57c48b088d4670922e2a651..376362363f48fc8faecc6f4817def4c5073cbd86 100644 (file)
@@ -9,6 +9,7 @@ include(CheckIncludeFiles)
 include(CheckIncludeFileCXX)
 include(CheckFunctionExists)
 
+check_function_exists(memset_s HAVE_MEMSET_S)
 check_function_exists(fallocate CEPH_HAVE_FALLOCATE)
 check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
 check_function_exists(posix_fallocate HAVE_POSIX_FALLOCATE)
index 3ec0ca2009c73166e1ced045bc7254ab9a7cae57..82b57ad94b538845cde8d45b39f7e9c6dd93d92f 100644 (file)
 #include <fcntl.h>
 #include <stdint.h>
 #include <stdio.h>
+#include "acconfig.h"
+#ifdef HAVE_MEMSET_S
+# define __STDC_WANT_LIB_EXT1__ 1
+#endif
 #include <string.h>
 #include <thread>
 #ifndef _WIN32
@@ -233,7 +237,7 @@ char *ceph_strerror_r(int errnum, char *buf, size_t buflen)
 }
 
 int ceph_memzero_s(void *dest, size_t destsz, size_t count) {
-#ifdef __STDC_LIB_EXT1__
+#ifdef HAVE_MEMSET_S
     return memset_s(dest, destsz, 0, count);
 #elif defined(_WIN32)
     SecureZeroMemory(dest, count);
index be9432db25d48e5f4a2fdb5f6598fce09ab79175..66eecda948b63ac3f3a02f618213354b1943c168 100644 (file)
@@ -3,6 +3,9 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
+/* Define to 1 if you have the `memset_s()` function. */
+#cmakedefine HAVE_MEMSET_S
+
 /* fallocate(2) is supported */
 #cmakedefine CEPH_HAVE_FALLOCATE