diff --git a/openmp/runtime/src/kmp_os.h b/openmp/runtime/src/kmp_os.h --- a/openmp/runtime/src/kmp_os.h +++ b/openmp/runtime/src/kmp_os.h @@ -1040,6 +1040,9 @@ } // extern "C" #endif // __cplusplus +// Safe C API +#include "kmp_safe_c_api.h" + // Macros for C++11 atomic functions #define KMP_ATOMIC_LD(p, order) (p)->load(std::memory_order_##order) #define KMP_ATOMIC_OP(op, p, v, order) (p)->op(v, std::memory_order_##order) @@ -1090,5 +1093,3 @@ #endif #endif /* KMP_OS_H */ -// Safe C API -#include "kmp_safe_c_api.h" diff --git a/openmp/runtime/src/kmp_safe_c_api.h b/openmp/runtime/src/kmp_safe_c_api.h --- a/openmp/runtime/src/kmp_safe_c_api.h +++ b/openmp/runtime/src/kmp_safe_c_api.h @@ -10,6 +10,7 @@ #ifndef KMP_SAFE_C_API_H #define KMP_SAFE_C_API_H +#include #include "kmp_platform.h" #include @@ -33,7 +34,15 @@ // Use this only when buffer size is unknown #define KMP_MEMCPY(dst, src, cnt) memcpy_s(dst, cnt, src, cnt) -#define KMP_STRLEN(str) strnlen_s(str, RSIZE_MAX_STR) +template ::value> +struct kmp_get_rmax_t {}; +template struct kmp_get_rmax_t { + static const size_t value = RSIZE_MAX_STR; +}; +template struct kmp_get_rmax_t { + static const size_t value = sizeof(T); +}; +#define KMP_STRLEN(str) strnlen_s(str, kmp_get_rmax_t::value) // Use this only when buffer size is unknown #define KMP_STRNCPY(dst, src, cnt) strncpy_s(dst, cnt, src, cnt)