From 4ddfc64d2346887dfd3a38433b3d714e19c08f07 Mon Sep 17 00:00:00 2001 From: jackieathome Date: Tue, 11 Jan 2022 23:46:36 +0800 Subject: [PATCH] Using cmake to build libboundscheck. Signed-off-by: jackieathome --- CMakeLists.txt | 363 ++++++++++++++++++++++++++++++++++++++ Makefile | 1 + boundscheck_config.h.in | 284 +++++++++++++++++++++++++++++ include/securec.h | 37 ++-- src/fscanf_s.c | 2 + src/fwscanf_s.c | 4 + src/gets_s.c | 2 + src/memcpy_s.c | 2 + src/memmove_s.c | 2 + src/memset_s.c | 2 + src/scanf_s.c | 2 + src/secureinput_w.c | 3 + src/secureprintoutput_w.c | 3 + src/snprintf_s.c | 2 + src/sprintf_s.c | 2 + src/sscanf_s.c | 2 + src/strcat_s.c | 2 + src/strcpy_s.c | 2 + src/strncat_s.c | 2 + src/strncpy_s.c | 2 + src/strtok_s.c | 2 + src/swprintf_s.c | 4 + src/swscanf_s.c | 4 + src/vfscanf_s.c | 2 + src/vfwscanf_s.c | 4 + src/vscanf_s.c | 2 + src/vsprintf_s.c | 2 + src/vsscanf_s.c | 2 + src/vswprintf_s.c | 5 + src/vswscanf_s.c | 4 + src/vwscanf_s.c | 4 + src/wcscat_s.c | 4 + src/wcscpy_s.c | 4 + src/wcsncat_s.c | 4 + src/wcsncpy_s.c | 4 + src/wcstok_s.c | 4 + src/wmemcpy_s.c | 4 + src/wmemmove_s.c | 4 + src/wscanf_s.c | 4 + 39 files changed, 773 insertions(+), 15 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 boundscheck_config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..198c71e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,363 @@ +# +# Licensed under Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v2 for more details. +# Create: 2022-01-10 +# +CMAKE_MINIMUM_REQUIRED(VERSION 3.0) + +PROJECT(boundscheck) +SET(CMAKE_CXX_COMPILER_WORKS 1) + +SET(SECUREC_VERSION_MAJOR 1) +SET(SECUREC_VERSION_MINOR 11) + +MESSAGE(STATUS "SYSTEM :${CMAKE_SYSTEM_NAME}") +MESSAGE(STATUS "CXX Compiler :${CMAKE_CXX_COMPILER_ID}") +MESSAGE(STATUS "C Compiler :${CMAKE_C_COMPILER_ID}") +MESSAGE(STATUS "CMAKE_SYSTEM_VERSION :${CMAKE_SYSTEM_VERSION}") +MESSAGE(STATUS "CMAKE_SYSTEM_NAME :${CMAKE_SYSTEM_NAME}") +MESSAGE(STATUS "CMAKE_SYSTEM :${CMAKE_SYSTEM}") +MESSAGE(STATUS "CMAKE_HOST_SYSTEM_NAME :${CMAKE_HOST_SYSTEM_NAME}") +MESSAGE(STATUS "CMAKE_HOST_SYSTEM :${CMAKE_HOST_SYSTEM}") +MESSAGE(STATUS "LINUX :${LINUX}") +MESSAGE(STATUS "UNIX :${UNIX}") +MESSAGE(STATUS "MINGW :${MINGW}") +MESSAGE(STATUS "MSVC :${MSVC}") +MESSAGE(STATUS "WIN32 :${WIN32}") + +IF (CMAKE_SYSTEM_NAME MATCHES "Windows") + IF (MSVC) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /GS") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /sdl") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /nologo") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zc:wchar_t") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zc:strictStrings") + + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} /Zc:inline") + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2") + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD") + + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Od") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /RTCsu") + #SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /fsanitize=address") + + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NXCOMPAT") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DYNAMICBASE") + #SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /HIGHENTROPYVA") + + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zi") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:REF") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:ICF") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NOLOGO") + + SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /INCREMENTAL:NO") + SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO") + ELSE () + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpie") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2 -O2") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") + + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2 -Wfloat-equal -Wshadow") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-security") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --param ssp-buffer-size=4") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Warray-bounds") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-overflow=1") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-aliasing=2") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wswitch -Wswitch-default") + + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s") + + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ftrapv") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fstack-check") + + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fvisibility=hidden") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fvisibility-inlines-hidden") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pie") + #SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro,-z,now") + #SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") + ENDIF () +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "MSYS") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpie") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2 -O2") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") + + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2 -Wfloat-equal -Wshadow") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-security") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --param ssp-buffer-size=4") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Warray-bounds") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-overflow=1") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-aliasing=2") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wswitch -Wswitch-default") + + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s") + + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ftrapv") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fstack-check") + + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fvisibility=hidden") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fvisibility-inlines-hidden") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pie") + #SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro,-z,now") + #SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") +ELSE () + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpie") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2 -O2") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") + + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2 -Wfloat-equal -Wshadow") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-security") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --param ssp-buffer-size=4") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Warray-bounds") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-overflow=1") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-aliasing=2") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wswitch -Wswitch-default") + + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s") + + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ftrapv") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fstack-check") + + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fvisibility=hidden") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fvisibility-inlines-hidden") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pie") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro,-z,now") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") +ENDIF () + +INCLUDE(CheckIncludeFile) +check_include_file(errno.h SECUREC_HAVE_ERRNO_H) +check_include_file(memory.h SECUREC_HAVE_MEMORY_H) +check_include_file(stdarg.h SECUREC_HAVE_STDARG_H) +check_include_file(stddef.h SECUREC_HAVE_STDDEF_H) +check_include_file(stdio.h SECUREC_HAVE_STDIO_H) +check_include_file(stdlib.h SECUREC_HAVE_STDLIB_H) +check_include_file(string.h SECUREC_HAVE_STRING_H) +check_include_file(wchar.h SECUREC_HAVE_WCHAR_H) +check_include_file(ctype.h SECUREC_HAVE_CTYPES_H) +check_include_file(wctype.h SECUREC_HAVE_WCTYPES_H) + +INCLUDE(CheckFunctionExists) +check_function_exists(memset_s SECUREC_HAVE_MEMSET) +check_function_exists(memmove_s SECUREC_HAVE_MEMMOVE) +check_function_exists(memcpy_s SECUREC_HAVE_MEMCPY) +check_function_exists(strcpy_s SECUREC_HAVE_STRCPY) +check_function_exists(strncpy_s SECUREC_HAVE_STRNCPY) +check_function_exists(strcat_s SECUREC_HAVE_STRCAT) +check_function_exists(strncat_s SECUREC_HAVE_STRNCAT) +check_function_exists(sprintf_s SECUREC_HAVE_SPRINTF) +check_function_exists(snprintf_s SECUREC_HAVE_SNPRINTF) +check_function_exists(strtok_s SECUREC_HAVE_STRTOK) +check_function_exists(gets_s SECUREC_HAVE_GETS) +check_function_exists(wmemmove_s SECUREC_HAVE_MEMMOVE_W) +check_function_exists(wmemcpy_s SECUREC_HAVE_MEMCPY_W) +check_function_exists(wcscpy_s SECUREC_HAVE_STRCPY_W) +check_function_exists(wcsncpy_s SECUREC_HAVE_STRNCPY_W) +check_function_exists(wcscat_s SECUREC_HAVE_STRCAT_W) +check_function_exists(wcsncat_s SECUREC_HAVE_STRNCAT_W) +check_function_exists(wcstok_s SECUREC_HAVE_STRTOK_W) + +INCLUDE(CheckSymbolExists) +IF (MSVC) + + IF (MSVC_VERSION GREATER_EQUAL 1910) + check_symbol_exists(scanf_s "stdio.h" SECUREC_HAVE_SCANF) + check_symbol_exists(vscanf_s "stdio.h" SECUREC_HAVE_VSCANF) + check_symbol_exists(vsprintf_s "stdio.h" SECUREC_HAVE_VSPRINTF) + check_symbol_exists(vsnprintf_s "stdio.h" SECUREC_HAVE_VSNPRINTF) + check_symbol_exists(sscanf_s "stdio.h" SECUREC_HAVE_SSCANF) + check_symbol_exists(vsscanf_s "stdio.h" SECUREC_HAVE_VSSCANF) + check_symbol_exists(fscanf_s "stdio.h" SECUREC_HAVE_FSCANF) + check_symbol_exists(vfscanf_s "stdio.h" SECUREC_HAVE_VFSCANF) + check_symbol_exists(vswprintf_s "stdio.h" SECUREC_HAVE_VSPRINTF_W) + check_symbol_exists(swprintf_s "stdio.h" SECUREC_HAVE_SPRINTF_W) + check_symbol_exists(wscanf_s "stdio.h" SECUREC_HAVE_SCANF_W) + check_symbol_exists(vwscanf_s "stdio.h" SECUREC_HAVE_VSCANF_W) + check_symbol_exists(swscanf_s "stdio.h" SECUREC_HAVE_SSCANF_W) + check_symbol_exists(vswscanf_s "stdio.h" SECUREC_HAVE_VSSCANF_W) + check_symbol_exists(vsprintf_s "stdio.h" SECUREC_HAVE_FSCANF_W) + check_symbol_exists(vfwscanf_s "stdio.h" SECUREC_HAVE_VFSCANF_W) + check_symbol_exists(_snprintf_s "stdio.h" SECUREC_HAVE_SNPRINTF_WIN32) + ELSE () + check_function_exists(scanf_s SECUREC_HAVE_SCANF) + check_function_exists(vscanf_s SECUREC_HAVE_VSCANF) + check_function_exists(vsprintf_s SECUREC_HAVE_VSPRINTF) + check_function_exists(vsnprintf_s SECUREC_HAVE_VSNPRINTF) + check_function_exists(sscanf_s SECUREC_HAVE_SSCANF) + check_function_exists(vsscanf_s SECUREC_HAVE_VSSCANF) + check_function_exists(fscanf_s SECUREC_HAVE_FSCANF) + check_function_exists(vfscanf_s SECUREC_HAVE_VFSCANF) + check_function_exists(vswprintf_s SECUREC_HAVE_VSPRINTF_W) + check_function_exists(swprintf_s SECUREC_HAVE_SPRINTF_W) + check_function_exists(wscanf_s SECUREC_HAVE_SCANF_W) + check_function_exists(vwscanf_s SECUREC_HAVE_VSCANF_W) + check_function_exists(swscanf_s SECUREC_HAVE_SSCANF_W) + check_function_exists(vswscanf_s SECUREC_HAVE_VSSCANF_W) + check_function_exists(fwscanf_s SECUREC_HAVE_FSCANF_W) + check_function_exists(vfwscanf_s SECUREC_HAVE_VFSCANF_W) + check_function_exists(_snprintf_s SECUREC_HAVE_SNPRINTF_WIN32) + ENDIF () +ELSE () + check_function_exists(scanf_s SECUREC_HAVE_SCANF) + check_function_exists(vscanf_s SECUREC_HAVE_VSCANF) + check_function_exists(vsprintf_s SECUREC_HAVE_VSPRINTF) + check_function_exists(vsnprintf_s SECUREC_HAVE_VSNPRINTF) + check_function_exists(sscanf_s SECUREC_HAVE_SSCANF) + check_function_exists(vsscanf_s SECUREC_HAVE_VSSCANF) + check_function_exists(fscanf_s SECUREC_HAVE_FSCANF) + check_function_exists(vfscanf_s SECUREC_HAVE_VFSCANF) + check_function_exists(vswprintf_s SECUREC_HAVE_VSPRINTF_W) + check_function_exists(swprintf_s SECUREC_HAVE_SPRINTF_W) + check_function_exists(wscanf_s SECUREC_HAVE_SCANF_W) + check_function_exists(vwscanf_s SECUREC_HAVE_VSCANF_W) + check_function_exists(swscanf_s SECUREC_HAVE_SSCANF_W) + check_function_exists(vswscanf_s SECUREC_HAVE_VSSCANF_W) + check_function_exists(fwscanf_s SECUREC_HAVE_FSCANF_W) + check_function_exists(vfwscanf_s SECUREC_HAVE_VFSCANF_W) +ENDIF () + +INCLUDE(CheckCXXSourceRuns) +CHECK_CXX_SOURCE_RUNS( + "#include + #include + #include + #include + + int main() + { + wchar_t wcs[80]; + wcscpy(wcs, L\"we \"); + wcscat(wcs, L\"are \"); + wcscat(wcs, L\"wchar_t \"); + wcscat(wcs, L\"string.\"); + wprintf(L\"%ls\", wcs); + + return 0; + }" SECUREC_HAVE_WCHAR_T_RUN) + +IF (${SECUREC_HAVE_WCHAR_T_RUN}) + SET(SECUREC_HAVE_WCHAR_T 1) +ELSE () + SET(SECUREC_HAVE_WCHAR_T 0) +ENDIF () + +CONFIGURE_FILE( + "${PROJECT_SOURCE_DIR}/boundscheck_config.h.in" + "${PROJECT_BINARY_DIR}/boundscheck_config.h" +) + +SET(SRC_INCS + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_BINARY_DIR} +) + +SET(SRC_FILES + src/securecutil.c + src/secureinput_a.c + src/secureinput_w.c + src/secureprintoutput_a.c + src/secureprintoutput_w.c + src/snprintf_s.c + src/vsnprintf_s.c + src/fscanf_s.c + src/fwscanf_s.c + src/gets_s.c + src/memcpy_s.c + src/memmove_s.c + src/memset_s.c + src/scanf_s.c + src/sprintf_s.c + src/sscanf_s.c + src/strcat_s.c + src/strcpy_s.c + src/strncat_s.c + src/strncpy_s.c + src/strtok_s.c + src/swprintf_s.c + src/swscanf_s.c + src/vfwscanf_s.c + src/vsprintf_s.c + src/vsscanf_s.c + src/vswprintf_s.c + src/vswscanf_s.c + src/vwscanf_s.c + src/wcscat_s.c + src/wcscpy_s.c + src/wcsncat_s.c + src/wcsncpy_s.c + src/wcstok_s.c + src/wscanf_s.c + src/wmemcpy_s.c + src/wmemmove_s.c + src/vfscanf_s.c + src/vscanf_s.c +) + +ADD_LIBRARY(boundscheck SHARED ${SRC_FILES}) +TARGET_INCLUDE_DIRECTORIES(boundscheck PUBLIC ${SRC_INCS}) +SET_TARGET_PROPERTIES (boundscheck PROPERTIES CLEAN_DIRECT_OUTPUT 1) +SET_TARGET_PROPERTIES(boundscheck PROPERTIES + VERSION 1.11 + SOVERSION 1 +) + +ADD_LIBRARY(boundscheck_static STATIC ${SRC_FILES}) +TARGET_INCLUDE_DIRECTORIES(boundscheck_static PUBLIC ${SRC_INCS}) +SET_TARGET_PROPERTIES(boundscheck_static PROPERTIES OUTPUT_NAME "boundscheck_s") +SET_TARGET_PROPERTIES(boundscheck_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) + + +#INSTALL(FILES $ DESTINATION ${CMAKE_SYSTEM_NAME}/X64/$<$:Debug>$<$:Release> OPTIONAL) +INSTALL(TARGETS boundscheck boundscheck_static LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +INSTALL(FILES + ${PROJECT_SOURCE_DIR}/include/securec.h + ${PROJECT_SOURCE_DIR}/include/securectype.h + ${PROJECT_BINARY_DIR}/boundscheck_config.h + DESTINATION include/boundscheck +) diff --git a/Makefile b/Makefile index bdeee08..1db67d5 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ OPTION += -Wmissing-prototypes OPTION += -Wstrict-overflow=1 OPTION += -Wstrict-aliasing=2 OPTION += -Wswitch -Wswitch-default +OPTION += -DHAVE_CONFIG_H=0 CFLAG = -Wall -DNDEBUG -O2 $(OPTION) diff --git a/boundscheck_config.h.in b/boundscheck_config.h.in new file mode 100644 index 0000000..660c0f7 --- /dev/null +++ b/boundscheck_config.h.in @@ -0,0 +1,284 @@ +/* + * Licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * Create: 2022-01-10 + */ + +#pragma once +#ifndef __SECUREC_CONFIG_H__ +#define __SECUREC_CONFIG_H__ + +#define SECUREC_VERSION_MAJOR @SECUREC_VERSION_MAJOR@ +#define SECUREC_VERSION_MINOR @SECUREC_VERSION_MINOR@ + +#cmakedefine SECUREC_HAVE_MEMORY_H @SECUREC_HAVE_MEMORY_H@ +#cmakedefine SECUREC_HAVE_ERRNO_H @SECUREC_HAVE_ERRNO_H@ +#cmakedefine SECUREC_HAVE_STDARG_H @SECUREC_HAVE_STDARG_H@ +#cmakedefine SECUREC_HAVE_STDDEF_H @SECUREC_HAVE_STDDEF_H@ +#cmakedefine SECUREC_HAVE_STDIO_H @SECUREC_HAVE_STDIO_H@ +#cmakedefine SECUREC_HAVE_STDLIB_H @SECUREC_HAVE_STDLIB_H@ +#cmakedefine SECUREC_HAVE_STRING_H @SECUREC_HAVE_STRING_H@ +#cmakedefine SECUREC_HAVE_CTYPES_H @SECUREC_HAVE_CTYPES_H@ +#cmakedefine SECUREC_HAVE_WCTYPES_H @SECUREC_HAVE_WCTYPES_H@ + +#cmakedefine SECUREC_HAVE_MEMSET @SECUREC_HAVE_MEMSET@ +#ifndef SECUREC_HAVE_MEMSET +#define SECUREC_ENABLE_MEMSET 1 +#else +#define SECUREC_ENABLE_MEMSET 0 +#endif + +#cmakedefine SECUREC_HAVE_MEMMOVE @SECUREC_HAVE_MEMMOVE@ +#ifndef SECUREC_HAVE_MEMMOVE +#define SECUREC_ENABLE_MEMMOVE 1 +#else +#define SECUREC_ENABLE_MEMMOVE 0 +#endif + +#cmakedefine SECUREC_HAVE_MEMCPY @SECUREC_HAVE_MEMCPY@ +#ifndef SECUREC_HAVE_MEMCPY +#define SECUREC_ENABLE_MEMCPY 1 +#else +#define SECUREC_ENABLE_MEMCPY 0 +#endif + +#cmakedefine SECUREC_HAVE_STRCPY @SECUREC_HAVE_STRCPY@ +#ifndef SECUREC_HAVE_STRCPY +#define SECUREC_ENABLE_STRCPY 1 +#else +#define SECUREC_ENABLE_STRCPY 0 +#endif + +#cmakedefine SECUREC_HAVE_STRNCPY @SECUREC_HAVE_STRNCPY@ +#ifndef SECUREC_HAVE_STRNCPY +#define SECUREC_ENABLE_STRNCPY 1 +#else +#define SECUREC_ENABLE_STRNCPY 0 +#endif + +#cmakedefine SECUREC_HAVE_STRCAT @SECUREC_HAVE_STRCAT@ +#ifndef SECUREC_HAVE_STRCAT +#define SECUREC_ENABLE_STRCAT 1 +#else +#define SECUREC_ENABLE_STRCAT 0 +#endif + +#cmakedefine SECUREC_HAVE_STRNCAT @SECUREC_HAVE_STRNCAT@ +#ifndef SECUREC_HAVE_STRNCAT +#define SECUREC_ENABLE_STRNCAT 1 +#else +#define SECUREC_ENABLE_STRNCAT 0 +#endif + +#cmakedefine SECUREC_HAVE_VSPRINTF @SECUREC_HAVE_VSPRINTF@ +#ifndef SECUREC_HAVE_VSPRINTF +#define SECUREC_ENABLE_VSPRINTF 1 +#else +#define SECUREC_ENABLE_VSPRINTF 0 +#endif + +#cmakedefine SECUREC_HAVE_SPRINTF @SECUREC_HAVE_SPRINTF@ +#ifndef SECUREC_HAVE_SPRINTF +#define SECUREC_ENABLE_SPRINTF 1 +#else +#define SECUREC_ENABLE_SPRINTF 0 +#endif + +#cmakedefine SECUREC_HAVE_VSNPRINTF @SECUREC_HAVE_VSNPRINTF@ +#ifndef SECUREC_HAVE_VSNPRINTF +#define SECUREC_ENABLE_VSNPRINTF 1 +#else +#define SECUREC_ENABLE_VSNPRINTF 0 +#endif + + + +#cmakedefine SECUREC_HAVE_SNPRINTF @SECUREC_HAVE_SNPRINTF@ +#ifndef SECUREC_HAVE_SNPRINTF +#define SECUREC_ENABLE_SNPRINTF 1 +#else +#define SECUREC_ENABLE_SNPRINTF 0 +#endif + +#cmakedefine SECUREC_HAVE_SNPRINTF_WIN32 @SECUREC_HAVE_SNPRINTF_WIN32@ +#ifndef SECUREC_HAVE_SNPRINTF_WIN32 +#define SECUREC_ENABLE_SNPRINTF_WIN32 1 +#else +#define SECUREC_ENABLE_SNPRINTF_WIN32 0 +#endif + +#cmakedefine SECUREC_HAVE_SCANF @SECUREC_HAVE_SCANF@ +#ifndef SECUREC_HAVE_SCANF +#define SECUREC_ENABLE_SCANF 1 +#else +#define SECUREC_ENABLE_SCANF 0 +#endif + +#cmakedefine SECUREC_HAVE_VSCANF @SECUREC_HAVE_VSCANF@ +#ifndef SECUREC_HAVE_VSCANF +#define SECUREC_ENABLE_VSCANF 1 +#else +#define SECUREC_ENABLE_VSCANF 0 +#endif + +#cmakedefine SECUREC_HAVE_SSCANF @SECUREC_HAVE_SSCANF@ +#ifndef SECUREC_HAVE_SSCANF +#define SECUREC_ENABLE_SSCANF 1 +#else +#define SECUREC_ENABLE_SSCANF 0 +#endif + +#cmakedefine SECUREC_HAVE_VSSCANF @SECUREC_HAVE_VSSCANF@ +#ifndef SECUREC_HAVE_VSSCANF +#define SECUREC_ENABLE_VSSCANF 1 +#else +#define SECUREC_ENABLE_VSSCANF 0 +#endif + +#cmakedefine SECUREC_HAVE_FSCANF @SECUREC_HAVE_FSCANF@ +#ifndef SECUREC_HAVE_FSCANF +#define SECUREC_ENABLE_FSCANF 1 +#else +#define SECUREC_ENABLE_FSCANF 0 +#endif + +#cmakedefine SECUREC_HAVE_VFSCANF @SECUREC_HAVE_VFSCANF@ +#ifndef SECUREC_HAVE_VFSCANF +#define SECUREC_ENABLE_VFSCANF 1 +#else +#define SECUREC_ENABLE_VFSCANF 0 +#endif + +#cmakedefine SECUREC_HAVE_STRTOK @SECUREC_HAVE_STRTOK@ +#ifndef SECUREC_HAVE_STRTOK +#define SECUREC_ENABLE_STRTOK 1 +#else +#define SECUREC_ENABLE_STRTOK 0 +#endif + +#cmakedefine SECUREC_HAVE_GETS @SECUREC_HAVE_GETS@ +#ifndef SECUREC_HAVE_GETS +#define SECUREC_ENABLE_GETS 1 +#else +#define SECUREC_ENABLE_GETS 0 +#endif + +#cmakedefine SECUREC_HAVE_WCHAR_T @SECUREC_HAVE_WCHAR_T@ +#ifndef SECUREC_HAVE_WCHAR_T +#define SECUREC_ENABLE_WCHAR_FUNC 0 +#else +#define SECUREC_ENABLE_WCHAR_FUNC 1 +#endif + +#cmakedefine SECUREC_HAVE_MEMMOVE_W @SECUREC_HAVE_MEMMOVE_W@ +#ifndef SECUREC_HAVE_MEMMOVE_W +#define SECUREC_ENABLE_MEMMOVE_W 1 +#else +#define SECUREC_ENABLE_MEMMOVE_W 0 +#endif + +#cmakedefine SECUREC_HAVE_MEMCPY_W @SECUREC_HAVE_MEMCPY_W@ +#ifndef SECUREC_HAVE_MEMCPY_W +#define SECUREC_ENABLE_MEMCPY_W 1 +#else +#define SECUREC_ENABLE_MEMCPY_W 0 +#endif + +#cmakedefine SECUREC_HAVE_STRCPY_W @SECUREC_HAVE_STRCPY_W@ +#ifndef SECUREC_HAVE_STRCPY_W +#define SECUREC_ENABLE_STRCPY_W 1 +#else +#define SECUREC_ENABLE_STRCPY_W 0 +#endif + +#cmakedefine SECUREC_HAVE_STRNCPY_W @SECUREC_HAVE_STRNCPY_W@ +#ifndef SECUREC_HAVE_STRNCPY_W +#define SECUREC_ENABLE_STRNCPY_W 1 +#else +#define SECUREC_ENABLE_STRNCPY_W 0 +#endif + +#cmakedefine SECUREC_HAVE_STRCAT_W @SECUREC_HAVE_STRCAT_W@ +#ifndef SECUREC_HAVE_STRCAT_W +#define SECUREC_ENABLE_STRCAT_W 1 +#else +#define SECUREC_ENABLE_STRCAT_W 0 +#endif + +#cmakedefine SECUREC_HAVE_STRNCAT_W @SECUREC_HAVE_STRNCAT_W@ +#ifndef SECUREC_HAVE_STRNCAT_W +#define SECUREC_ENABLE_STRNCAT_W 1 +#else +#define SECUREC_ENABLE_STRNCAT_W 0 +#endif + +#cmakedefine SECUREC_HAVE_VSPRINTF_W @SECUREC_HAVE_VSPRINTF_W@ +#ifndef SECUREC_HAVE_VSPRINTF_W +#define SECUREC_ENABLE_VSPRINTF_W 1 +#else +#define SECUREC_ENABLE_VSPRINTF_W 0 +#endif + +#cmakedefine SECUREC_HAVE_SPRINTF_W @SECUREC_HAVE_SPRINTF_W@ +#ifndef SECUREC_HAVE_SPRINTF_W +#define SECUREC_ENABLE_SPRINTF_W 1 +#else +#define SECUREC_ENABLE_SPRINTF_W 0 +#endif + +#cmakedefine SECUREC_HAVE_SCANF_W @SECUREC_HAVE_SCANF_W@ +#ifndef SECUREC_HAVE_SCANF_W +#define SECUREC_ENABLE_SCANF_W 1 +#else +#define SECUREC_ENABLE_SCANF_W 0 +#endif + +#cmakedefine SECUREC_HAVE_VSCANF_W @SECUREC_HAVE_VSCANF_W@ +#ifndef SECUREC_HAVE_VSCANF_W +#define SECUREC_ENABLE_VSCANF_W 1 +#else +#define SECUREC_ENABLE_VSCANF_W 0 +#endif + +#cmakedefine SECUREC_HAVE_SSCANF_W @SECUREC_HAVE_SSCANF_W@ +#ifndef SECUREC_HAVE_SSCANF_W +#define SECUREC_ENABLE_SSCANF_W 1 +#else +#define SECUREC_ENABLE_SSCANF_W 0 +#endif + +#cmakedefine SECUREC_HAVE_VSSCANF_W @SECUREC_HAVE_VSSCANF_W@ +#ifndef SECUREC_HAVE_VSSCANF_W +#define SECUREC_ENABLE_VSSCANF_W 1 +#else +#define SECUREC_ENABLE_VSSCANF_W 0 +#endif + +#cmakedefine SECUREC_HAVE_FSCANF_W @SECUREC_HAVE_FSCANF_W@ +#ifndef SECUREC_HAVE_FSCANF_W +#define SECUREC_ENABLE_FSCANF_W 1 +#else +#define SECUREC_ENABLE_FSCANF_W 0 +#endif + +#cmakedefine SECUREC_HAVE_VFSCANF_W @SECUREC_HAVE_VFSCANF_W@ +#ifndef SECUREC_HAVE_VFSCANF_W +#define SECUREC_ENABLE_VFSCANF_W 1 +#else +#define SECUREC_ENABLE_VFSCANF_W 0 +#endif + +#cmakedefine SECUREC_HAVE_STRTOK_W @SECUREC_HAVE_STRTOK_W@ +#ifndef SECUREC_HAVE_STRTOK_W +#define SECUREC_ENABLE_STRTOK_W 1 +#else +#define SECUREC_ENABLE_STRTOK_W 0 +#endif + +#endif diff --git a/include/securec.h b/include/securec.h index d933056..1fb8c9b 100644 --- a/include/securec.h +++ b/include/securec.h @@ -18,6 +18,13 @@ #ifndef SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27 #define SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27 +#ifndef HAVE_CONFIG_H +#define HAVE_CONFIG_H 1 +#endif + +#if HAVE_CONFIG_H +#include "boundscheck_config.h" +#endif #include "securectype.h" #ifndef SECUREC_HAVE_STDARG_H #define SECUREC_HAVE_STDARG_H 1 @@ -389,7 +396,7 @@ SECUREC_API char *gets_s(char *buffer, size_t destMax); #endif #if SECUREC_ENABLE_WCHAR_FUNC -#if SECUREC_ENABLE_MEMCPY +#if SECUREC_ENABLE_MEMCPY_W /* * Description: The wmemcpy_s function copies n successive wide characters from the object pointed to * by src into the object pointed to by dest. @@ -402,7 +409,7 @@ SECUREC_API char *gets_s(char *buffer, size_t destMax); SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); #endif -#if SECUREC_ENABLE_MEMMOVE +#if SECUREC_ENABLE_MEMMOVE_W /* * Description: The wmemmove_s function copies n successive wide characters from the object * pointed to by src into the object pointed to by dest. @@ -415,7 +422,7 @@ SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); #endif -#if SECUREC_ENABLE_STRCPY +#if SECUREC_ENABLE_STRCPY_W /* * Description: The wcscpy_s function copies the wide string pointed to by strSrc(including the terminating * null wide character) into the array pointed to by strDest @@ -427,7 +434,7 @@ SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); #endif -#if SECUREC_ENABLE_STRNCPY +#if SECUREC_ENABLE_STRNCPY_W /* * Description: The wcsncpy_s function copies not more than n successive wide characters (not including the * terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest @@ -440,7 +447,7 @@ SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *st SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); #endif -#if SECUREC_ENABLE_STRCAT +#if SECUREC_ENABLE_STRCAT_W /* * Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the * terminating null wide character) to the end of the wide string pointed to by strDest @@ -452,7 +459,7 @@ SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *s SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); #endif -#if SECUREC_ENABLE_STRNCAT +#if SECUREC_ENABLE_STRNCAT_W /* * Description: The wcsncat_s function appends not more than n successive wide characters (not including the * terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to @@ -466,7 +473,7 @@ SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *st SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); #endif -#if SECUREC_ENABLE_STRTOK +#if SECUREC_ENABLE_STRTOK_W /* * Description: The wcstok_s function is the wide-character equivalent of the strtok_s function * Parameter: strToken - the string to be delimited @@ -478,7 +485,7 @@ SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *s SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context); #endif -#if SECUREC_ENABLE_VSPRINTF +#if SECUREC_ENABLE_VSPRINTF_W /* * Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function * Parameter: strDest - produce output according to a format,write to the character string strDest @@ -491,7 +498,7 @@ SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wcha SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList); #endif -#if SECUREC_ENABLE_SPRINTF +#if SECUREC_ENABLE_SPRINTF_W /* * Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function * Parameter: strDest - produce output according to a format,write to the character string strDest @@ -503,7 +510,7 @@ SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *for SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...); #endif -#if SECUREC_ENABLE_FSCANF +#if SECUREC_ENABLE_FSCANF_W /* * Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function * Parameter: stream - stdio file stream @@ -513,7 +520,7 @@ SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *form SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...); #endif -#if SECUREC_ENABLE_VFSCANF +#if SECUREC_ENABLE_VFSCANF_W /* * Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function * Parameter: stream - stdio file stream @@ -524,7 +531,7 @@ SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...); SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList); #endif -#if SECUREC_ENABLE_SCANF +#if SECUREC_ENABLE_SCANF_W /* * Description: The wscanf_s function is the wide-character equivalent of the scanf_s function * Parameter: format - format string @@ -533,7 +540,7 @@ SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList) SECUREC_API int wscanf_s(const wchar_t *format, ...); #endif -#if SECUREC_ENABLE_VSCANF +#if SECUREC_ENABLE_VSCANF_W /* * Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function * Parameter: format - format string @@ -543,7 +550,7 @@ SECUREC_API int wscanf_s(const wchar_t *format, ...); SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList); #endif -#if SECUREC_ENABLE_SSCANF +#if SECUREC_ENABLE_SSCANF_W /* * Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function * Parameter: buffer - read character from buffer @@ -553,7 +560,7 @@ SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList); SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...); #endif -#if SECUREC_ENABLE_VSSCANF +#if SECUREC_ENABLE_VSSCANF_W /* * Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function * Parameter: buffer - read character from buffer diff --git a/src/fscanf_s.c b/src/fscanf_s.c index d3c7f06..e1052ce 100644 --- a/src/fscanf_s.c +++ b/src/fscanf_s.c @@ -14,6 +14,7 @@ #include "securec.h" +#if SECUREC_ENABLE_FSCANF /* * * The fscanf_s function is equivalent to fscanf except that the c, s, @@ -51,3 +52,4 @@ int fscanf_s(FILE *stream, const char *format, ...) return ret; } +#endif diff --git a/src/fwscanf_s.c b/src/fwscanf_s.c index bd0f12a..855d398 100644 --- a/src/fwscanf_s.c +++ b/src/fwscanf_s.c @@ -14,6 +14,8 @@ #include "securec.h" +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_FSCANF_W /* * * The fwscanf_s function is the wide-character equivalent of the fscanf_s function @@ -50,3 +52,5 @@ int fwscanf_s(FILE *stream, const wchar_t *format, ...) return ret; } +#endif +#endif diff --git a/src/gets_s.c b/src/gets_s.c index d12495a..5895428 100644 --- a/src/gets_s.c +++ b/src/gets_s.c @@ -27,6 +27,7 @@ SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t size) } } +#if SECUREC_ENABLE_GETS && !SECUREC_IN_KERNEL /* * * The gets_s function reads at most one less than the number of characters @@ -69,3 +70,4 @@ char *gets_s(char *buffer, size_t destMax) return NULL; } +#endif diff --git a/src/memcpy_s.c b/src/memcpy_s.c index a7fd487..bb225a2 100644 --- a/src/memcpy_s.c +++ b/src/memcpy_s.c @@ -484,6 +484,7 @@ SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax, const void *sr (count) > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) #endif +#if SECUREC_ENABLE_MEMCPY /* * * The memcpy_s function copies n characters from the object pointed to by src into the object pointed to by dest @@ -525,6 +526,7 @@ errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count) #if SECUREC_EXPORT_KERNEL_SYMBOL EXPORT_SYMBOL(memcpy_s); #endif +#endif #if SECUREC_WITH_PERFORMANCE_ADDONS /* diff --git a/src/memmove_s.c b/src/memmove_s.c index f231f05..7f292f2 100644 --- a/src/memmove_s.c +++ b/src/memmove_s.c @@ -57,6 +57,7 @@ SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count) } #endif +#if SECUREC_ENABLE_MEMMOVE /* * * The memmove_s function copies count bytes of characters from src to dest. @@ -121,3 +122,4 @@ errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count) EXPORT_SYMBOL(memmove_s); #endif +#endif diff --git a/src/memset_s.c b/src/memset_s.c index d9a657f..95e7f97 100644 --- a/src/memset_s.c +++ b/src/memset_s.c @@ -444,6 +444,7 @@ SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c) return ERANGE_AND_RESET; } +#if SECUREC_ENABLE_MEMSET /* * * The memset_s function copies the value of c (converted to an unsigned char) @@ -479,6 +480,7 @@ errno_t memset_s(void *dest, size_t destMax, int c, size_t count) #if SECUREC_EXPORT_KERNEL_SYMBOL EXPORT_SYMBOL(memset_s); #endif +#endif #if SECUREC_WITH_PERFORMANCE_ADDONS /* diff --git a/src/scanf_s.c b/src/scanf_s.c index fa5470b..652a88d 100644 --- a/src/scanf_s.c +++ b/src/scanf_s.c @@ -14,6 +14,7 @@ #include "securec.h" +#if SECUREC_ENABLE_SCANF /* * * The scanf_s function is equivalent to fscanf_s with the argument stdin interposed before the arguments to scanf_s @@ -49,3 +50,4 @@ int scanf_s(const char *format, ...) return ret; } +#endif diff --git a/src/secureinput_w.c b/src/secureinput_w.c index 12c9ef8..53fc3dc 100644 --- a/src/secureinput_w.c +++ b/src/secureinput_w.c @@ -29,7 +29,10 @@ #endif /* Disable wchar func to clear vs warning */ +#ifdef SECUREC_ENABLE_WCHAR_FUNC +#undef SECUREC_ENABLE_WCHAR_FUNC #define SECUREC_ENABLE_WCHAR_FUNC 0 +#endif #define SECUREC_FORMAT_OUTPUT_INPUT 1 #ifndef SECUREC_FOR_WCHAR diff --git a/src/secureprintoutput_w.c b/src/secureprintoutput_w.c index 672c018..f829d0e 100644 --- a/src/secureprintoutput_w.c +++ b/src/secureprintoutput_w.c @@ -28,7 +28,10 @@ #endif /* Disable wchar func to clear vs warning */ +#ifdef SECUREC_ENABLE_WCHAR_FUNC +#undef SECUREC_ENABLE_WCHAR_FUNC #define SECUREC_ENABLE_WCHAR_FUNC 0 +#endif #define SECUREC_FORMAT_OUTPUT_INPUT 1 #ifndef SECUREC_FOR_WCHAR diff --git a/src/snprintf_s.c b/src/snprintf_s.c index e9b94f3..2a7fccc 100644 --- a/src/snprintf_s.c +++ b/src/snprintf_s.c @@ -59,6 +59,8 @@ int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, #if SECUREC_EXPORT_KERNEL_SYMBOL EXPORT_SYMBOL(snprintf_s); #endif +#elif SECUREC_ENABLE_SNPRINTF_WIN32 +#define snprintf_s _snprintf_s #endif #if SECUREC_SNPRINTF_TRUNCATED diff --git a/src/sprintf_s.c b/src/sprintf_s.c index 0cf3fca..f6d47c3 100644 --- a/src/sprintf_s.c +++ b/src/sprintf_s.c @@ -14,6 +14,7 @@ #include "securec.h" +#if SECUREC_ENABLE_SPRINTF /* * * The sprintf_s function is equivalent to the sprintf function @@ -56,3 +57,4 @@ int sprintf_s(char *strDest, size_t destMax, const char *format, ...) EXPORT_SYMBOL(sprintf_s); #endif +#endif diff --git a/src/sscanf_s.c b/src/sscanf_s.c index b441329..f00d365 100644 --- a/src/sscanf_s.c +++ b/src/sscanf_s.c @@ -14,6 +14,7 @@ #include "securec.h" +#if SECUREC_ENABLE_SSCANF /* * * The sscanf_s function is equivalent to fscanf_s, @@ -56,3 +57,4 @@ int sscanf_s(const char *buffer, const char *format, ...) EXPORT_SYMBOL(sscanf_s); #endif +#endif diff --git a/src/strcat_s.c b/src/strcat_s.c index f835e7b..31bc7f8 100644 --- a/src/strcat_s.c +++ b/src/strcat_s.c @@ -49,6 +49,7 @@ SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax, const char *strSr return EOK; } +#if SECUREC_ENABLE_STRCAT /* * * The strcat_s function appends a copy of the string pointed to by strSrc (including the terminating null character) @@ -99,3 +100,4 @@ errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc) EXPORT_SYMBOL(strcat_s); #endif +#endif diff --git a/src/strcpy_s.c b/src/strcpy_s.c index ca1b2dd..b41b6b6 100644 --- a/src/strcpy_s.c +++ b/src/strcpy_s.c @@ -298,6 +298,7 @@ errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc) return CheckSrcRange(strDest, destMax, strSrc); } +#if SECUREC_ENABLE_STRCPY /* * * The strcpy_s function copies the string pointed to strSrc @@ -351,3 +352,4 @@ errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc) EXPORT_SYMBOL(strcpy_s); #endif +#endif diff --git a/src/strncat_s.c b/src/strncat_s.c index 6686d29..765219b 100644 --- a/src/strncat_s.c +++ b/src/strncat_s.c @@ -51,6 +51,7 @@ SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax, const char * return EOK; } +#if SECUREC_ENABLE_STRNCAT /* * * The strncat_s function appends not more than n successive characters @@ -117,3 +118,4 @@ errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t coun EXPORT_SYMBOL(strncat_s); #endif +#endif diff --git a/src/strncpy_s.c b/src/strncpy_s.c index 5f4c5b7..bc7f3c0 100644 --- a/src/strncpy_s.c +++ b/src/strncpy_s.c @@ -81,6 +81,7 @@ errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t return CheckSrcCountRange(strDest, destMax, strSrc, count); } +#if SECUREC_ENABLE_STRNCPY /* * * The strncpy_s function copies not more than n successive characters (not including the terminating null character) @@ -143,3 +144,4 @@ errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t coun EXPORT_SYMBOL(strncpy_s); #endif +#endif diff --git a/src/strtok_s.c b/src/strtok_s.c index cd5dcd2..3b76d67 100644 --- a/src/strtok_s.c +++ b/src/strtok_s.c @@ -74,6 +74,7 @@ SECUREC_INLINE char *SecUpdateToken(char *strToken, const char *strDelimit, char return strToken; } +#if SECUREC_ENABLE_STRTOK /* * * The strtok_s function parses a string into a sequence of strToken, @@ -114,3 +115,4 @@ char *strtok_s(char *strToken, const char *strDelimit, char **context) EXPORT_SYMBOL(strtok_s); #endif +#endif diff --git a/src/swprintf_s.c b/src/swprintf_s.c index 09d77a2..0ab946a 100644 --- a/src/swprintf_s.c +++ b/src/swprintf_s.c @@ -14,6 +14,8 @@ #include "securec.h" +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_SPRINTF_W /* * * The swprintf_s function is the wide-character equivalent of the sprintf_s function @@ -46,3 +48,5 @@ int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...) return ret; } +#endif +#endif diff --git a/src/swscanf_s.c b/src/swscanf_s.c index e5b8bbf..9aae635 100644 --- a/src/swscanf_s.c +++ b/src/swscanf_s.c @@ -14,6 +14,8 @@ #include "securec.h" +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_SSCANF_W /* * * The swscanf_s function is the wide-character equivalent of the sscanf_s function @@ -52,3 +54,5 @@ int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...) return ret; } +#endif +#endif diff --git a/src/vfscanf_s.c b/src/vfscanf_s.c index 214ee6a..dc20377 100644 --- a/src/vfscanf_s.c +++ b/src/vfscanf_s.c @@ -14,6 +14,7 @@ #include "secinput.h" +#if SECUREC_ENABLE_VFSCANF /* * * The vfscanf_s function is equivalent to fscanf_s, with the variable argument list replaced by argList @@ -62,3 +63,4 @@ int vfscanf_s(FILE *stream, const char *format, va_list argList) return retVal; } +#endif diff --git a/src/vfwscanf_s.c b/src/vfwscanf_s.c index 1ab9c3c..1e06e77 100644 --- a/src/vfwscanf_s.c +++ b/src/vfwscanf_s.c @@ -18,6 +18,8 @@ #include "secinput.h" +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_VFSCANF_W /* * * The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function @@ -65,3 +67,5 @@ int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList) return retVal; } +#endif +#endif diff --git a/src/vscanf_s.c b/src/vscanf_s.c index 61480a6..35bf621 100644 --- a/src/vscanf_s.c +++ b/src/vscanf_s.c @@ -14,6 +14,7 @@ #include "secinput.h" +#if SECUREC_ENABLE_VSCANF /* * * The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList, @@ -61,3 +62,4 @@ int vscanf_s(const char *format, va_list argList) return retVal; } +#endif diff --git a/src/vsprintf_s.c b/src/vsprintf_s.c index f50fa4a..6a95e09 100644 --- a/src/vsprintf_s.c +++ b/src/vsprintf_s.c @@ -14,6 +14,7 @@ #include "secureprintoutput.h" +#if SECUREC_ENABLE_VSPRINTF /* * * The vsprintf_s function is equivalent to the vsprintf function @@ -65,3 +66,4 @@ int vsprintf_s(char *strDest, size_t destMax, const char *format, va_list argLis EXPORT_SYMBOL(vsprintf_s); #endif +#endif diff --git a/src/vsscanf_s.c b/src/vsscanf_s.c index a19abe2..2896114 100644 --- a/src/vsscanf_s.c +++ b/src/vsscanf_s.c @@ -18,6 +18,7 @@ #include #endif +#if SECUREC_ENABLE_VSSCANF /* * * vsscanf_s @@ -85,3 +86,4 @@ int vsscanf_s(const char *buffer, const char *format, va_list argList) EXPORT_SYMBOL(vsscanf_s); #endif +#endif diff --git a/src/vswprintf_s.c b/src/vswprintf_s.c index 29715fc..ccf0ebc 100644 --- a/src/vswprintf_s.c +++ b/src/vswprintf_s.c @@ -18,6 +18,9 @@ #include "secureprintoutput.h" + +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_VSPRINTF_W /* * * The vswprintf_s function is the wide-character equivalent of the vsprintf_s function @@ -60,3 +63,5 @@ int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list return retVal; } +#endif +#endif diff --git a/src/vswscanf_s.c b/src/vswscanf_s.c index bab53a3..d6dbd94 100644 --- a/src/vswscanf_s.c +++ b/src/vswscanf_s.c @@ -27,6 +27,8 @@ SECUREC_INLINE size_t SecWcslen(const wchar_t *s) return ((size_t)((end - s))); } +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_VSSCANF_W /* * * The vswscanf_s function is the wide-character equivalent of the vsscanf_s function @@ -77,3 +79,5 @@ int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList) return retVal; } +#endif +#endif diff --git a/src/vwscanf_s.c b/src/vwscanf_s.c index b39f9bc..8313bf8 100644 --- a/src/vwscanf_s.c +++ b/src/vwscanf_s.c @@ -18,6 +18,8 @@ #include "secinput.h" +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_VSCANF_W /* * * The vwscanf_s function is the wide-character equivalent of the vscanf_s function @@ -62,3 +64,5 @@ int vwscanf_s(const wchar_t *format, va_list argList) return retVal; } +#endif +#endif diff --git a/src/wcscat_s.c b/src/wcscat_s.c index fa7d847..e05fae8 100644 --- a/src/wcscat_s.c +++ b/src/wcscat_s.c @@ -51,6 +51,8 @@ SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax, const wchar_t return EOK; } +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_STRCAT_W /* * * The wcscat_s function appends a copy of the wide string pointed to by strSrc @@ -105,3 +107,5 @@ errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) return SecDoCatW(strDest, destMax, strSrc); } +#endif +#endif diff --git a/src/wcscpy_s.c b/src/wcscpy_s.c index 8c4a4af..8efd1a0 100644 --- a/src/wcscpy_s.c +++ b/src/wcscpy_s.c @@ -39,6 +39,8 @@ SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax, const wchar_t } } +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_STRCPY_W /* * * The wcscpy_s function copies the wide string pointed to by strSrc @@ -84,3 +86,5 @@ errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) return SecDoCpyW(strDest, destMax, strSrc); } +#endif +#endif diff --git a/src/wcsncat_s.c b/src/wcsncat_s.c index 33e53a3..09a9450 100644 --- a/src/wcsncat_s.c +++ b/src/wcsncat_s.c @@ -48,6 +48,8 @@ SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax, const wc return EOK; } +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_STRNCAT_W /* * * The wcsncat_s function appends not more than n successive wide characters @@ -111,3 +113,5 @@ errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_ return SecDoCatLimitW(strDest, destMax, strSrc, count); } +#endif +#endif diff --git a/src/wcsncpy_s.c b/src/wcsncpy_s.c index 463f90e..6e58e15 100644 --- a/src/wcsncpy_s.c +++ b/src/wcsncpy_s.c @@ -42,6 +42,8 @@ SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax, const wc } } +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_STRNCPY_W /* * * The wcsncpy_s function copies not more than n successive wide characters @@ -105,3 +107,5 @@ errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_ return SecDoCpyLimitW(strDest, destMax, strSrc, count); } +#endif +#endif diff --git a/src/wcstok_s.c b/src/wcstok_s.c index 063ca69..f6a63a7 100644 --- a/src/wcstok_s.c +++ b/src/wcstok_s.c @@ -73,6 +73,8 @@ SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken, const wchar_t *strDel return strToken; } +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_STRTOK_W /* * * wcstok_s @@ -110,3 +112,5 @@ wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **contex return SecUpdateTokenW(orgToken, strDelimit, context); } +#endif +#endif diff --git a/src/wmemcpy_s.c b/src/wmemcpy_s.c index 2f2b4a3..126ba3a 100644 --- a/src/wmemcpy_s.c +++ b/src/wmemcpy_s.c @@ -19,6 +19,8 @@ #include "securecutil.h" +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_MEMCPY_W /* * * The wmemcpy_s function copies n successive wide characters @@ -69,3 +71,5 @@ errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t coun return memcpy_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t)); } +#endif +#endif diff --git a/src/wmemmove_s.c b/src/wmemmove_s.c index 88bb97b..0eaa7af 100644 --- a/src/wmemmove_s.c +++ b/src/wmemmove_s.c @@ -19,6 +19,8 @@ #include "securecutil.h" +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_MEMMOVE_W /* * * The wmemmove_s function copies n successive wide characters from the object pointed @@ -68,3 +70,5 @@ errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t cou return memmove_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t)); } +#endif +#endif diff --git a/src/wscanf_s.c b/src/wscanf_s.c index badb04e..1760f91 100644 --- a/src/wscanf_s.c +++ b/src/wscanf_s.c @@ -14,6 +14,8 @@ #include "securec.h" +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_SCANF_W /* * * @@ -50,3 +52,5 @@ int wscanf_s(const wchar_t *format, ...) return ret; } +#endif +#endif -- Gitee