From: Kefu Chai Date: Mon, 26 Apr 2021 16:00:37 +0000 (+0800) Subject: common/compat: detect memset_s() using check_function_exists() X-Git-Tag: v17.1.0~2082^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fab337c1d033618cd03186070e5ed06b95a1d85a;p=ceph.git common/compat: detect memset_s() using check_function_exists() more robust this way. Signed-off-by: Kefu Chai --- diff --git a/cmake/modules/CephChecks.cmake b/cmake/modules/CephChecks.cmake index 26a5d0bcd7a..376362363f4 100644 --- a/cmake/modules/CephChecks.cmake +++ b/cmake/modules/CephChecks.cmake @@ -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) diff --git a/src/common/compat.cc b/src/common/compat.cc index 3ec0ca2009c..82b57ad94b5 100644 --- a/src/common/compat.cc +++ b/src/common/compat.cc @@ -19,6 +19,10 @@ #include #include #include +#include "acconfig.h" +#ifdef HAVE_MEMSET_S +# define __STDC_WANT_LIB_EXT1__ 1 +#endif #include #include #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); diff --git a/src/include/config-h.in.cmake b/src/include/config-h.in.cmake index be9432db25d..66eecda948b 100644 --- a/src/include/config-h.in.cmake +++ b/src/include/config-h.in.cmake @@ -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