diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..91df2fb056e6ef7396c72515aff64410cd60957c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.vscode/
+target/
+Cargo.lock
diff --git a/3rd/gstor/.gitignore b/3rd/gstor/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..d4e77a58609a0d96de66bc58e1a0520d090c5ca7
--- /dev/null
+++ b/3rd/gstor/.gitignore
@@ -0,0 +1,10 @@
+# cmake
+**CMakeCache.txt
+**CMakeFiles/
+**cmake_install.cmake
+**Makefile
+
+library/
+output/
+build/include/config.h
+build/build_result.log
diff --git a/3rd/gstor/CMakeLists.txt b/3rd/gstor/CMakeLists.txt
index 39b27efa386da3bcdcf0ce03b36636c04917b4e4..aaa930e353b818ca931194fea1e8fdb6d36dec81 100644
--- a/3rd/gstor/CMakeLists.txt
+++ b/3rd/gstor/CMakeLists.txt
@@ -117,31 +117,32 @@ set(DCC_KV_STORAGE_PATH ${PROJECT_SOURCE_DIR}/src/storage/kv_executor)
set(DCC_GSTOR_INC_PATH ${PROJECT_SOURCE_DIR}/src/storage/gstor)
## other dependency include
-set(DCC_SECUREC_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/huawei_security/include)
-set(DCC_OPENSSL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/openssl/include)
-set(DCC_CJSON_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/cJSON/include)
-set(DCC_LZ4_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/lz4/include)
-set(DCC_ZLIB_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zlib/include)
-set(DCC_ZSTANDARD_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zstd/include)
-set(DCC_LIBAIO_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/libaio/include)
-# set(DCC_DCF_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/dcf/include)
-# set(DCC_CBB_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/cbb/include)
-
-set(DCC_ZEKERNEL_KERNEL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zekernel/include/kernel)
-set(DCC_ZEKERNEL_PROTOCOL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zekernel/include/protocol)
-set(DCC_ZEKERNEL_COMMON_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zekernel/include/common)
+set(DCC_SECUREC_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/inc/huawei_security)
+set(DCC_OPENSSL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/inc/openssl)
+#set(DCC_CJSON_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/inc/cJSON)
+if (ENABLE_LZ4)
+set(DCC_LZ4_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/inc/lz4)
+endif()
+set(DCC_ZLIB_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/inc/zlib)
+if (ENABLE_ZSTD)
+set(DCC_ZSTANDARD_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/inc/zstd)
+endif()
+if (ENABLE_LIBAIO)
+set(DCC_LIBAIO_INC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/inc/libaio)
+endif()
+set(DCC_ZEKERNEL_KERNEL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/lib/include/kernel)
+# set(DCC_ZEKERNEL_PROTOCOL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zekernel/include/protocol)
+# set(DCC_ZEKERNEL_COMMON_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zekernel/include/common)
## lib
-set(SECUREC_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/huawei_security/lib)
-set(OPENSSL_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/openssl/lib)
-set(CJSON_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/cJSON/lib)
-set(DCC_LZ4_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/lz4/lib)
-set(DCC_ZLIB_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zlib/lib)
-set(DCC_ZSTANDARD_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zstd/lib)
-set(DCC_ZEKERNEL_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zekernel/lib)
-# set(DCC_DCF_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/dcf/lib)
-# set(DCC_CBB_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/cbb/lib)
+set(SECUREC_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/lib)
+set(OPENSSL_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/lib)
+set(CJSON_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/lib)
+set(DCC_LZ4_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/lib)
+set(DCC_ZLIB_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/lib)
+set(DCC_ZSTANDARD_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/lib)
+# set(DCC_ZEKERNEL_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/library/zekernel/lib)
## output path
set (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/output/lib)
@@ -170,15 +171,23 @@ if (ENABLE_MEMCHECK)
endif ()
set(G_BIN_EXT_LIBS ${MEMCHECK_LIBS})
-link_directories(${LIBRARY_OUTPUT_PATH} ${SECUREC_LIB_PATH} ${OPENSSL_LIB_PATH} ${CJSON_LIB_PATH} ${DCC_ZEKERNEL_LIB_PATH} ${DCC_DCF_LIB_PATH} ${DCC_CBB_LIB_PATH} ${DCC_LZ4_LIB_PATH} ${DCC_ZLIB_LIB_PATH} ${DCC_ZSTANDARD_LIB_PATH} ${MEMCHECK_LINK_DIRECTORIES})
+#link_directories(${LIBRARY_OUTPUT_PATH} ${SECUREC_LIB_PATH} ${OPENSSL_LIB_PATH} ${CJSON_LIB_PATH} ${DCC_LZ4_LIB_PATH} ${DCC_ZLIB_LIB_PATH} ${DCC_ZSTANDARD_LIB_PATH} ${MEMCHECK_LINK_DIRECTORIES})
+link_directories(${LIBRARY_OUTPUT_PATH} ${SECUREC_LIB_PATH} } ${DCC_ZLIB_LIB_PATH} ${DCC_ZSTANDARD_LIB_PATH} ${MEMCHECK_LINK_DIRECTORIES})
set(vpp_libsecurec "securec")
+if (ENABLE_LZ4)
set(3rd_liblz4 "lz4")
+endif()
+if (ENABLE_ZSTD)
set(3rd_libzstd "zstd")
+endif()
+if (ENABLE_SSL)
set(3rd_libssl "ssl")
+endif()
+if (ENABLE_CRYPTO)
set(3rd_lib_crypto "crypto")
-set(3rd_libjson "cjson")
-# set(3rd_libcbb "cbb_static")
+endif()
+#set(3rd_libjson "cjson")
add_subdirectory(src)
# OPTION(TEST "option for test module" OFF)
diff --git a/3rd/gstor/README.md b/3rd/gstor/README.md
index 0135fedca54acf59db43c875a0f058c42762fecb..c4eb97e12a881082a078fc4b0e1695c1c0a6606c 100644
--- a/3rd/gstor/README.md
+++ b/3rd/gstor/README.md
@@ -4,47 +4,44 @@
##### 1、编程语言:C
##### 2、编译工程:cmake或make,建议使用cmake
##### 3、目录说明:
-- local-db:主目录,CMakeLists.txt为主工程入口;
- src: 源代码目录,按子目录划分模块解耦;
- build:工程构建脚本
+- dependency:第三方依赖
#### 二、编译指导
##### 1、概述
-编译local-db需要依赖binarylibs组件。
-- binarylibs:依赖的第三方开源软件,你可以直接编译openGauss-third_party代码获取,也可以从开源社区下载已经编译好的并上传的一个副本。
+编译gstor需要依赖dependency组件。
+- dependency:依赖的第三方开源软件
##### 2、操作系统和软件依赖要求
支持以下操作系统:
- CentOS 7.6(x86)
- openEuler-20.03-LTS
+- Ubuntu 20.04
适配其他系统,可参照openGauss数据库编译指导
-当前local-db依赖第三方软件有securec、zlib、lz4、zstd、openssl、cjson;
-编译local-db依赖的第三方软件要求与编译opengauss对依赖的第三方软件要求一致。
-##### 3、下载local-db及依赖组件
-可以从开源社区下载openGauss-third_party。
-可以通过以下网站获取编译好的binarylibs。
-https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/openGauss-third_party_binarylibs.tar.gz
-##### 4、编译第三方软件
-在编译local-db之前,需要先编译local-db依赖的开源及第三方软件。这些开源及第三方软件存储在openGauss-third_party代码仓库中,通常只需要构建一次。如果开源软件有更新,需要重新构建软件。
-用户也可以直接从binarylibs库中获取开源软件编译和构建的输出文件。
+
+- GCC >= 7.3
+
+当前gstor依赖第三方软件有securec、zlib、lz4、openssl;
+编译gstor依赖的第三方软件要求与编译opengauss对依赖的第三方软件要求一致。
+##### 3、编译第三方软件
+在编译gstor之前,需要先编译gstor依赖的开源及第三方软件。
+$ sh dependency/build/build_all.sh
+
##### 5、代码编译
-使用local-db/build/linux/opengauss/build.sh编译代码, 参数说明请见以下表格。
+使用build.sh编译代码, 参数说明请见以下表格。
| 选项 | 参数 | 说明 |
| --- |:--- | :--- |
-| -3rd | [binarylibs path] | 指定binarylibs路径。该路径必须是绝对路径。|
| -m | [version_mode] | 编译目标版本,Debug或者Release。默认Release|
| -t | [build_tool] | 指定编译工具,cmake或者make。默认cmake。|
-现在只需使用如下命令即可编译(env.sh需要修改其中[binarylibs path]当前环境的路径):
-[user@linux local-db]$ source env.sh
-[user@linux local-db]$ sh build.sh -3rd [binarylibs path] -m Release -t cmake
-完成编译后,动态库生成在local-db/output/lib目录中
-
+$ sh build.sh -m Release -t cmake
+完成编译后,动态库生成在output/lib目录中
+可执行程序生成在output/bin/目录中
#### 三、接口与使用示例
#####1. 接口说明
#####2. DEMO示例
-
-[user@linux local-db]$ mkdir output/data
+可根据对应的目录进行测试
[user@linux local-db]$ local-db -D output/data
diff --git a/3rd/gstor/build/linux/opengauss/build.sh b/3rd/gstor/build/linux/opengauss/build.sh
old mode 100644
new mode 100755
index 7febcb6154fb9a0a40c2ad3f14c9f24228d5c0b8..4099497c962d8510c20941aa0fc3cf8bf352519d
--- a/3rd/gstor/build/linux/opengauss/build.sh
+++ b/3rd/gstor/build/linux/opengauss/build.sh
@@ -29,6 +29,13 @@ function print_help()
"
}
+LOCAL_DIR=$(dirname "${0}")
+ROOT_DIR=$(cd `dirname $0`/../../..; pwd)
+
+# default value to the parameter '-3rd'.
+# This is where the files generated by dependency/build/build_all.sh will go
+binarylib_dir="${ROOT_DIR}/output"
+
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
@@ -87,71 +94,70 @@ if [ ! "$build_tool"x == "make"x ] && [ ! "$build_tool"x == "cmake"x ]; then
fi
export CFLAGS="-std=gnu99"
-LOCAL_PATH=${0}
-
-CUR_PATH=$(pwd)
-
-LOCAL_DIR=$(dirname "${LOCAL_PATH}")
-
-export PACKAGE=$LOCAL_DIR/../../../
-export OUT_PACKAGE=dcc
-
-export DCC_LIBRARYS=$(pwd)/../../../library
-
-[ -d "${DCC_LIBRARYS}" ] && rm -rf ${DCC_LIBRARYS}
-mkdir -p $DCC_LIBRARYS/huawei_security
-mkdir -p $DCC_LIBRARYS/openssl
-mkdir -p $DCC_LIBRARYS/huawei_security
-mkdir -p $DCC_LIBRARYS/openssl
-mkdir -p $DCC_LIBRARYS/lz4
-mkdir -p $DCC_LIBRARYS/zstd
-mkdir -p $DCC_LIBRARYS/cJSON
-mkdir -p $DCC_LIBRARYS/zlib
-mkdir -p $DCC_LIBRARYS/libaio/include
-mkdir -p $DCC_LIBRARYS/dcf
-mkdir -p $DCC_LIBRARYS/cbb
-
-LIB_PATH=${binarylib_dir}/kernel/dependency/
-PLAT_LIB_PATH=${binarylib_dir}/kernel/platform/
-COPT_LIB_PATH=${binarylib_dir}/kernel/component/
-
-cp -r $PLAT_LIB_PATH/Huawei_Secure_C/comm/lib $DCC_LIBRARYS/huawei_security/lib
-cp -r $LIB_PATH/openssl/comm/lib $DCC_LIBRARYS/openssl/lib
-cp -r $LIB_PATH/zstd/lib $DCC_LIBRARYS/zstd/lib
-cp -r $LIB_PATH/lz4/comm/lib $DCC_LIBRARYS/lz4/lib
-cp -r $LIB_PATH/cjson/comm/lib $DCC_LIBRARYS/cJSON/lib
-cp -r $LIB_PATH/zlib*/comm/lib $DCC_LIBRARYS/zlib/lib
-
-cp -r $PLAT_LIB_PATH/Huawei_Secure_C/comm/include $DCC_LIBRARYS/huawei_security/include
-cp -r $LIB_PATH/openssl/comm/include $DCC_LIBRARYS/openssl/include
-cp -r $LIB_PATH/zstd/include $DCC_LIBRARYS/zstd/include
-cp -r $LIB_PATH/lz4/comm/include $DCC_LIBRARYS/lz4/include
-cp -r $LIB_PATH/cjson/comm/include/cjson $DCC_LIBRARYS/cJSON/include
-cp -r $LIB_PATH/zlib*/comm/include $DCC_LIBRARYS/zlib/include
-cp -r /usr/include/libaio.h $DCC_LIBRARYS/libaio/include
-
-cp -r $COPT_LIB_PATH/cbb/include $DCC_LIBRARYS/cbb/include
-cp -r $COPT_LIB_PATH/cbb/lib $DCC_LIBRARYS/cbb/lib
-
-# cp -r $COPT_LIB_PATH/dcf/include $DCC_LIBRARYS/dcf/include
-# cp -r $COPT_LIB_PATH/dcf/lib $DCC_LIBRARYS/dcf/lib
+export PACKAGE=${ROOT_DIR}
+# export OUT_PACKAGE=dcc
+# export DCC_LIBRARYS=${ROOT_DIR}/library
+
+O_LIB_DIR=${ROOT_DIR}/output/lib
+O_INC_DIR=${ROOT_DIR}/output/inc
+
+# OLD way for library: based on library/ , which contains openssl,cJSON, lz4 e.t. and the include、lib
+# NEW way for library: based on output/ , which contains
+# - lib : Holds the compilation results of libaray files
+# - inc : To replace the previous library/xxx/include as the include directory for header files, containing openssl, cJSON, lz4...
+# - bin : Holds the compilation results of executable files
+[ -d "${O_INC_DIR}" ] && rm -rf ${O_INC_DIR}
+mkdir -p "${O_INC_DIR}/huawei_security"
+#mkdir -p "${O_INC_DIR}/openssl"
+#mkdir -p "${O_INC_DIR}/lz4"
+#mkdir -p "${O_INC_DIR}/zstd"
+#mkdir -p "${O_INC_DIR}/cJSON"
+mkdir -p "${O_INC_DIR}/zlib"
+
+#mkdir -p "${O_INC_DIR}/libaio"
+
+
+[ -d "${O_LIB_DIR}" ] && rm -rf ${O_LIB_DIR}
+mkdir -p "${O_LIB_DIR}"
+
+LIB_PATH=${binarylib_dir}/kernel/dependency
+PLAT_LIB_PATH=${binarylib_dir}/kernel/platform
+# COPT_LIB_PATH=${binarylib_dir}/kernel/component
+
+cp -r $PLAT_LIB_PATH/Huawei_Secure_C/comm/lib/* $O_LIB_DIR
+#cp -r $LIB_PATH/openssl/comm/lib/* $O_LIB_DIR
+#cp -r $LIB_PATH/zstd/lib/* $O_LIB_DIR
+#cp -r $LIB_PATH/lz4/comm/lib/* $O_LIB_DIR
+#cp -r $LIB_PATH/cjson/comm/lib/* $O_LIB_DIR
+cp -r $LIB_PATH/zlib*/comm/lib/* $O_LIB_DIR
+
+# OLD way for include directory: libaray/xxx/include
+# NEW way for include directory: output/inc/xxx
+cp -r $PLAT_LIB_PATH/Huawei_Secure_C/comm/include/* ${O_INC_DIR}/huawei_security
+#cp -r $LIB_PATH/openssl/comm/include/* ${O_INC_DIR}/openssl
+#cp -r $LIB_PATH/zstd/include/* ${O_INC_DIR}/zstd
+#cp -r $LIB_PATH/lz4/comm/include/* ${O_INC_DIR}/lz4
+#cp -r $LIB_PATH/cjson/comm/include/cjson/* ${O_INC_DIR}/cJSON
+cp -r $LIB_PATH/zlib*/comm/include/* ${O_INC_DIR}/zlib
+
+#cp -r /usr/include/libaio.h ${O_INC_DIR}/libaio
cd $PACKAGE
if [ "$build_tool"x == "cmake"x ];then
cmake -DCMAKE_BUILD_TYPE=${version_mode} -DUT=OFF -DENABLE_GCOV=OFF -DENABLE_DCC_LITE=ON \
- -DENABLE_MEMCHECK=OFF -DENABLE_EXPORT_API=ON -DSTATISTICS=OFF -DENABLE_BACKUP=OFF
+ -DENABLE_MEMCHECK=OFF -DENABLE_EXPORT_API=ON -DSTATISTICS=OFF -DENABLE_BACKUP=OFF -DENABLE_LIBAIO=OFF -DSSL=OFF -DCRYPTO=OFF
make -sj 8
else
make clean
make BUILD_TYPE=${version_mode} -sj 8
fi
-mkdir -p ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/include
-mkdir -p ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/lib
-mkdir -p ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/bin
+# mkdir -p ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/include
+# mkdir -p ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/lib
+# mkdir -p ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/bin
# cp ./src/client/interface/clt_interface.h ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/include
-# cp ./src/interface/dcc_interface.h ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/include
-cp ./output/bin/* ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/bin
-cp ./output/lib/*.so ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/lib
+# cp ./src/interface/dcc_interface.h ${binarylib_dir}/kernel/component/${#}/include
+# cp ./output/bin/* ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/bin
+# cp ./output/lib/*.so ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/lib
# cp $COPT_LIB_PATH/dcf/lib/libdcf.so ${binarylib_dir}/kernel/component/${OUT_PACKAGE}/lib
echo "build DCC SUCCESS"
diff --git a/3rd/gstor/db.ini.template b/3rd/gstor/db.ini.template
new file mode 100644
index 0000000000000000000000000000000000000000..36176b247684d347fac0cfac6a611961617fd29b
--- /dev/null
+++ b/3rd/gstor/db.ini.template
@@ -0,0 +1,19 @@
+buf_pool_num=1
+data_buf_size=134217728
+cr_pool_count=1
+cr_pool_size=1048576
+log_buf_size=16777216
+shared_area_size=134217728
+vma_size=4194304
+large_vma_size=1048576
+tran_buf_size=1191936
+dbwr_buf_size=1048576
+lgwr_buf_size=8392704
+lgwr_cipher_buf_size=8392704
+lgwr_async_buf_size=16384
+lgwr_head_buf_size=16384
+large_pool_size=4194304
+buf_iocbs_size=1163264
+temp_pool_num=1
+temp_buf_size=4194304
+index_buf_size=16384
diff --git a/3rd/gstor/dependency/.gitignore b/3rd/gstor/dependency/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..ee8b54086055160a07a9f7e843692cf737d43ebe
--- /dev/null
+++ b/3rd/gstor/dependency/.gitignore
@@ -0,0 +1,8 @@
+install_comm/
+install_comm_dist/
+install_llt/
+install_llt_dist/
+*.o
+*.so
+*.a
+*.log
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/.gitignore b/3rd/gstor/dependency/Huawei_Secure_C/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..397b4a7624e35fa60563a9c03b1213d93f7b6546
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/.gitignore
@@ -0,0 +1 @@
+*.log
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/LICENSE b/3rd/gstor/dependency/Huawei_Secure_C/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..42f2a83670c666eb8a37c96c31eb0e7eb019d8a0
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/LICENSE
@@ -0,0 +1,124 @@
+木兰宽松许可证, 第2版
+
+2020年1月 http://license.coscl.org.cn/MulanPSL2
+
+您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
+
+0. 定义
+
+“软件” 是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
+
+“贡献” 是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
+
+“贡献者” 是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
+
+“法人实体” 是指提交贡献的机构及其“关联实体”。
+
+“关联实体” 是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
+
+1. 授予版权许可
+
+每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
+
+2. 授予专利许可
+
+每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
+
+3. 无商标许可
+
+“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。
+
+4. 分发限制
+
+您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
+
+5. 免责声明与责任限制
+
+“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
+
+6. 语言
+
+“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
+
+条款结束
+
+如何将木兰宽松许可证,第2版,应用到您的软件
+
+如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
+
+1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
+
+2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
+
+3, 请将如下声明文本放入每个源文件的头部注释中。
+
+Copyright (c) [Year] [name of copyright holder]
+[Software Name] is 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.
+Mulan Permissive Software License,Version 2
+Mulan Permissive Software License,Version 2 (Mulan PSL v2)
+
+January 2020 http://license.coscl.org.cn/MulanPSL2
+
+Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
+
+0. Definition
+
+Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
+
+Contribution means the copyrightable work licensed by a particular Contributor under this License.
+
+Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
+
+Legal Entity means the entity making a Contribution and all its Affiliates.
+
+Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, 'control' means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
+
+1. Grant of Copyright License
+
+Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
+
+2. Grant of Patent License
+
+Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
+
+3. No Trademark License
+
+No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4.
+
+4. Distribution Restriction
+
+You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
+
+5. Disclaimer of Warranty and Limitation of Liability
+
+THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT'S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+6. Language
+
+THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
+
+END OF THE TERMS AND CONDITIONS
+
+How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
+
+To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
+
+Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
+Create a file named "LICENSE" which contains the whole context of this License in the first directory of your software package;
+Attach the statement to the appropriate annotated syntax at the beginning of each source file.
+Copyright (c) [Year] [name of copyright holder]
+[Software Name] is 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.
\ No newline at end of file
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/MakefileCustom b/3rd/gstor/dependency/Huawei_Secure_C/MakefileCustom
new file mode 100644
index 0000000000000000000000000000000000000000..e4ae934a8e9c29792a9f404d608c0fa917f08836
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/MakefileCustom
@@ -0,0 +1,123 @@
+
+ANSI_OBJS = fscanf_s.o gets_s.o memcpy_s.o memmove_s.o memset_s.o scanf_s.o securecutil.o secureinput_a.o secureprintoutput_a.o snprintf_s.o sprintf_s.o sscanf_s.o strcat_s.o strcpy_s.o strncat_s.o strncpy_s.o strtok_s.o vfscanf_s.o vscanf_s.o vsnprintf_s.o vsprintf_s.o vsscanf_s.o
+
+UNICODE_OBJS = secureinput_w.o vswscanf_s.o vwscanf_s.o fwscanf_s.o swprintf_s.o swscanf_s.o vfwscanf_s.o vswprintf_s.o wcscat_s.o wcscpy_s.o wcsncat_s.o wcsncpy_s.o wcstok_s.o wmemcpy_s.o wmemmove_s.o wscanf_s.o secureprintoutput_w.o
+
+ALL_OBJS = $(ANSI_OBJS) $(UNICODE_OBJS)
+
+TESTOBJS = $(ALL_OBJS) test.o
+
+CC = gcc
+
+FLAGS = -I ../include -Wall -DNDEBUG -DSECUREC_WARP_OUTPUT -s -fstack-protector-strong -Wl,-z,relro,-z,now -O2
+#FLAGS = -Wall -W -I ../include -I. -g -D_DEBUG
+
+ARCH:=$(shell getconf LONG_BIT)
+
+ifeq ($(ARCH), 64)
+ FLAGS += -fPIC
+endif
+
+
+securecshare: $(ALL_OBJS)
+ $(CC) $(FLAGS) -shared -o libsecurec.so $(ALL_OBJS)
+ansisecurecshare: $(ANSI_OBJS)
+ $(CC) $(FLAGS) -shared -o libsecurec.so $(ANSI_OBJS)
+securecstatic: $(ALL_OBJS)
+ ar crv libsecurec.a $(ALL_OBJS)
+ ranlib libsecurec.a
+ansisecurecstatic: $(ANSI_OBJS)
+ ar crv libsecurec.a $(ANSI_OBJS)
+ ranlib libsecurec.a
+secureinput_a.o : secureinput_a.c secinput.h input.inl
+ $(CC) $(FLAGS) -c secureinput_a.c
+secureinput_w.o : secureinput_w.c secinput.h input.inl
+ $(CC) $(FLAGS) -c secureinput_w.c
+fscanf_s.o : fscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c fscanf_s.c
+fwscanf_s.o : fwscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c fwscanf_s.c
+gets_s.o : gets_s.c securecutil.h
+ $(CC) $(FLAGS) -c gets_s.c
+memcpy_s.o : memcpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c memcpy_s.c
+memmove_s.o : memmove_s.c securecutil.h
+ $(CC) $(FLAGS) -c memmove_s.c
+memset_s.o : memset_s.c securecutil.h
+ $(CC) $(FLAGS) -c memset_s.c
+scanf_s.o : scanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c scanf_s.c
+securecutil.o : securecutil.c securecutil.h secureprintoutput.h
+ $(CC) $(FLAGS) -c securecutil.c
+secureprintoutput_a.o : secureprintoutput_a.c securecutil.h secureprintoutput.h output.inl
+ $(CC) $(FLAGS) -c secureprintoutput_a.c
+secureprintoutput_w.o : secureprintoutput_w.c securecutil.h secureprintoutput.h output.inl
+ $(CC) $(FLAGS) -c secureprintoutput_w.c
+snprintf_s.o : snprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c snprintf_s.c
+sprintf_s.o : sprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c sprintf_s.c
+sscanf_s.o : sscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c sscanf_s.c
+strcat_s.o : strcat_s.c securecutil.h
+ $(CC) $(FLAGS) -c strcat_s.c
+strcpy_s.o : strcpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c strcpy_s.c
+strncat_s.o : strncat_s.c securecutil.h
+ $(CC) $(FLAGS) -c strncat_s.c
+strncpy_s.o : strncpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c strncpy_s.c
+strtok_s.o : strtok_s.c securecutil.h
+ $(CC) $(FLAGS) -c strtok_s.c
+swprintf_s.o : swprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c swprintf_s.c
+swscanf_s.o : swscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c swscanf_s.c
+vfscanf_s.o : vfscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vfscanf_s.c
+vfwscanf_s.o : vfwscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vfwscanf_s.c
+vscanf_s.o : vscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vscanf_s.c
+vsnprintf_s.o : vsnprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c vsnprintf_s.c
+vsprintf_s.o : vsprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c vsprintf_s.c
+vsscanf_s.o : vsscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vsscanf_s.c
+vswprintf_s.o : vswprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c vswprintf_s.c
+vswscanf_s.o : vswscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vswscanf_s.c
+vwscanf_s.o : vwscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c vwscanf_s.c
+wcscat_s.o : wcscat_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcscat_s.c
+wcscpy_s.o : wcscpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcscpy_s.c
+wcsncat_s.o : wcsncat_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcsncat_s.c
+wcsncpy_s.o : wcsncpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcsncpy_s.c
+wcstok_s.o : wcstok_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcstok_s.c
+wmemcpy_s.o : wmemcpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c wmemcpy_s.c
+wmemmove_s.o : wmemmove_s.c securecutil.h
+ $(CC) $(FLAGS) -c wmemmove_s.c
+wscanf_s.o : wscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c wscanf_s.c
+maketest: $(TESTOBJS)
+ $(CC) $(FLAGS) -o tst $(TESTOBJS)
+test.o : test.c
+ $(CC) $(FLAGS) -c test.c
+
+staticlink: $(TESTOBJS)
+ $(CC) $(FLAGS) -o tst test.c -L. -lsecurec.a
+dynLink:
+ gcc -g -o tst test.c -L. -l/home/l00254400/sec -lsecurec
+ gcc -g -o tst test.c -L. -lsecurec
+ gcc -g -o tst test.c -L. -l./securec
+clean:
+ rm *.o
+
\ No newline at end of file
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/README.en.md b/3rd/gstor/dependency/Huawei_Secure_C/README.en.md
new file mode 100644
index 0000000000000000000000000000000000000000..8ce43d768437aa4fb1002431fbd1efa19bb7f68f
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/README.en.md
@@ -0,0 +1,67 @@
+# bounds_checking_function
+
+#### Description
+
+- following the standard of C11 Annex K (bound-checking interfaces), functions of the common memory/string operation classes, such as memcpy_s, strcpy_s, are selected and implemented.
+
+- other standard functions in C11 Annex K will be analyzed in the future and implemented in this organization if necessary.
+
+- handles the release, update, and maintenance of bounds_checking_function.
+
+#### Function List
+
+- memcpy_s
+- wmemcpy_s
+- memmove_s
+- wmemmove_s
+- memset_s
+- strcpy_s
+- wcscpy_s
+- strncpy_s
+- wcsncpy_s
+- strcat_s
+- wcscat_s
+- strncat_s
+- wcsncat_s
+- strtok_s
+- cwcstok_s
+- sprintf_s
+- swprintf_s
+- vsprintf_s
+- vswprintf_s
+- snprintf_s
+- vsnprintf_s
+- scanf_s
+- wscanf_s
+- vscanf_s
+- vwscanf_s
+- fscanf_s
+- fwscanf_s
+- vfscanf_s
+- vfwscanf_s
+- sscanf_s
+- swscanf_s
+- vsscanf_s
+- vswscanf_s
+- gets_s
+
+
+#### Building
+
+- compilation steps
+
+1. Add all the .c files under /src to the source code listing for the build script.
+
+2. In the build options, specify the header directory and the build options required for the project (for example, add
+-Ipath_to_include -fstack-protector-strong -fPIC -Wall -D_FORTIFY_SOURCE=2 -O2 in CFLAGS).
+
+3. Generate .o files for each .c file.
+
+4. Generate static or shared libraries for .o files according to project requirements.
+
+- compiling examples:
+```
+gcc -o memcpy_s.o -c -Iinclude -fstack-protector-strong -fPIC -Wall -D_FORTIFY_SOURCE=2 -O2 src/memcpy_s.c
+```
+
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/README.md b/3rd/gstor/dependency/Huawei_Secure_C/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..2f19960dfe303fa687db0056cec5db2d4036880f
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/README.md
@@ -0,0 +1,61 @@
+# bounds_checking_function
+
+#### 介绍
+- 遵循C11 Annex K (Bounds-checking interfaces)的标准,选取并实现了常见的内存/字符串操作类的函数,如memcpy_s、strcpy_s等函数。
+- 未来将分析C11 Annex K中的其他标准函数,如果有必要,将在该组织中实现。
+- 处理边界检查函数的版本发布、更新以及维护。
+
+#### 函数清单
+
+- memcpy_s
+- wmemcpy_s
+- memmove_s
+- wmemmove_s
+- memset_s
+- strcpy_s
+- wcscpy_s
+- strncpy_s
+- wcsncpy_s
+- strcat_s
+- wcscat_s
+- strncat_s
+- wcsncat_s
+- strtok_s
+- cwcstok_s
+- sprintf_s
+- swprintf_s
+- vsprintf_s
+- vswprintf_s
+- snprintf_s
+- vsnprintf_s
+- scanf_s
+- wscanf_s
+- vscanf_s
+- vwscanf_s
+- fscanf_s
+- fwscanf_s
+- vfscanf_s
+- vfwscanf_s
+- sscanf_s
+- swscanf_s
+- vsscanf_s
+- vswscanf_s
+- gets_s
+
+
+#### 构建方法
+
+- 编译步骤
+
+1. 将src下的.c文件添加到构建脚本的源码清单中。
+
+2. 在编译选项中指定头文件目录以及项目需要的编译选项(例如:在CFLAGS中添加 -Ipath_to_include -fstack-protector-strong -fPIC -Wall -D_FORTIFY_SOURCE=2 -O2)。
+
+3. 为每个.c文件编译生成.o文件 。
+
+4. 根据项目需要将.o文件生成静态库或共享库使用。
+
+- 编译示例:
+```
+gcc -o memcpy_s.o -c -Iinclude -fstack-protector-strong -fPIC -Wall -D_FORTIFY_SOURCE=2 -O2 src/memcpy_s.c
+```
\ No newline at end of file
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/build.sh b/3rd/gstor/dependency/Huawei_Secure_C/build.sh
new file mode 100644
index 0000000000000000000000000000000000000000..0886d81301494282f4c09eff106c1f8e99d9f147
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/build.sh
@@ -0,0 +1,275 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
+# description: the script that make install securec
+# date: 2019-12-28
+# version: 1.01
+# history:
+# 2019-01-16 modify for securec_V100R001C01SPC006B002
+# 2019-12-28 change formatting and add copyright notice
+
+set -e
+######################################################################
+# Parameter setting
+######################################################################
+LOCAL_PATH=${0}
+FIRST_CHAR=$(expr substr "$LOCAL_PATH" 1 1)
+if [ "$FIRST_CHAR" = "/" ]; then
+ LOCAL_PATH=${0}
+else
+ LOCAL_PATH="$(pwd)/${LOCAL_PATH}"
+fi
+
+LOCAL_DIR=$(dirname "${LOCAL_PATH}")
+CONFIG_FILE_NAME=config.ini
+BUILD_OPTION=release
+SOURCE_CODE_PATH=.
+LOG_FILE=${LOCAL_DIR}/build_securec.log
+BUILD_FAILED=1
+
+ls ${LOCAL_DIR}/${CONFIG_FILE_NAME} > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+ die "[Error] the file ${CONFIG_FILE_NAME} not exist."
+fi
+
+COMPLIE_TYPE_LIST=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' | awk -F '=' '{print $2}' | sed 's/|/ /g')
+COMPONENT_NAME=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' | awk -F '=' '{print $1}' | awk -F '@' '{print $2}')
+COMPONENT_TYPE=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' | awk -F '@' '{print $1}')
+
+if [ "${COMPONENT_NAME}"X = ""X ]; then
+ die "[Error] get component name failed!"
+fi
+
+if [ "${COMPONENT_TYPE}"X = ""X ]; then
+ die "[Error] get component type failed!"
+fi
+
+ROOT_DIR="${LOCAL_DIR}/../../../"
+INSTALL_COMPOENT_PATH_NAME="${LOCAL_DIR}/../../output/kernel/${COMPONENT_TYPE}/${COMPONENT_NAME}"
+
+#######################################################################
+## print help information
+#######################################################################
+function print_help() {
+ echo "Usage: $0 [OPTION]
+ -h|--help show help information
+ -m|--build_option provode type of operation, values of paramenter is build, shrink, dist or clean
+ "
+}
+
+#######################################################################
+# Print log.
+#######################################################################
+log() {
+ echo "[Build securec] $(date +%y-%m-%d' '%T): $@"
+ echo "[Build securec] $(date +%y-%m-%d' '%T): $@" >> "$LOG_FILE" 2>&1
+}
+
+#######################################################################
+# print log and exit.
+#######################################################################
+die() {
+ log "$@"
+ echo "$@"
+ exit $BUILD_FAILED
+}
+
+#######################################################################
+# build and install component
+#######################################################################
+function build_component() {
+ cd ${LOCAL_DIR}
+ cp MakefileCustom ${LOCAL_DIR}/${SOURCE_CODE_PATH}/src
+ cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}/src
+ if [ $? -ne 0 ]; then
+ die "[Error] change dir to $SRC_DIR failed."
+ fi
+
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}; do
+ case "${COMPILE_TYPE}" in
+ release)
+ die "[Error] securec not supported build type."
+ ;;
+ debug)
+ die "[Error] securec not supported build type."
+ ;;
+ comm)
+ log "[Notice] securec \"make -f MakefileCustom securecstatic\" build started"
+ make -f MakefileCustom securecstatic
+ if [ $? -ne 0 ]; then
+ die "securec make failed."
+ fi
+ make -f MakefileCustom securecshare
+ if [ $? -ne 0 ]; then
+ die "securec make failed."
+ fi
+ log "[Notice] securec build using \"${COMPILE_TYPE}\" has been finished"
+ ;;
+ release_llt)
+ die "[Error] securec not supported build type."
+ ;;
+ debug_llt)
+ die "[Error] securec not supported build type."
+ ;;
+ llt)
+ die "[Error] securec not supported build type."
+ ;;
+ *)
+ log "Internal Error: option processing error: $1"
+ log "please write right paramenter in ${CONFIG_FILE_NAME}"
+ exit 1
+ ;;
+ esac
+ done
+}
+
+#######################################################################
+# choose the real files
+#######################################################################
+function shrink_component() {
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}; do
+ case "${COMPILE_TYPE}" in
+ comm)
+ mkdir -p ${LOCAL_DIR}/install_comm_dist/lib
+ cp ${LOCAL_DIR}/${SOURCE_CODE_PATH}/src/libsecurec.a ${LOCAL_DIR}/install_comm_dist/lib
+ mkdir -p ${LOCAL_DIR}/install_comm/lib
+ cp ${LOCAL_DIR}/${SOURCE_CODE_PATH}/src/libsecurec.a ${LOCAL_DIR}/install_comm/lib
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp ${LOCAL_DIR}/${SOURCE_CODE_PATH}/src/libsecurec.a ${LOCAL_DIR}/install_comm_dist/lib\" failed"
+ fi
+ ;;
+ release) ;;
+
+ debug) ;;
+
+ llt) ;;
+
+ release_llt) ;;
+
+ debug_llt) ;;
+
+ *) ;;
+ esac
+ log "[Notice] securec shrink using \"${COMPILE_TYPE}\" has been finished!"
+ done
+}
+
+##############################################################################################################
+# dist the real files to the matched path
+# we could makesure that $INSTALL_COMPOENT_PATH_NAME is not null, '.' or '/'
+##############################################################################################################
+function dist_component() {
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}; do
+ case "${COMPILE_TYPE}" in
+ comm)
+ mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/comm
+ rm -rf ${INSTALL_COMPOENT_PATH_NAME}/comm/*
+ cp -arxf ${LOCAL_DIR}/${SOURCE_CODE_PATH}/include ${INSTALL_COMPOENT_PATH_NAME}/comm
+ cp -r ${LOCAL_DIR}/install_comm_dist/* ${INSTALL_COMPOENT_PATH_NAME}/comm
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_comm_dist/* ${INSTALL_COMPOENT_PATH_NAME}/comm\" failed."
+ fi
+ mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/Dynamic_Lib
+ rm -rf ${INSTALL_COMPOENT_PATH_NAME}/Dynamic_Lib/*
+ cp -r ${LOCAL_DIR}/${SOURCE_CODE_PATH}/src/libsecurec.so ${INSTALL_COMPOENT_PATH_NAME}/Dynamic_Lib/
+ if [ $? -ne 0 ]; then
+ die "[Error] cp dynamic failed."
+ fi
+ ;;
+ release) ;;
+
+ debug) ;;
+
+ *) ;;
+ esac
+ log "[Notice] securec dist using \"${COMPILE_TYPE}\" has been finished!"
+ done
+}
+
+#######################################################################
+# clean component
+#######################################################################
+function clean_component() {
+ cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}/src
+ if [ $? -ne 0 ]; then
+ die "[Error] cd ${LOCAL_DIR}/${SOURCE_CODE_PATH} failed."
+ fi
+
+ make clean
+
+ cd ${LOCAL_DIR}
+ if [ $? -ne 0 ]; then
+ die "[Error] cd ${LOCAL_DIR} failed."
+ fi
+ [ -n "${SOURCE_CODE_PATH}" ] && rm -rf ${SOURCE_CODE_PATH}
+ rm -rf install_*
+
+ log "[Notice] securec clean has been finished!"
+}
+#######################################################################
+#######################################################################
+#######################################################################
+# main
+#######################################################################
+#######################################################################
+#######################################################################
+function main() {
+ case "${BUILD_OPTION}" in
+ build)
+ build_component
+ ;;
+ shrink)
+ shrink_component
+ ;;
+ dist)
+ dist_component
+ ;;
+ clean)
+ clean_component
+ ;;
+ all)
+ build_component
+ shrink_component
+ dist_component
+ #clean_component
+ ;;
+ *)
+ log "Internal Error: option processing error: $2"
+ log "please input right paramenter values build, shrink, dist or clean "
+ ;;
+ esac
+}
+
+########################################################################
+if [ $# = 0 ]; then
+ log "missing option"
+ print_help
+ exit 1
+fi
+
+##########################################################################
+#read command line paramenters
+##########################################################################
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h | --help)
+ print_help
+ exit 1
+ ;;
+ -m | --build_option)
+ if [ "$2"X = X ]; then
+ die "no given version number values"
+ fi
+ BUILD_OPTION=$2
+ shift 2
+ ;;
+ *)
+ log "Internal Error: option processing error: $1" 1>&2
+ log "please input right paramtenter, the following command may help you"
+ log "./build.sh --help or ./build.sh -h"
+ exit 1
+ ;;
+ esac
+done
+
+###########################################################################
+main
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/config.ini b/3rd/gstor/dependency/Huawei_Secure_C/config.ini
new file mode 100644
index 0000000000000000000000000000000000000000..d5fd097447473cbf0f4b9eb3a3bb18b3fde4921e
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/config.ini
@@ -0,0 +1,5 @@
+###############################
+# securec support
+###############################
+platform@Huawei_Secure_C=comm
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/include/securec.h b/3rd/gstor/dependency/Huawei_Secure_C/include/securec.h
new file mode 100644
index 0000000000000000000000000000000000000000..e0a977e275c400445b2bd61d9858c25c15785739
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/include/securec.h
@@ -0,0 +1,630 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: The user of this secure c library should include this header file in you source code.
+ * This header file declare all supported API prototype of the library,
+ * such as memcpy_s, strcpy_s, wcscpy_s,strcat_s, strncat_s, sprintf_s, scanf_s, and so on.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27
+#define SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27
+
+#include "securectype.h"
+#ifndef SECUREC_HAVE_STDARG_H
+#define SECUREC_HAVE_STDARG_H 1
+#endif
+
+#if SECUREC_HAVE_STDARG_H
+#include
+#endif
+
+#ifndef SECUREC_HAVE_ERRNO_H
+#define SECUREC_HAVE_ERRNO_H 1
+#endif
+
+/* EINVAL ERANGE may defined in errno.h */
+#if SECUREC_HAVE_ERRNO_H
+#if SECUREC_IN_KERNEL
+#include
+#else
+#include
+#endif
+#endif
+
+/* Define error code */
+#if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \
+ (defined(__STDC_WANT_LIB_EXT1__) && (!__STDC_WANT_LIB_EXT1__))
+#ifndef SECUREC_DEFINED_ERRNO_TYPE
+#define SECUREC_DEFINED_ERRNO_TYPE
+/* Just check whether macrodefinition exists. */
+#ifndef errno_t
+typedef int errno_t;
+#endif
+#endif
+#endif
+
+/* Success */
+#ifndef EOK
+#define EOK 0
+#endif
+
+#ifndef EINVAL
+/* The src buffer is not correct and destination buffer cant not be reset */
+#define EINVAL 22
+#endif
+
+#ifndef EINVAL_AND_RESET
+/* Once the error is detected, the dest buffer must be reseted! Value is 22 or 128 */
+#define EINVAL_AND_RESET 150
+#endif
+
+#ifndef ERANGE
+/* The destination buffer is not long enough and destination buffer can not be reset */
+#define ERANGE 34
+#endif
+
+#ifndef ERANGE_AND_RESET
+/* Once the error is detected, the dest buffer must be reseted! Value is 34 or 128 */
+#define ERANGE_AND_RESET 162
+#endif
+
+#ifndef EOVERLAP_AND_RESET
+/* Once the buffer overlap is detected, the dest buffer must be reseted! Value is 54 or 128 */
+#define EOVERLAP_AND_RESET 182
+#endif
+
+/* If you need export the function of this library in Win32 dll, use __declspec(dllexport) */
+#ifndef SECUREC_API
+#if defined(SECUREC_DLL_EXPORT)
+#define SECUREC_API __declspec(dllexport)
+#elif defined(SECUREC_DLL_IMPORT)
+#define SECUREC_API __declspec(dllimport)
+#else
+/*
+ * Standardized function declaration. If a security function is declared in the your code,
+ * it may cause a compilation alarm,Please delete the security function you declared.
+ * Adding extern under windows will cause the system to have inline functions to expand,
+ * so do not add the extern in default
+ */
+#if defined(_MSC_VER)
+#define SECUREC_API
+#else
+#define SECUREC_API extern
+#endif
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ /*
+ * Description: The GetHwSecureCVersion function get SecureC Version string and version number.
+ * Parameter: verNumber - to store version number (for example value is 0x500 | 0xa)
+ * Return: version string
+ */
+ SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber);
+
+#if SECUREC_ENABLE_MEMSET
+ /*
+ * Description: The memset_s function copies the value of c (converted to an unsigned char) into each of
+ * the first count characters of the object pointed to by dest.
+ * Parameter: dest - destination address
+ * Parameter: destMax - The maximum length of destination buffer
+ * Parameter: c - the value to be copied
+ * Parameter: count - copies count bytes of value to dest
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count);
+#endif
+
+#ifndef SECUREC_ONLY_DECLARE_MEMSET
+#define SECUREC_ONLY_DECLARE_MEMSET 0
+#endif
+
+#if !SECUREC_ONLY_DECLARE_MEMSET
+
+#if SECUREC_ENABLE_MEMMOVE
+ /*
+ * Description: The memmove_s function copies n characters from the object pointed to by src
+ * into the object pointed to by dest.
+ * Parameter: dest - destination address
+ * Parameter: destMax - The maximum length of destination buffer
+ * Parameter: src - source address
+ * Parameter: count - copies count bytes from the src
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count);
+#endif
+
+#if SECUREC_ENABLE_MEMCPY
+ /*
+ * Description: The memcpy_s function copies n characters from the object pointed to
+ * by src into the object pointed to by dest.
+ * Parameter: dest - destination address
+ * Parameter: destMax - The maximum length of destination buffer
+ * Parameter: src - source address
+ * Parameter: count - copies count bytes from the src
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count);
+#endif
+
+#if SECUREC_ENABLE_STRCPY
+ /*
+ * Description: The strcpy_s function copies the string pointed to by strSrc (including
+ * the terminating null character) into the array pointed to by strDest
+ * Parameter: strDest - destination address
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
+ * Parameter: strSrc - source address
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc);
+#endif
+
+#if SECUREC_ENABLE_STRNCPY
+ /*
+ * Description: The strncpy_s function copies not more than n successive characters (not including
+ * the terminating null character) from the array pointed to by strSrc to the array pointed to by strDest.
+ * Parameter: strDest - destination address
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
+ * Parameter: strSrc - source address
+ * Parameter: count - copies count characters from the src
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
+#endif
+
+#if SECUREC_ENABLE_STRCAT
+ /*
+ * Description: The strcat_s function appends a copy of the string pointed to by strSrc (including
+ * the terminating null character) to the end of the string pointed to by strDest.
+ * Parameter: strDest - destination address
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide character)
+ * Parameter: strSrc - source address
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc);
+#endif
+
+#if SECUREC_ENABLE_STRNCAT
+ /*
+ * Description: The strncat_s function appends not more than n successive characters (not including
+ * the terminating null character)
+ * from the array pointed to by strSrc to the end of the string pointed to by strDest.
+ * Parameter: strDest - destination address
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
+ * Parameter: strSrc - source address
+ * Parameter: count - copies count characters from the src
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
+#endif
+
+#if SECUREC_ENABLE_VSPRINTF
+ /*
+ * Description: The vsprintf_s function is equivalent to the vsprintf function except for the parameter destMax
+ * and the explicit runtime-constraints violation
+ * Parameter: strDest - produce output according to a format ,write to the character string strDest.
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte)
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of characters printed(not including the terminating null byte '\0'),
+ * If an error occurred Return: -1.
+ */
+ SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format,
+ va_list argList) SECUREC_ATTRIBUTE(3, 0);
+#endif
+
+#if SECUREC_ENABLE_SPRINTF
+ /*
+ * Description: The sprintf_s function is equivalent to the sprintf function except for the parameter destMax
+ * and the explicit runtime-constraints violation
+ * Parameter: strDest - produce output according to a format ,write to the character string strDest.
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
+ * Parameter: format - fromat string
+ * Return: the number of characters printed(not including the terminating null byte '\0'),
+ * If an error occurred Return: -1.
+ */
+ SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
+#endif
+
+#if SECUREC_ENABLE_VSNPRINTF
+ /*
+ * Description: The vsnprintf_s function is equivalent to the vsnprintf function except for
+ * the parameter destMax/count and the explicit runtime-constraints violation
+ * Parameter: strDest - produce output according to a format ,write to the character string strDest.
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
+ * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of characters printed(not including the terminating null byte '\0'),
+ * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
+ */
+ SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
+ va_list argList) SECUREC_ATTRIBUTE(4, 0);
+#endif
+
+#if SECUREC_ENABLE_SNPRINTF
+ /*
+ * Description: The snprintf_s function is equivalent to the snprintf function except for
+ * the parameter destMax/count and the explicit runtime-constraints violation
+ * Parameter: strDest - produce output according to a format ,write to the character string strDest.
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
+ * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
+ * Parameter: format - fromat string
+ * Return: the number of characters printed(not including the terminating null byte '\0'),
+ * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
+ */
+ SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
+ ...) SECUREC_ATTRIBUTE(4, 5);
+#endif
+
+#if SECUREC_SNPRINTF_TRUNCATED
+ /*
+ * Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except
+ * no count parameter and return value
+ * Parameter: strDest - produce output according to a format ,write to the character string strDest
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of characters printed(not including the terminating null byte '\0'),
+ * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
+ */
+ SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
+ va_list argList) SECUREC_ATTRIBUTE(3, 0);
+
+ /*
+ * Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except
+ * no count parameter and return value
+ * Parameter: strDest - produce output according to a format ,write to the character string strDest.
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
+ * Parameter: format - fromat string
+ * Return: the number of characters printed(not including the terminating null byte '\0'),
+ * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
+ */
+ SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax,
+ const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
+#endif
+
+#if SECUREC_ENABLE_SCANF
+ /*
+ * Description: The scanf_s function is equivalent to fscanf_s with the argument stdin
+ * interposed before the arguments to scanf_s
+ * Parameter: format - fromat string
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int scanf_s(const char *format, ...);
+#endif
+
+#if SECUREC_ENABLE_VSCANF
+ /*
+ * Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int vscanf_s(const char *format, va_list argList);
+#endif
+
+#if SECUREC_ENABLE_SSCANF
+ /*
+ * Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a
+ * string (specified by the argument buffer) rather than from a stream
+ * Parameter: buffer - read character from buffer
+ * Parameter: format - fromat string
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int sscanf_s(const char *buffer, const char *format, ...);
+#endif
+
+#if SECUREC_ENABLE_VSSCANF
+ /*
+ * Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list
+ * replaced by argList
+ * Parameter: buffer - read character from buffer
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList);
+#endif
+
+#if SECUREC_ENABLE_FSCANF
+ /*
+ * Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers
+ * apply to a pair of arguments (unless assignment suppression is indicated by a*)
+ * Parameter: stream - stdio file stream
+ * Parameter: format - fromat string
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int fscanf_s(FILE *stream, const char *format, ...);
+#endif
+
+#if SECUREC_ENABLE_VFSCANF
+ /*
+ * Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list
+ * replaced by argList
+ * Parameter: stream - stdio file stream
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList);
+#endif
+
+#if SECUREC_ENABLE_STRTOK
+ /*
+ * Description: The strtok_s function parses a string into a sequence of strToken,
+ * replace all characters in strToken string that match to strDelimit set with 0.
+ * On the first call to strtok_s the string to be parsed should be specified in strToken.
+ * In each subsequent call that should parse the same string, strToken should be NULL
+ * Parameter: strToken - the string to be delimited
+ * Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
+ * Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
+ * Return: On the first call returns the address of the first non \0 character, otherwise NULL is returned.
+ * In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
+ * return NULL if the *context string length is equal 0, otherwise return *context.
+ */
+ SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context);
+#endif
+
+#if SECUREC_ENABLE_GETS && !SECUREC_IN_KERNEL
+ /*
+ * Description: The gets_s function reads at most one less than the number of characters specified
+ * by destMax from the stream pointed to by stdin, into the array pointed to by buffer
+ * Parameter: buffer - destination address
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
+ * Return: buffer if there was no runtime-constraint violation,If an error occurred Return: NULL.
+ */
+ SECUREC_API char *gets_s(char *buffer, size_t destMax);
+#endif
+
+#if SECUREC_ENABLE_WCHAR_FUNC
+#if SECUREC_ENABLE_MEMCPY
+ /*
+ * Description: The wmemcpy_s function copies n successive wide characters from the object pointed to
+ * by src into the object pointed to by dest.
+ * Parameter: dest - destination address
+ * Parameter: destMax - The maximum length of destination buffer
+ * Parameter: src - source address
+ * Parameter: count - copies count wide characters from the src
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
+#endif
+
+#if SECUREC_ENABLE_MEMMOVE
+ /*
+ * Description: The wmemmove_s function copies n successive wide characters from the object
+ * pointed to by src into the object pointed to by dest.
+ * Parameter: dest - destination address
+ * Parameter: destMax - The maximum length of destination buffer
+ * Parameter: src - source address
+ * Parameter: count - copies count wide characters from the src
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
+#endif
+
+#if SECUREC_ENABLE_STRCPY
+ /*
+ * Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating
+ * null wide character) into the array pointed to by strDest
+ * Parameter: strDest - destination address
+ * Parameter: destMax - The maximum length of destination buffer
+ * Parameter: strSrc - source address
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
+#endif
+
+#if SECUREC_ENABLE_STRNCPY
+ /*
+ * 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
+ * Parameter: strDest - destination address
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
+ * Parameter: strSrc - source address
+ * Parameter: count - copies count wide characters from the src
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
+#endif
+
+#if SECUREC_ENABLE_STRCAT
+ /*
+ * 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
+ * Parameter: strDest - destination address
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
+ * Parameter: strSrc - source address
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
+#endif
+
+#if SECUREC_ENABLE_STRNCAT
+ /*
+ * 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
+ * by strDest.
+ * Parameter: strDest - destination address
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
+ * Parameter: strSrc - source address
+ * Parameter: count - copies count wide characters from the src
+ * Return: EOK if there was no runtime-constraint violation
+ */
+ SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
+#endif
+
+#if SECUREC_ENABLE_STRTOK
+ /*
+ * Description: The wcstok_s function is the wide-character equivalent of the strtok_s function
+ * Parameter: strToken - the string to be delimited
+ * Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
+ * Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
+ * Return: a pointer to the first character of a token, or a null pointer if there is no token
+ * or there is a runtime-constraint violation.
+ */
+ SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context);
+#endif
+
+#if SECUREC_ENABLE_VSPRINTF
+ /*
+ * 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
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null )
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of characters printed(not including the terminating null wide characte),
+ * If an error occurred Return: -1.
+ */
+ SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList);
+#endif
+
+#if SECUREC_ENABLE_SPRINTF
+
+ /*
+ * 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
+ * Parameter: destMax - The maximum length of destination buffer(including the terminating null )
+ * Parameter: format - fromat string
+ * Return: the number of characters printed(not including the terminating null wide characte),
+ * If an error occurred Return: -1.
+ */
+ SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...);
+#endif
+
+#if SECUREC_ENABLE_FSCANF
+ /*
+ * Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function
+ * Parameter: stream - stdio file stream
+ * Parameter: format - fromat string
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...);
+#endif
+
+#if SECUREC_ENABLE_VFSCANF
+ /*
+ * Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
+ * Parameter: stream - stdio file stream
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList);
+#endif
+
+#if SECUREC_ENABLE_SCANF
+ /*
+ * Description: The wscanf_s function is the wide-character equivalent of the scanf_s function
+ * Parameter: format - fromat string
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int wscanf_s(const wchar_t *format, ...);
+#endif
+
+#if SECUREC_ENABLE_VSCANF
+ /*
+ * Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList);
+#endif
+
+#if SECUREC_ENABLE_SSCANF
+ /*
+ * Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function
+ * Parameter: buffer - read character from buffer
+ * Parameter: format - fromat string
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...);
+#endif
+
+#if SECUREC_ENABLE_VSSCANF
+ /*
+ * Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function
+ * Parameter: buffer - read character from buffer
+ * Parameter: format - fromat string
+ * Parameter: argList - instead of a variable number of arguments
+ * Return: the number of input items assigned, If an error occurred Return: -1.
+ */
+ SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList);
+#endif
+#endif /* SECUREC_ENABLE_WCHAR_FUNC */
+#endif
+
+ /* Those functions are used by macro ,must declare hare , also for without function declaration warning */
+ extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count);
+ extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc);
+
+#if SECUREC_WITH_PERFORMANCE_ADDONS
+ /* Those functions are used by macro */
+ extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count);
+ extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count);
+ extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count);
+ extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count);
+
+/* The strcpy_sp is a macro, not a function in performance optimization mode. */
+#define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
+ __builtin_constant_p((src))) ? \
+ SECUREC_STRCPY_SM((dest), (destMax), (src)) : \
+ strcpy_s((dest), (destMax), (src)))
+
+/* The strncpy_sp is a macro, not a function in performance optimization mode. */
+#define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
+ __builtin_constant_p((destMax)) && \
+ __builtin_constant_p((src))) ? \
+ SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \
+ strncpy_s((dest), (destMax), (src), (count)))
+
+/* The strcat_sp is a macro, not a function in performance optimization mode. */
+#define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
+ __builtin_constant_p((src))) ? \
+ SECUREC_STRCAT_SM((dest), (destMax), (src)) : \
+ strcat_s((dest), (destMax), (src)))
+
+/* The strncat_sp is a macro, not a function in performance optimization mode. */
+#define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
+ __builtin_constant_p((destMax)) && \
+ __builtin_constant_p((src))) ? \
+ SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \
+ strncat_s((dest), (destMax), (src), (count)))
+
+/* The memcpy_sp is a macro, not a function in performance optimization mode. */
+#define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \
+ (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \
+ (__builtin_constant_p((destMax)) ? \
+ (((size_t)(destMax) > 0 && \
+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
+ memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \
+ memcpy_sOptAsm((dest), (destMax), (src), (count))))
+
+/* The memset_sp is a macro, not a function in performance optimization mode. */
+#define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \
+ (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \
+ (__builtin_constant_p((destMax)) ? \
+ (((((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
+ memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \
+ memset_sOptAsm((dest), (destMax), (c), (count))))
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/include/securectype.h b/3rd/gstor/dependency/Huawei_Secure_C/include/securectype.h
new file mode 100644
index 0000000000000000000000000000000000000000..17cca940d83f611bdbbaeca2552ed3bb937a9113
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/include/securectype.h
@@ -0,0 +1,570 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: Define internal used macro and data type. The marco of SECUREC_ON_64BITS
+ * will be determined in this header file, which is a switch for part
+ * of code. Some macro are used to supress warning by MS compiler.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7
+#define SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7
+
+#ifndef SECUREC_USING_STD_SECURE_LIB
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+#if defined(__STDC_WANT_SECURE_LIB__) && (!__STDC_WANT_SECURE_LIB__)
+/* Security functions have been provided since vs2005, default use of system library functions */
+#define SECUREC_USING_STD_SECURE_LIB 0
+#else
+#define SECUREC_USING_STD_SECURE_LIB 1
+#endif
+#else
+#define SECUREC_USING_STD_SECURE_LIB 0
+#endif
+#endif
+
+/* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */
+#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (!SECUREC_USING_STD_SECURE_LIB)
+#ifndef SECUREC_DISABLE_CRT_FUNC
+#define SECUREC_DISABLE_CRT_FUNC 1
+#endif
+#ifndef SECUREC_DISABLE_CRT_IMP
+#define SECUREC_DISABLE_CRT_IMP 1
+#endif
+#else /* MSC VER */
+#ifndef SECUREC_DISABLE_CRT_FUNC
+#define SECUREC_DISABLE_CRT_FUNC 0
+#endif
+#ifndef SECUREC_DISABLE_CRT_IMP
+#define SECUREC_DISABLE_CRT_IMP 0
+#endif
+#endif
+
+#if SECUREC_DISABLE_CRT_FUNC
+#ifdef __STDC_WANT_SECURE_LIB__
+#undef __STDC_WANT_SECURE_LIB__
+#endif
+#define __STDC_WANT_SECURE_LIB__ 0
+#endif
+
+#if SECUREC_DISABLE_CRT_IMP
+#ifdef _CRTIMP_ALTERNATIVE
+#undef _CRTIMP_ALTERNATIVE
+#endif
+#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */
+#endif
+
+/* Compile in kernel under macro control */
+#ifndef SECUREC_IN_KERNEL
+#ifdef __KERNEL__
+#define SECUREC_IN_KERNEL 1
+#else
+#define SECUREC_IN_KERNEL 0
+#endif
+#endif
+
+#if SECUREC_IN_KERNEL
+#ifndef SECUREC_ENABLE_SCANF_FILE
+#define SECUREC_ENABLE_SCANF_FILE 0
+#endif
+#ifndef SECUREC_ENABLE_WCHAR_FUNC
+#define SECUREC_ENABLE_WCHAR_FUNC 0
+#endif
+#else /* SECUREC_IN_KERNEL */
+#ifndef SECUREC_ENABLE_SCANF_FILE
+#define SECUREC_ENABLE_SCANF_FILE 1
+#endif
+#ifndef SECUREC_ENABLE_WCHAR_FUNC
+#define SECUREC_ENABLE_WCHAR_FUNC 1
+#endif
+#endif
+
+/* Default secure function declaration, default declarations for non-standard functions */
+#ifndef SECUREC_SNPRINTF_TRUNCATED
+#define SECUREC_SNPRINTF_TRUNCATED 1
+#endif
+
+#if SECUREC_USING_STD_SECURE_LIB
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+/* Declare secure functions that are not available in the VS compiler */
+#ifndef SECUREC_ENABLE_MEMSET
+#define SECUREC_ENABLE_MEMSET 1
+#endif
+/* VS 2005 have vsnprintf_s function */
+#ifndef SECUREC_ENABLE_VSNPRINTF
+#define SECUREC_ENABLE_VSNPRINTF 0
+#endif
+#ifndef SECUREC_ENABLE_SNPRINTF
+/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */
+#define snprintf_s _snprintf_s
+#define SECUREC_ENABLE_SNPRINTF 0
+#endif
+/* Before VS 2010 do not have v functions */
+#if _MSC_VER <= 1600 || defined(SECUREC_FOR_V_SCANFS)
+#ifndef SECUREC_ENABLE_VFSCANF
+#define SECUREC_ENABLE_VFSCANF 1
+#endif
+#ifndef SECUREC_ENABLE_VSCANF
+#define SECUREC_ENABLE_VSCANF 1
+#endif
+#ifndef SECUREC_ENABLE_VSSCANF
+#define SECUREC_ENABLE_VSSCANF 1
+#endif
+#endif
+
+#else /* MSC VER */
+#ifndef SECUREC_ENABLE_MEMSET
+#define SECUREC_ENABLE_MEMSET 0
+#endif
+#ifndef SECUREC_ENABLE_SNPRINTF
+#define SECUREC_ENABLE_SNPRINTF 0
+#endif
+#ifndef SECUREC_ENABLE_VSNPRINTF
+#define SECUREC_ENABLE_VSNPRINTF 0
+#endif
+#endif
+
+#ifndef SECUREC_ENABLE_MEMMOVE
+#define SECUREC_ENABLE_MEMMOVE 0
+#endif
+#ifndef SECUREC_ENABLE_MEMCPY
+#define SECUREC_ENABLE_MEMCPY 0
+#endif
+#ifndef SECUREC_ENABLE_STRCPY
+#define SECUREC_ENABLE_STRCPY 0
+#endif
+#ifndef SECUREC_ENABLE_STRNCPY
+#define SECUREC_ENABLE_STRNCPY 0
+#endif
+#ifndef SECUREC_ENABLE_STRCAT
+#define SECUREC_ENABLE_STRCAT 0
+#endif
+#ifndef SECUREC_ENABLE_STRNCAT
+#define SECUREC_ENABLE_STRNCAT 0
+#endif
+#ifndef SECUREC_ENABLE_SPRINTF
+#define SECUREC_ENABLE_SPRINTF 0
+#endif
+#ifndef SECUREC_ENABLE_VSPRINTF
+#define SECUREC_ENABLE_VSPRINTF 0
+#endif
+#ifndef SECUREC_ENABLE_SSCANF
+#define SECUREC_ENABLE_SSCANF 0
+#endif
+#ifndef SECUREC_ENABLE_VSSCANF
+#define SECUREC_ENABLE_VSSCANF 0
+#endif
+#ifndef SECUREC_ENABLE_SCANF
+#define SECUREC_ENABLE_SCANF 0
+#endif
+#ifndef SECUREC_ENABLE_VSCANF
+#define SECUREC_ENABLE_VSCANF 0
+#endif
+
+#ifndef SECUREC_ENABLE_FSCANF
+#define SECUREC_ENABLE_FSCANF 0
+#endif
+#ifndef SECUREC_ENABLE_VFSCANF
+#define SECUREC_ENABLE_VFSCANF 0
+#endif
+#ifndef SECUREC_ENABLE_STRTOK
+#define SECUREC_ENABLE_STRTOK 0
+#endif
+#ifndef SECUREC_ENABLE_GETS
+#define SECUREC_ENABLE_GETS 0
+#endif
+
+#else /* SECUREC USE STD SECURE LIB */
+
+#ifndef SECUREC_ENABLE_MEMSET
+#define SECUREC_ENABLE_MEMSET 1
+#endif
+#ifndef SECUREC_ENABLE_MEMMOVE
+#define SECUREC_ENABLE_MEMMOVE 1
+#endif
+#ifndef SECUREC_ENABLE_MEMCPY
+#define SECUREC_ENABLE_MEMCPY 1
+#endif
+#ifndef SECUREC_ENABLE_STRCPY
+#define SECUREC_ENABLE_STRCPY 1
+#endif
+#ifndef SECUREC_ENABLE_STRNCPY
+#define SECUREC_ENABLE_STRNCPY 1
+#endif
+#ifndef SECUREC_ENABLE_STRCAT
+#define SECUREC_ENABLE_STRCAT 1
+#endif
+#ifndef SECUREC_ENABLE_STRNCAT
+#define SECUREC_ENABLE_STRNCAT 1
+#endif
+#ifndef SECUREC_ENABLE_SPRINTF
+#define SECUREC_ENABLE_SPRINTF 1
+#endif
+#ifndef SECUREC_ENABLE_VSPRINTF
+#define SECUREC_ENABLE_VSPRINTF 1
+#endif
+#ifndef SECUREC_ENABLE_SNPRINTF
+#define SECUREC_ENABLE_SNPRINTF 1
+#endif
+#ifndef SECUREC_ENABLE_VSNPRINTF
+#define SECUREC_ENABLE_VSNPRINTF 1
+#endif
+#ifndef SECUREC_ENABLE_SSCANF
+#define SECUREC_ENABLE_SSCANF 1
+#endif
+#ifndef SECUREC_ENABLE_VSSCANF
+#define SECUREC_ENABLE_VSSCANF 1
+#endif
+#ifndef SECUREC_ENABLE_SCANF
+#if SECUREC_ENABLE_SCANF_FILE
+#define SECUREC_ENABLE_SCANF 1
+#else
+#define SECUREC_ENABLE_SCANF 0
+#endif
+#endif
+#ifndef SECUREC_ENABLE_VSCANF
+#if SECUREC_ENABLE_SCANF_FILE
+#define SECUREC_ENABLE_VSCANF 1
+#else
+#define SECUREC_ENABLE_VSCANF 0
+#endif
+#endif
+
+#ifndef SECUREC_ENABLE_FSCANF
+#if SECUREC_ENABLE_SCANF_FILE
+#define SECUREC_ENABLE_FSCANF 1
+#else
+#define SECUREC_ENABLE_FSCANF 0
+#endif
+#endif
+#ifndef SECUREC_ENABLE_VFSCANF
+#if SECUREC_ENABLE_SCANF_FILE
+#define SECUREC_ENABLE_VFSCANF 1
+#else
+#define SECUREC_ENABLE_VFSCANF 0
+#endif
+#endif
+
+#ifndef SECUREC_ENABLE_STRTOK
+#define SECUREC_ENABLE_STRTOK 1
+#endif
+#ifndef SECUREC_ENABLE_GETS
+#define SECUREC_ENABLE_GETS 1
+#endif
+#endif /* SECUREC_USE_STD_SECURE_LIB */
+
+#if !SECUREC_ENABLE_SCANF_FILE
+#if SECUREC_ENABLE_FSCANF
+#undef SECUREC_ENABLE_FSCANF
+#define SECUREC_ENABLE_FSCANF 0
+#endif
+#if SECUREC_ENABLE_VFSCANF
+#undef SECUREC_ENABLE_VFSCANF
+#define SECUREC_ENABLE_VFSCANF 0
+#endif
+#if SECUREC_ENABLE_SCANF
+#undef SECUREC_ENABLE_SCANF
+#define SECUREC_ENABLE_SCANF 0
+#endif
+#if SECUREC_ENABLE_FSCANF
+#undef SECUREC_ENABLE_FSCANF
+#define SECUREC_ENABLE_FSCANF 0
+#endif
+
+#endif
+
+#if SECUREC_IN_KERNEL
+#include
+#include
+#else
+#ifndef SECUREC_HAVE_STDIO_H
+#define SECUREC_HAVE_STDIO_H 1
+#endif
+#ifndef SECUREC_HAVE_STRING_H
+#define SECUREC_HAVE_STRING_H 1
+#endif
+#ifndef SECUREC_HAVE_STDLIB_H
+#define SECUREC_HAVE_STDLIB_H 1
+#endif
+#if SECUREC_HAVE_STDIO_H
+#include
+#endif
+#if SECUREC_HAVE_STRING_H
+#include
+#endif
+#if SECUREC_HAVE_STDLIB_H
+#include
+#endif
+#endif
+
+/*
+ * If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable.
+ * The macro is automatically closed on the windows platform and linux kernel
+ */
+#ifndef SECUREC_WITH_PERFORMANCE_ADDONS
+#if SECUREC_IN_KERNEL
+#define SECUREC_WITH_PERFORMANCE_ADDONS 0
+#else
+#define SECUREC_WITH_PERFORMANCE_ADDONS 1
+#endif
+#endif
+
+/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */
+#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
+#ifndef SECUREC_COMPATIBLE_WIN_FORMAT
+#define SECUREC_COMPATIBLE_WIN_FORMAT
+#endif
+#endif
+
+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+/* On windows platform, can't use optimized function for there is no __builtin_constant_p like function */
+/* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */
+#ifdef SECUREC_WITH_PERFORMANCE_ADDONS
+#undef SECUREC_WITH_PERFORMANCE_ADDONS
+#define SECUREC_WITH_PERFORMANCE_ADDONS 0
+#endif
+#endif
+
+#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \
+ defined(SECUREC_VXWORKS_VERSION_5_4)
+#ifndef SECUREC_VXWORKS_PLATFORM
+#define SECUREC_VXWORKS_PLATFORM
+#endif
+#endif
+
+/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */
+#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && !defined(SECUREC_VXWORKS_PLATFORM)
+#ifndef SECUREC_COMPATIBLE_LINUX_FORMAT
+#define SECUREC_COMPATIBLE_LINUX_FORMAT
+#endif
+#endif
+
+#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
+#ifndef SECUREC_HAVE_STDDEF_H
+#define SECUREC_HAVE_STDDEF_H 1
+#endif
+/* Some system may no stddef.h */
+#if SECUREC_HAVE_STDDEF_H
+#if !SECUREC_IN_KERNEL
+#include
+#endif
+#endif
+#endif
+
+/*
+ * Add the -DSECUREC_SUPPORT_FORMAT_WARNING=1 compiler option to supoort -Wformat=2.
+ * Default does not check the format is that the same data type in the actual code.
+ * In the product is different in the original data type definition of VxWorks and Linux.
+ */
+#ifndef SECUREC_SUPPORT_FORMAT_WARNING
+#define SECUREC_SUPPORT_FORMAT_WARNING 0
+#endif
+
+#if SECUREC_SUPPORT_FORMAT_WARNING
+#define SECUREC_ATTRIBUTE(x, y) __attribute__((format(printf, (x), (y))))
+#else
+#define SECUREC_ATTRIBUTE(x, y)
+#endif
+
+/*
+ * Add the -DSECUREC_SUPPORT_BUILTIN_EXPECT=0 compiler option, if complier can not support __builtin_expect.
+ */
+#ifndef SECUREC_SUPPORT_BUILTIN_EXPECT
+#define SECUREC_SUPPORT_BUILTIN_EXPECT 1
+#endif
+
+#if SECUREC_SUPPORT_BUILTIN_EXPECT && defined(__GNUC__) && ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)))
+/*
+ * This is a built-in function that can be used without a declaration, if warning for declaration not found occurred,
+ * you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options
+ */
+#ifdef SECUREC_NEED_BUILTIN_EXPECT_DECLARE
+long __builtin_expect(long exp, long c);
+#endif
+
+#define SECUREC_LIKELY(x) __builtin_expect(!!(x), 1)
+#define SECUREC_UNLIKELY(x) __builtin_expect(!!(x), 0)
+#else
+#define SECUREC_LIKELY(x) (x)
+#define SECUREC_UNLIKELY(x) (x)
+#endif
+
+/* Define the max length of the string */
+#ifndef SECUREC_STRING_MAX_LEN
+#define SECUREC_STRING_MAX_LEN 0x7fffffffUL
+#endif
+#define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / sizeof(wchar_t))
+
+/* Add SECUREC_MEM_MAX_LEN for memcpy and memmove */
+#ifndef SECUREC_MEM_MAX_LEN
+#define SECUREC_MEM_MAX_LEN 0x7fffffffUL
+#endif
+#define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t))
+
+#if SECUREC_STRING_MAX_LEN > 0x7fffffffUL
+#error "max string is 2G"
+#endif
+
+#if (defined(__GNUC__) && defined(__SIZEOF_POINTER__))
+#if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8)
+#error "unsupported system"
+#endif
+#endif
+
+#if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64)
+#define SECUREC_ON_64BITS
+#endif
+
+#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__))
+#if __SIZEOF_POINTER__ == 8
+#define SECUREC_ON_64BITS
+#endif
+#endif
+
+#if defined(__SVR4) || defined(__svr4__)
+#define SECUREC_ON_SOLARIS
+#endif
+
+#if (defined(__hpux) || defined(_AIX) || defined(SECUREC_ON_SOLARIS))
+#define SECUREC_ON_UNIX
+#endif
+
+/*
+ * Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow system on default,
+ * and strtold.
+ * The function strtold is referenced first at ISO9899:1999(C99), and some old compilers can
+ * not support these functions. Here provides a macro to open these functions:
+ * SECUREC_SUPPORT_STRTOLD -- If defined, strtold will be used
+ */
+#ifndef SECUREC_SUPPORT_STRTOLD
+#define SECUREC_SUPPORT_STRTOLD 0
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT))
+#if defined(__USE_ISOC99) || \
+ (defined(_AIX) && defined(_ISOC99_SOURCE)) || \
+ (defined(__hpux) && defined(__ia64)) || \
+ (defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
+ defined(_STDC_C99) || defined(__EXTENSIONS__))
+#undef SECUREC_SUPPORT_STRTOLD
+#define SECUREC_SUPPORT_STRTOLD 1
+#endif
+#endif
+#if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_)))
+#undef SECUREC_SUPPORT_STRTOLD
+#define SECUREC_SUPPORT_STRTOLD 0
+#endif
+#endif
+
+#if SECUREC_WITH_PERFORMANCE_ADDONS
+
+#ifndef SECUREC_TWO_MIN
+#define SECUREC_TWO_MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+/* For strncpy_s performance optimization */
+#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \
+ (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
+ (SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \
+ (((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \
+ (memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count))))
+
+#define SECUREC_STRCPY_SM(dest, destMax, src) \
+ (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
+ (strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \
+ (strcpy_error((dest), (destMax), (src))))
+
+/* For strcat_s performance optimization */
+#if defined(__GNUC__)
+#define SECUREC_STRCAT_SM(dest, destMax, src) ({ \
+ int catRet_ = EOK; \
+ if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
+ char *catTmpDst_ = (char *)(dest); \
+ size_t catRestSize_ = (destMax); \
+ while (catRestSize_ > 0 && *catTmpDst_ != '\0') { \
+ ++catTmpDst_; \
+ --catRestSize_; \
+ } \
+ if (catRestSize_ == 0) { \
+ catRet_ = EINVAL; \
+ } else if ((strlen(src) + 1) <= catRestSize_) { \
+ memcpy(catTmpDst_, (src), strlen(src) + 1); \
+ catRet_ = EOK; \
+ } else { \
+ catRet_ = ERANGE; \
+ } \
+ if (catRet_ != EOK) { \
+ catRet_ = strcat_s((dest), (destMax), (src)); \
+ } \
+ } else { \
+ catRet_ = strcat_s((dest), (destMax), (src)); \
+ } \
+ catRet_; \
+})
+#else
+#define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src))
+#endif
+
+/* For strncat_s performance optimization */
+#if defined(__GNUC__)
+#define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \
+ int ncatRet_ = EOK; \
+ if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
+ (((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
+ char *ncatTmpDest_ = (char *)(dest); \
+ size_t ncatRestSize_ = (size_t)(destMax); \
+ while (ncatRestSize_ > 0 && *ncatTmpDest_ != '\0') { \
+ ++ncatTmpDest_; \
+ --ncatRestSize_; \
+ } \
+ if (ncatRestSize_ == 0) { \
+ ncatRet_ = EINVAL; \
+ } else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize_) { \
+ if ((size_t)(count) < strlen(src)) { \
+ memcpy(ncatTmpDest_, (src), (count)); \
+ *(ncatTmpDest_ + (count)) = '\0'; \
+ } else { \
+ memcpy(ncatTmpDest_, (src), strlen(src) + 1); \
+ } \
+ } else { \
+ ncatRet_ = ERANGE; \
+ } \
+ if (ncatRet_ != EOK) { \
+ ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \
+ } \
+ } else { \
+ ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \
+ } \
+ ncatRet_; \
+})
+#else
+#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count))
+#endif
+
+/* This macro do not check buffer overlap by default */
+#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \
+ (!(((size_t)(destMax) == 0) || \
+ (((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
+ ((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((void *)(src) == NULL)) ? \
+ (memcpy((dest), (src), (count)), EOK) : \
+ (memcpy_s((dest), (destMax), (src), (count))))
+
+#define SECUREC_MEMSET_SM(dest, destMax, c, count) \
+ (!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
+ ((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \
+ (memset((dest), (c), (count)), EOK) : \
+ (memset_s((dest), (destMax), (c), (count))))
+
+#endif
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/MakefileCustom b/3rd/gstor/dependency/Huawei_Secure_C/src/MakefileCustom
new file mode 100644
index 0000000000000000000000000000000000000000..e4ae934a8e9c29792a9f404d608c0fa917f08836
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/MakefileCustom
@@ -0,0 +1,123 @@
+
+ANSI_OBJS = fscanf_s.o gets_s.o memcpy_s.o memmove_s.o memset_s.o scanf_s.o securecutil.o secureinput_a.o secureprintoutput_a.o snprintf_s.o sprintf_s.o sscanf_s.o strcat_s.o strcpy_s.o strncat_s.o strncpy_s.o strtok_s.o vfscanf_s.o vscanf_s.o vsnprintf_s.o vsprintf_s.o vsscanf_s.o
+
+UNICODE_OBJS = secureinput_w.o vswscanf_s.o vwscanf_s.o fwscanf_s.o swprintf_s.o swscanf_s.o vfwscanf_s.o vswprintf_s.o wcscat_s.o wcscpy_s.o wcsncat_s.o wcsncpy_s.o wcstok_s.o wmemcpy_s.o wmemmove_s.o wscanf_s.o secureprintoutput_w.o
+
+ALL_OBJS = $(ANSI_OBJS) $(UNICODE_OBJS)
+
+TESTOBJS = $(ALL_OBJS) test.o
+
+CC = gcc
+
+FLAGS = -I ../include -Wall -DNDEBUG -DSECUREC_WARP_OUTPUT -s -fstack-protector-strong -Wl,-z,relro,-z,now -O2
+#FLAGS = -Wall -W -I ../include -I. -g -D_DEBUG
+
+ARCH:=$(shell getconf LONG_BIT)
+
+ifeq ($(ARCH), 64)
+ FLAGS += -fPIC
+endif
+
+
+securecshare: $(ALL_OBJS)
+ $(CC) $(FLAGS) -shared -o libsecurec.so $(ALL_OBJS)
+ansisecurecshare: $(ANSI_OBJS)
+ $(CC) $(FLAGS) -shared -o libsecurec.so $(ANSI_OBJS)
+securecstatic: $(ALL_OBJS)
+ ar crv libsecurec.a $(ALL_OBJS)
+ ranlib libsecurec.a
+ansisecurecstatic: $(ANSI_OBJS)
+ ar crv libsecurec.a $(ANSI_OBJS)
+ ranlib libsecurec.a
+secureinput_a.o : secureinput_a.c secinput.h input.inl
+ $(CC) $(FLAGS) -c secureinput_a.c
+secureinput_w.o : secureinput_w.c secinput.h input.inl
+ $(CC) $(FLAGS) -c secureinput_w.c
+fscanf_s.o : fscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c fscanf_s.c
+fwscanf_s.o : fwscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c fwscanf_s.c
+gets_s.o : gets_s.c securecutil.h
+ $(CC) $(FLAGS) -c gets_s.c
+memcpy_s.o : memcpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c memcpy_s.c
+memmove_s.o : memmove_s.c securecutil.h
+ $(CC) $(FLAGS) -c memmove_s.c
+memset_s.o : memset_s.c securecutil.h
+ $(CC) $(FLAGS) -c memset_s.c
+scanf_s.o : scanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c scanf_s.c
+securecutil.o : securecutil.c securecutil.h secureprintoutput.h
+ $(CC) $(FLAGS) -c securecutil.c
+secureprintoutput_a.o : secureprintoutput_a.c securecutil.h secureprintoutput.h output.inl
+ $(CC) $(FLAGS) -c secureprintoutput_a.c
+secureprintoutput_w.o : secureprintoutput_w.c securecutil.h secureprintoutput.h output.inl
+ $(CC) $(FLAGS) -c secureprintoutput_w.c
+snprintf_s.o : snprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c snprintf_s.c
+sprintf_s.o : sprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c sprintf_s.c
+sscanf_s.o : sscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c sscanf_s.c
+strcat_s.o : strcat_s.c securecutil.h
+ $(CC) $(FLAGS) -c strcat_s.c
+strcpy_s.o : strcpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c strcpy_s.c
+strncat_s.o : strncat_s.c securecutil.h
+ $(CC) $(FLAGS) -c strncat_s.c
+strncpy_s.o : strncpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c strncpy_s.c
+strtok_s.o : strtok_s.c securecutil.h
+ $(CC) $(FLAGS) -c strtok_s.c
+swprintf_s.o : swprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c swprintf_s.c
+swscanf_s.o : swscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c swscanf_s.c
+vfscanf_s.o : vfscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vfscanf_s.c
+vfwscanf_s.o : vfwscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vfwscanf_s.c
+vscanf_s.o : vscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vscanf_s.c
+vsnprintf_s.o : vsnprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c vsnprintf_s.c
+vsprintf_s.o : vsprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c vsprintf_s.c
+vsscanf_s.o : vsscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vsscanf_s.c
+vswprintf_s.o : vswprintf_s.c securecutil.h
+ $(CC) $(FLAGS) -c vswprintf_s.c
+vswscanf_s.o : vswscanf_s.c securecutil.h input.inl
+ $(CC) $(FLAGS) -c vswscanf_s.c
+vwscanf_s.o : vwscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c vwscanf_s.c
+wcscat_s.o : wcscat_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcscat_s.c
+wcscpy_s.o : wcscpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcscpy_s.c
+wcsncat_s.o : wcsncat_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcsncat_s.c
+wcsncpy_s.o : wcsncpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcsncpy_s.c
+wcstok_s.o : wcstok_s.c securecutil.h
+ $(CC) $(FLAGS) -c wcstok_s.c
+wmemcpy_s.o : wmemcpy_s.c securecutil.h
+ $(CC) $(FLAGS) -c wmemcpy_s.c
+wmemmove_s.o : wmemmove_s.c securecutil.h
+ $(CC) $(FLAGS) -c wmemmove_s.c
+wscanf_s.o : wscanf_s.c securecutil.h
+ $(CC) $(FLAGS) -c wscanf_s.c
+maketest: $(TESTOBJS)
+ $(CC) $(FLAGS) -o tst $(TESTOBJS)
+test.o : test.c
+ $(CC) $(FLAGS) -c test.c
+
+staticlink: $(TESTOBJS)
+ $(CC) $(FLAGS) -o tst test.c -L. -lsecurec.a
+dynLink:
+ gcc -g -o tst test.c -L. -l/home/l00254400/sec -lsecurec
+ gcc -g -o tst test.c -L. -lsecurec
+ gcc -g -o tst test.c -L. -l./securec
+clean:
+ rm *.o
+
\ No newline at end of file
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/fscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/fscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..2d1e735c3c8cec8d2c171a8eac2669588f77cc07
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/fscanf_s.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: fscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securec.h"
+
+/*
+ *
+ * The fscanf_s function is equivalent to fscanf except that the c, s,
+ * and [ conversion specifiers apply to a pair of arguments (unless assignment suppression is indicated by a*)
+ * The fscanf function reads data from the current position of stream into
+ * the locations given by argument (if any). Each argument must be a pointer
+ * to a variable of a type that corresponds to a type specifier in format.
+ * format controls the interpretation of the input fields and has the same
+ * form and function as the format argument for scanf.
+ *
+ *
+ * stream Pointer to FILE structure.
+ * format Format control string, see Format Specifications.
+ * ... Optional arguments.
+ *
+ *
+ * ... The convered value stored in user assigned address
+ *
+ *
+ * Each of these functions returns the number of fields successfully converted
+ * and assigned; the return value does not include fields that were read but
+ * not assigned. A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int fscanf_s(FILE *stream, const char *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vfscanf_s(stream, format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/fwscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/fwscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..ed2438b1d91b59cdede3669d3537da9cc0c6ee1a
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/fwscanf_s.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: fwscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securec.h"
+
+/*
+ *
+ * The fwscanf_s function is the wide-character equivalent of the fscanf_s function
+ * The fwscanf_s function reads data from the current position of stream into
+ * the locations given by argument (if any). Each argument must be a pointer
+ * to a variable of a type that corresponds to a type specifier in format.
+ * format controls the interpretation of the input fields and has the same
+ * form and function as the format argument for scanf.
+ *
+ *
+ * stream Pointer to FILE structure.
+ * format Format control string, see Format Specifications.
+ * ... Optional arguments.
+ *
+ *
+ * ... The converted value stored in user assigned address
+ *
+ *
+ * Each of these functions returns the number of fields successfully converted
+ * and assigned; the return value does not include fields that were read but
+ * not assigned. A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int fwscanf_s(FILE *stream, const wchar_t *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vfwscanf_s(stream, format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/gets_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/gets_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..18d785888cde0d9bdc01b1e9e2ccf9549f7a5b76
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/gets_s.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: gets_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+/*
+ * The parameter size is buffer size in byte
+ */
+SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t size)
+{
+ size_t len = strlen(buffer);
+ --len; /* Unsigned integer wrapping is accepted and is checked afterwards */
+ while (len < size && (buffer[len] == '\r' || buffer[len] == '\n')) {
+ buffer[len] = '\0';
+ --len; /* Unsigned integer wrapping is accepted and is checked next loop */
+ }
+}
+
+/*
+ *
+ * The gets_s function reads at most one less than the number of characters
+ * specified by destMax from the std input stream, into the array pointed to by buffer
+ * The line consists of all characters up to and including
+ * the first newline character ('\n'). gets_s then replaces the newline
+ * character with a null character ('\0') before returning the line.
+ * If the first character read is the end-of-file character, a null character
+ * is stored at the beginning of buffer and NULL is returned.
+ *
+ *
+ * buffer Storage location for input string.
+ * destMax The size of the buffer.
+ *
+ *
+ * buffer is updated
+ *
+ *
+ * buffer Successful operation
+ * NULL Improper parameter or read fail
+ */
+char *gets_s(char *buffer, size_t destMax)
+{
+#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
+ size_t bufferSize = ((destMax == (size_t)(-1)) ? SECUREC_STRING_MAX_LEN : destMax);
+#else
+ size_t bufferSize = destMax;
+#endif
+
+ if (buffer == NULL || bufferSize == 0 || bufferSize > SECUREC_STRING_MAX_LEN) {
+ SECUREC_ERROR_INVALID_PARAMTER("gets_s");
+ return NULL;
+ }
+
+ if (fgets(buffer, (int)bufferSize, SECUREC_STREAM_STDIN) != NULL) {
+ SecTrimCRLF(buffer, bufferSize);
+ return buffer;
+ }
+
+ return NULL;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/input.inl b/3rd/gstor/dependency/Huawei_Secure_C/src/input.inl
new file mode 100644
index 0000000000000000000000000000000000000000..06fff4157fc784e458f86722c842928b9333f221
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/input.inl
@@ -0,0 +1,2227 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: Used by secureinput_a.c and secureinput_w.c to include.
+ * This file provides a template function for ANSI and UNICODE compiling by
+ * different type definition. The functions of SecInputS or
+ * SecInputSW provides internal implementation for scanf family API, such as sscanf_s, fscanf_s.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef INPUT_INL_5D13A042_DC3F_4ED9_A8D1_882811274C27
+#define INPUT_INL_5D13A042_DC3F_4ED9_A8D1_882811274C27
+
+#if SECUREC_IN_KERNEL
+#if !defined(SECUREC_CTYPE_MACRO_ADAPT)
+#include
+#endif
+#else
+#if !defined(SECUREC_SYSAPI4VXWORKS) && !defined(SECUREC_CTYPE_MACRO_ADAPT)
+#include
+#ifdef SECUREC_FOR_WCHAR
+#include /* For iswspace */
+#endif
+#endif
+#endif
+
+#ifndef EOF
+#define EOF (-1)
+#endif
+
+#define SECUREC_NUM_WIDTH_SHORT 0
+#define SECUREC_NUM_WIDTH_INT 1
+#define SECUREC_NUM_WIDTH_LONG 2
+#define SECUREC_NUM_WIDTH_LONG_LONG 3 /* Also long double */
+
+#define SECUREC_BUFFERED_BLOK_SIZE 1024U
+
+#if defined(SECUREC_VXWORKS_PLATFORM) && !defined(va_copy) && !defined(__va_copy)
+/* The name is the same as system macro. */
+#define __va_copy(dest, src) do { \
+ size_t destSize_ = (size_t)sizeof(dest); \
+ size_t srcSize_ = (size_t)sizeof(src); \
+ if (destSize_ != srcSize_) { \
+ (void)memcpy((dest), (src), sizeof(va_list)); \
+ } else { \
+ (void)memcpy(&(dest), &(src), sizeof(va_list)); \
+ } \
+} SECUREC_WHILE_ZERO
+#endif
+
+#define SECUREC_MULTI_BYTE_MAX_LEN 6
+
+/* Compatibility macro name cannot be modifie */
+#ifndef UNALIGNED
+#if !(defined(_M_IA64)) && !(defined(_M_AMD64))
+#define UNALIGNED
+#else
+#define UNALIGNED __unaligned
+#endif
+#endif
+
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+/* Max 64bit value is 0xffffffffffffffff */
+#define SECUREC_MAX_64BITS_VALUE 18446744073709551615ULL
+#define SECUREC_MAX_64BITS_VALUE_DIV_TEN 1844674407370955161ULL
+#define SECUREC_MAX_64BITS_VALUE_CUT_LAST_DIGIT 18446744073709551610ULL
+#define SECUREC_MIN_64BITS_NEG_VALUE 9223372036854775808ULL
+#define SECUREC_MAX_64BITS_POS_VALUE 9223372036854775807ULL
+#define SECUREC_MIN_32BITS_NEG_VALUE 2147483648UL
+#define SECUREC_MAX_32BITS_POS_VALUE 2147483647UL
+#define SECUREC_MAX_32BITS_VALUE 4294967295UL
+#define SECUREC_MAX_32BITS_VALUE_INC 4294967296UL
+#define SECUREC_MAX_32BITS_VALUE_DIV_TEN 429496729UL
+#define SECUREC_LONG_BIT_NUM ((unsigned int)(sizeof(long) << 3U))
+/* Use ULL to clean up cl6x compilation alerts */
+#define SECUREC_MAX_LONG_POS_VALUE ((unsigned long)(1ULL << (SECUREC_LONG_BIT_NUM - 1)) - 1)
+#define SECUREC_MIN_LONG_NEG_VALUE ((unsigned long)(1ULL << (SECUREC_LONG_BIT_NUM - 1)))
+
+/* Covert to long long to clean up cl6x compilation alerts */
+#define SECUREC_LONG_HEX_BEYOND_MAX(number) (((unsigned long long)(number) >> (SECUREC_LONG_BIT_NUM - 4U)) > 0)
+#define SECUREC_LONG_OCTAL_BEYOND_MAX(number) (((unsigned long long)(number) >> (SECUREC_LONG_BIT_NUM - 3U)) > 0)
+
+#define SECUREC_QWORD_HEX_BEYOND_MAX(number) (((number) >> (64U - 4U)) > 0)
+#define SECUREC_QWORD_OCTAL_BEYOND_MAX(number) (((number) >> (64U - 3U)) > 0)
+
+#define SECUREC_LP64_BIT_WIDTH 64
+#define SECUREC_LP32_BIT_WIDTH 32
+
+#define SECUREC_CONVERT_IS_SIGNED(conv) ((conv) == 'd' || (conv) == 'i')
+#endif
+
+#define SECUREC_BRACE '{' /* [ to { */
+#define SECUREC_FILED_WIDTH_ENOUGH(spec) ((spec)->widthSet == 0 || (spec)->width > 0)
+#define SECUREC_FILED_WIDTH_DEC(spec) do { \
+ if ((spec)->widthSet != 0) { \
+ --(spec)->width; \
+ } \
+} SECUREC_WHILE_ZERO
+
+#ifdef SECUREC_FOR_WCHAR
+/* Bits for all wchar, size is 65536/8, only supports wide characters with a maximum length of two bytes */
+#define SECUREC_BRACKET_TABLE_SIZE 8192
+#define SECUREC_EOF WEOF
+#define SECUREC_MB_LEN 16 /* Max. # bytes in multibyte char ,see MB_LEN_MAX */
+#else
+/* Bits for all char, size is 256/8 */
+#define SECUREC_BRACKET_TABLE_SIZE 32
+#define SECUREC_EOF EOF
+#endif
+
+#if SECUREC_HAVE_WCHART
+#define SECUREC_ARRAY_WIDTH_IS_WRONG(spec) ((spec).arrayWidth == 0 || \
+ ((spec).isWCharOrLong <= 0 && (spec).arrayWidth > SECUREC_STRING_MAX_LEN) || \
+ ((spec).isWCharOrLong > 0 && (spec).arrayWidth > SECUREC_WCHAR_STRING_MAX_LEN))
+#else
+#define SECUREC_ARRAY_WIDTH_IS_WRONG(spec) ((spec).arrayWidth == 0 || (spec).arrayWidth > SECUREC_STRING_MAX_LEN)
+#endif
+
+typedef struct {
+#ifdef SECUREC_FOR_WCHAR
+ unsigned char *table; /* Default NULL */
+#else
+ unsigned char table[SECUREC_BRACKET_TABLE_SIZE]; /* Array length is large enough in application scenarios */
+#endif
+ unsigned char mask; /* Default 0 */
+} SecBracketTable;
+
+#ifdef SECUREC_FOR_WCHAR
+#define SECUREC_INIT_BRACKET_TABLE { NULL, 0 }
+#else
+#define SECUREC_INIT_BRACKET_TABLE { {0}, 0 }
+#endif
+
+#if SECUREC_ENABLE_SCANF_FLOAT
+typedef struct {
+ size_t floatStrTotalLen; /* Initialization must be length of buffer in charater */
+ size_t floatStrUsedLen; /* Store float string len */
+ SecChar *floatStr; /* Initialization must point to buffer */
+ SecChar *allocatedFloatStr; /* Initialization must be NULL to store alloced point */
+ SecChar buffer[SECUREC_FLOAT_BUFSIZE + 1];
+} SecFloatSpec;
+#endif
+
+#define SECUREC_NUMBER_STATE_DEFAULT 0U
+#define SECUREC_NUMBER_STATE_STARTED 1U
+
+typedef struct {
+ SecInt ch; /* Char read from input */
+ int charCount; /* Number of characters processed */
+ void *argPtr; /* Variable parameter pointer, point to the end of the string */
+ size_t arrayWidth; /* Length of pointer Variable parameter, in charaters */
+ SecUnsignedInt64 number64; /* Store input number64 value */
+ unsigned long number; /* Store input number32 value */
+ int numberWidth; /* 0 = SHORT, 1 = int, > 1 long or L_DOUBLE */
+ int numberArgType; /* 1 for 64-bit integer, 0 otherwise. use it as decode function index */
+ unsigned int negative; /* 0 is positive */
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ unsigned int beyondMax; /* Non-zero means beyond */
+#endif
+ unsigned int numberState; /* Identifies whether to start processing numbers, 1 is can input number*/
+ int width; /* Width number in format */
+ int widthSet; /* 0 is not set width in format */
+ int convChr; /* Lowercase format conversion characters */
+ int oriConvChr; /* Store original format conversion, convChr may change when parsing integers */
+ signed char isWCharOrLong; /* -1/0 not wchar or long, 1 for wchar or long */
+ unsigned char suppress; /* 0 is not have %* in format */
+} SecScanSpec;
+
+#ifdef SECUREC_FOR_WCHAR
+#define SECUREC_GETC fgetwc
+#define SECUREC_UN_GETC ungetwc
+/* Only supports wide characters with a maximum length of two bytes in format string */
+#define SECUREC_BRACKET_CHAR_MASK 0xffffU
+#else
+#define SECUREC_GETC fgetc
+#define SECUREC_UN_GETC ungetc
+#define SECUREC_BRACKET_CHAR_MASK 0xffU
+#endif
+
+#define SECUREC_CHAR_SIZE ((unsigned int)(sizeof(SecChar)))
+/* To avoid 648, mask high bit: 0x00ffffff 0x0000ffff or 0x00000000 */
+#define SECUREC_CHAR_MASK_HIGH (((((((((unsigned int)(-1) >> SECUREC_CHAR_SIZE) >> SECUREC_CHAR_SIZE) >> \
+ SECUREC_CHAR_SIZE) >> SECUREC_CHAR_SIZE) >> \
+ SECUREC_CHAR_SIZE) >> SECUREC_CHAR_SIZE) >> \
+ SECUREC_CHAR_SIZE) >> SECUREC_CHAR_SIZE)
+
+/* For char is 0xff, wcahr_t is 0xffff or 0xffffffff. */
+#define SECUREC_CHAR_MASK (~((((((((((unsigned int)(-1) & SECUREC_CHAR_MASK_HIGH) << \
+ SECUREC_CHAR_SIZE) << SECUREC_CHAR_SIZE) << \
+ SECUREC_CHAR_SIZE) << SECUREC_CHAR_SIZE) << \
+ SECUREC_CHAR_SIZE) << SECUREC_CHAR_SIZE) << \
+ SECUREC_CHAR_SIZE) << SECUREC_CHAR_SIZE))
+
+/* According wchar_t has multiple bytes, so use sizeof */
+#define SECUREC_GET_CHAR(stream, outCh) do { \
+ if ((stream)->count >= sizeof(SecChar)) { \
+ *(outCh) = (SecInt)(SECUREC_CHAR_MASK & \
+ (unsigned int)(int)(*((const SecChar *)(const void *)(stream)->cur))); \
+ (stream)->cur += sizeof(SecChar); \
+ (stream)->count -= sizeof(SecChar); \
+ } else { \
+ *(outCh) = SECUREC_EOF; \
+ } \
+} SECUREC_WHILE_ZERO
+
+#define SECUREC_UN_GET_CHAR(stream) do { \
+ if ((stream)->cur > (stream)->base) { \
+ (stream)->cur -= sizeof(SecChar); \
+ (stream)->count += sizeof(SecChar); \
+ } \
+} SECUREC_WHILE_ZERO
+
+/* Convert wchar_t to int and then to unsigned int to keep data clearing warning */
+#define SECUREC_TO_LOWERCASE(chr) ((int)((unsigned int)(int)(chr) | (unsigned int)('a' - 'A')))
+
+/* Record a flag for each bit */
+#define SECUREC_BRACKET_INDEX(x) ((unsigned int)(x) >> 3U)
+#define SECUREC_BRACKET_VALUE(x) ((unsigned char)(1U << ((unsigned int)(x) & 7U)))
+#if SECUREC_IN_KERNEL
+#define SECUREC_CONVERT_IS_UNSIGNED(conv) ((conv) == 'x' || (conv) == 'o' || (conv) == 'u')
+#endif
+
+/*
+ * Set char in %[xxx] into table, only supports wide characters with a maximum length of two bytes
+ */
+SECUREC_INLINE void SecBracketSetBit(unsigned char *table, SecUnsignedChar ch)
+{
+ unsigned int tableIndex = SECUREC_BRACKET_INDEX(((unsigned int)(int)ch & SECUREC_BRACKET_CHAR_MASK));
+ unsigned int tableValue = SECUREC_BRACKET_VALUE(((unsigned int)(int)ch & SECUREC_BRACKET_CHAR_MASK));
+ /* Do not use |= optimize this code, it will cause compiling warning */
+ table[tableIndex] = (unsigned char)(table[tableIndex] | tableValue);
+}
+
+SECUREC_INLINE void SecBracketSetBitRange(unsigned char *table, SecUnsignedChar startCh, SecUnsignedChar endCh)
+{
+ SecUnsignedChar expCh;
+ /* %[a-z] %[a-a] Format %[a-\xff] end is 0xFF, condition (expCh <= endChar) cause dead loop */
+ for (expCh = startCh; expCh < endCh; ++expCh) {
+ SecBracketSetBit(table, expCh);
+ }
+ SecBracketSetBit(table, endCh);
+}
+/*
+ * Determine whether the expression can be satisfied
+ */
+SECUREC_INLINE int SecCanInputForBracket(int convChr, SecInt ch, const SecBracketTable *bracketTable)
+{
+ unsigned int tableIndex = SECUREC_BRACKET_INDEX(((unsigned int)(int)ch & SECUREC_BRACKET_CHAR_MASK));
+ unsigned int tableValue = SECUREC_BRACKET_VALUE(((unsigned int)(int)ch & SECUREC_BRACKET_CHAR_MASK));
+#ifdef SECUREC_FOR_WCHAR
+ if (((unsigned int)(int)ch & (~(SECUREC_BRACKET_CHAR_MASK))) != 0) {
+ /* The value of the wide character exceeds the size of two bytes */
+ return 0;
+ }
+ return (int)(convChr == SECUREC_BRACE && bracketTable->table != NULL &&
+ ((bracketTable->table[tableIndex] ^ bracketTable->mask) & tableValue) != 0);
+#else
+ return (int)(convChr == SECUREC_BRACE &&
+ ((bracketTable->table[tableIndex] ^ bracketTable->mask) & tableValue) != 0);
+#endif
+}
+
+/*
+ * String input ends when blank character is encountered
+ */
+SECUREC_INLINE int SecCanInputString(int convChr, SecInt ch)
+{
+ return (int)(convChr == 's' &&
+ (!(ch >= SECUREC_CHAR('\t') && ch <= SECUREC_CHAR('\r')) && ch != SECUREC_CHAR(' ')));
+}
+
+/*
+ * Can input a character when format is %c
+ */
+SECUREC_INLINE int SecCanInputCharacter(int convChr)
+{
+ return (int)(convChr == 'c');
+}
+
+/*
+ * Determine if it is a 64-bit pointer function
+ * Return 0 is not ,1 is 64bit pointer
+ */
+SECUREC_INLINE int SecNumberArgType(size_t sizeOfVoidStar)
+{
+ /* Point size is 4 or 8 , Under the 64 bit system, the value not 0 */
+ /* To clear e778 */
+ if ((sizeOfVoidStar & sizeof(SecInt64)) != 0) {
+ return 1;
+ }
+ return 0;
+}
+SECUREC_INLINE int SecIsDigit(SecInt ch);
+SECUREC_INLINE int SecIsXdigit(SecInt ch);
+SECUREC_INLINE int SecIsSpace(SecInt ch);
+SECUREC_INLINE SecInt SecSkipSpaceChar(SecFileStream *stream, int *counter);
+SECUREC_INLINE SecInt SecGetChar(SecFileStream *stream, int *counter);
+SECUREC_INLINE void SecUnGetChar(SecInt ch, SecFileStream *stream, int *counter);
+
+#if SECUREC_ENABLE_SCANF_FLOAT
+
+/*
+ * Convert a floating point string to a floating point number
+ */
+SECUREC_INLINE void SecAssignFloat(const char *floatStr, int numberWidth, void *argPtr)
+{
+ char *endPtr = NULL;
+ double d;
+#if SECUREC_SUPPORT_STRTOLD
+ if (numberWidth == SECUREC_NUM_WIDTH_LONG_LONG) {
+ long double d2 = strtold(floatStr, &endPtr);
+ *(long double UNALIGNED *)(argPtr) = d2;
+ return;
+ }
+#endif
+ d = strtod(floatStr, &endPtr);
+ if (numberWidth > SECUREC_NUM_WIDTH_INT) {
+ *(double UNALIGNED *)(argPtr) = (double)d;
+ } else {
+ *(float UNALIGNED *)(argPtr) = (float)d;
+ }
+}
+
+#ifdef SECUREC_FOR_WCHAR
+/*
+ * Convert a floating point wchar string to a floating point number
+ * Success ret 0
+ */
+SECUREC_INLINE int SecAssignFloatW(const SecFloatSpec *floatSpec, const SecScanSpec *spec)
+{
+ /* Convert float string */
+ size_t mbsLen;
+ size_t tempFloatStrLen = (size_t)(floatSpec->floatStrTotalLen + 1) * sizeof(wchar_t);
+ char *tempFloatStr = (char *)SECUREC_MALLOC(tempFloatStrLen);
+
+ if (tempFloatStr == NULL) {
+ return -1;
+ }
+ tempFloatStr[0] = '\0';
+ SECUREC_MASK_MSVC_CRT_WARNING
+ mbsLen = wcstombs(tempFloatStr, floatSpec->floatStr, tempFloatStrLen - 1);
+ SECUREC_END_MASK_MSVC_CRT_WARNING
+ /* This condition must satisfy mbsLen is not -1 */
+ if (mbsLen >= tempFloatStrLen) {
+ SECUREC_FREE(tempFloatStr);
+ return -1;
+ }
+ tempFloatStr[mbsLen] = '\0';
+ SecAssignFloat(tempFloatStr, spec->numberWidth, spec->argPtr);
+ SECUREC_FREE(tempFloatStr);
+ return 0;
+}
+#endif
+
+/*
+ * Init SecFloatSpec befor parse format
+ */
+SECUREC_INLINE void SecInitFloatSpec(SecFloatSpec *floatSpec)
+{
+ floatSpec->floatStr = floatSpec->buffer;
+ floatSpec->allocatedFloatStr = NULL;
+ floatSpec->floatStrTotalLen = sizeof(floatSpec->buffer) / sizeof(floatSpec->buffer[0]);
+ floatSpec->floatStrUsedLen = 0;
+}
+
+SECUREC_INLINE void SecFreeFloatSpec(SecFloatSpec *floatSpec, int *doneCount)
+{
+ /* LSD 2014.3.6 add, clear the stack data */
+ if (memset_s(floatSpec->buffer, sizeof(floatSpec->buffer), 0, sizeof(floatSpec->buffer)) != EOK) {
+ *doneCount = 0; /* This code just to meet the coding requirements */
+ }
+ /* The pFloatStr can be alloced in SecExtendFloatLen function, clear and free it */
+ if (floatSpec->allocatedFloatStr != NULL) {
+ size_t bufferSize = floatSpec->floatStrTotalLen * sizeof(SecChar);
+ if (memset_s(floatSpec->allocatedFloatStr, bufferSize, 0, bufferSize) != EOK) {
+ *doneCount = 0; /* This code just to meet the coding requirements */
+ }
+ SECUREC_FREE(floatSpec->allocatedFloatStr);
+ floatSpec->allocatedFloatStr = NULL;
+ floatSpec->floatStr = NULL;
+ }
+}
+
+/*
+ * Splice floating point string
+ * Return 0 OK
+ */
+SECUREC_INLINE int SecExtendFloatLen(SecFloatSpec *floatSpec)
+{
+ if (floatSpec->floatStrUsedLen >= floatSpec->floatStrTotalLen) {
+ /* Buffer size is len x sizeof(SecChar) */
+ size_t oriSize = floatSpec->floatStrTotalLen * sizeof(SecChar);
+ /* Add one character to clear tool warning */
+ size_t nextSize = (oriSize * 2) + sizeof(SecChar); /* Multiply 2 to extend buffer size */
+
+ /* Prevents integer overflow, the maximum length of SECUREC_MAX_WIDTH_LEN is enough */
+ if (nextSize <= (size_t)SECUREC_MAX_WIDTH_LEN) {
+ void *nextBuffer = (void *)SECUREC_MALLOC(nextSize);
+ if (nextBuffer == NULL) {
+ return -1;
+ }
+ if (memcpy_s(nextBuffer, nextSize, floatSpec->floatStr, oriSize) != EOK) {
+ SECUREC_FREE(nextBuffer); /* This is a dead code, just to meet the coding requirements */
+ return -1;
+ }
+ /* Clear old buffer memory */
+ if (memset_s(floatSpec->floatStr, oriSize, 0, oriSize) != EOK) {
+ SECUREC_FREE(nextBuffer); /* This is a dead code, just to meet the coding requirements */
+ return -1;
+ }
+ /* Free old allocated buffer */
+ if (floatSpec->allocatedFloatStr != NULL) {
+ SECUREC_FREE(floatSpec->allocatedFloatStr);
+ }
+ floatSpec->allocatedFloatStr = (SecChar *)(nextBuffer); /* Use to clear free on stack warning */
+ floatSpec->floatStr = (SecChar *)(nextBuffer);
+ floatSpec->floatStrTotalLen = nextSize / sizeof(SecChar); /* Get buffer total len in character */
+ return 0;
+ }
+ return -1; /* Next size is beyond max */
+ }
+ return 0;
+}
+
+/* Do not use localeconv()->decimal_pointif onlay support '.' */
+SECUREC_INLINE int SecIsFloatDecimal(SecChar ch)
+{
+ return (int)(ch == SECUREC_CHAR('.'));
+}
+
+SECUREC_INLINE int SecInputFloatSign(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec)
+{
+ if (!SECUREC_FILED_WIDTH_ENOUGH(spec)) {
+ return 0;
+ }
+ spec->ch = SecGetChar(stream, &(spec->charCount));
+ if (spec->ch == SECUREC_CHAR('+') || spec->ch == SECUREC_CHAR('-')) {
+ SECUREC_FILED_WIDTH_DEC(spec); /* Make sure the count after un get char is correct */
+ if (spec->ch == SECUREC_CHAR('-')) {
+ floatSpec->floatStr[floatSpec->floatStrUsedLen] = SECUREC_CHAR('-');
+ ++floatSpec->floatStrUsedLen;
+ if (SecExtendFloatLen(floatSpec) != 0) {
+ return -1;
+ }
+ }
+ } else {
+ SecUnGetChar(spec->ch, stream, &(spec->charCount));
+ }
+ return 0;
+}
+
+SECUREC_INLINE int SecInputFloatDigit(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec)
+{
+ /* Now get integral part */
+ while (SECUREC_FILED_WIDTH_ENOUGH(spec)) {
+ spec->ch = SecGetChar(stream, &(spec->charCount));
+ if (SecIsDigit(spec->ch) == 0) {
+ SecUnGetChar(spec->ch, stream, &(spec->charCount));
+ return 0;
+ }
+ SECUREC_FILED_WIDTH_DEC(spec); /* Must be behind un get char, otherwise the logic is incorrect */
+ spec->numberState = SECUREC_NUMBER_STATE_STARTED;
+ floatSpec->floatStr[floatSpec->floatStrUsedLen] = (SecChar)spec->ch;
+ ++floatSpec->floatStrUsedLen;
+ if (SecExtendFloatLen(floatSpec) != 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+* Scan value of exponent.
+* Return 0 OK
+*/
+SECUREC_INLINE int SecInputFloatE(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec)
+{
+ if (SecInputFloatSign(stream, spec, floatSpec) == -1) {
+ return -1;
+ }
+ if (SecInputFloatDigit(stream, spec, floatSpec) != 0) {
+ return -1;
+ }
+ return 0;
+}
+
+SECUREC_INLINE int SecInputFloatFractional(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec)
+{
+ if (SECUREC_FILED_WIDTH_ENOUGH(spec)) {
+ spec->ch = SecGetChar(stream, &(spec->charCount));
+ if (SecIsFloatDecimal((SecChar)spec->ch) == 0) {
+ SecUnGetChar(spec->ch, stream, &(spec->charCount));
+ return 0;
+ }
+ SECUREC_FILED_WIDTH_DEC(spec); /* Must be behind un get char, otherwise the logic is incorrect */
+ /* Now check for decimal */
+ floatSpec->floatStr[floatSpec->floatStrUsedLen] = (SecChar)spec->ch;
+ ++floatSpec->floatStrUsedLen;
+ if (SecExtendFloatLen(floatSpec) != 0) {
+ return -1;
+ }
+ if (SecInputFloatDigit(stream, spec, floatSpec) != 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+SECUREC_INLINE int SecInputFloatExponent(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec)
+{
+ /* Now get exponent part */
+ if (spec->numberState == SECUREC_NUMBER_STATE_STARTED && SECUREC_FILED_WIDTH_ENOUGH(spec)) {
+ spec->ch = SecGetChar(stream, &(spec->charCount));
+ if (spec->ch != SECUREC_CHAR('e') && spec->ch != SECUREC_CHAR('E')) {
+ SecUnGetChar(spec->ch, stream, &(spec->charCount));
+ return 0;
+ }
+ SECUREC_FILED_WIDTH_DEC(spec); /* Must be behind un get char, otherwise the logic is incorrect */
+ floatSpec->floatStr[floatSpec->floatStrUsedLen] = SECUREC_CHAR('e');
+ ++floatSpec->floatStrUsedLen;
+ if (SecExtendFloatLen(floatSpec) != 0) {
+ return -1;
+ }
+ if (SecInputFloatE(stream, spec, floatSpec) != 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+* Scan %f.
+* Return 0 OK
+*/
+SECUREC_INLINE int SecInputFloat(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec)
+{
+ floatSpec->floatStrUsedLen = 0;
+
+ /* The following code sequence is strict */
+ if (SecInputFloatSign(stream, spec, floatSpec) != 0) {
+ return -1;
+ }
+ if (SecInputFloatDigit(stream, spec, floatSpec) != 0) {
+ return -1;
+ }
+ if (SecInputFloatFractional(stream, spec, floatSpec) != 0) {
+ return -1;
+ }
+ if (SecInputFloatExponent(stream, spec, floatSpec) != 0) {
+ return -1;
+ }
+
+ /* Make sure have a string terminator, buffer is large enough */
+ floatSpec->floatStr[floatSpec->floatStrUsedLen] = SECUREC_CHAR('\0');
+ if (spec->numberState == SECUREC_NUMBER_STATE_STARTED) {
+ return 0;
+ }
+ return -1;
+}
+#endif
+
+#if (!defined(SECUREC_FOR_WCHAR) && SECUREC_HAVE_WCHART && SECUREC_HAVE_MBTOWC) || \
+ (!defined(SECUREC_FOR_WCHAR) && defined(SECUREC_COMPATIBLE_VERSION))
+/* LSD only multi-bytes string need isleadbyte() function */
+SECUREC_INLINE int SecIsLeadByte(SecInt ch)
+{
+ unsigned int c = (unsigned int)ch;
+#if !(defined(_MSC_VER) || defined(_INC_WCTYPE))
+ return (int)(c & 0x80U); /* Use bitwise operation to check if the most significant bit is 1 */
+#else
+ return (int)isleadbyte((int)(c & 0xffU)); /* Use bitwise operations to limit character values to valid ranges */
+#endif
+}
+#endif
+
+/*
+ * Parsing whether it is a wide character
+ */
+SECUREC_INLINE void SecUpdateWcharFlagByType(SecUnsignedChar ch, SecScanSpec *spec)
+{
+ if (spec->isWCharOrLong != 0) {
+ /* Wide character identifiers have been explicitly set by l or h flag */
+ return;
+ }
+
+ /* Set default flag */
+#if defined(SECUREC_FOR_WCHAR) && defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+ spec->isWCharOrLong = 1; /* On windows wide char version %c %s %[ is wide char */
+#else
+ spec->isWCharOrLong = -1; /* On linux all version %c %s %[ is multi char */
+#endif
+
+ if (ch == SECUREC_CHAR('C') || ch == SECUREC_CHAR('S')) {
+#if defined(SECUREC_FOR_WCHAR) && defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+ spec->isWCharOrLong = -1; /* On windows wide char version %C %S is multi char */
+#else
+ spec->isWCharOrLong = 1; /* On linux all version %C %S is wide char */
+#endif
+ }
+
+ return;
+}
+/*
+ * Decode %l %ll
+ */
+SECUREC_INLINE void SecDecodeScanQualifierL(const SecUnsignedChar **format, SecScanSpec *spec)
+{
+ const SecUnsignedChar *fmt = *format;
+ if (*(fmt + 1) == SECUREC_CHAR('l')) {
+ spec->numberArgType = 1;
+ spec->numberWidth = SECUREC_NUM_WIDTH_LONG_LONG;
+ ++fmt;
+ } else {
+ spec->numberWidth = SECUREC_NUM_WIDTH_LONG;
+#if defined(SECUREC_ON_64BITS) && !(defined(SECUREC_COMPATIBLE_WIN_FORMAT))
+ /* On window 64 system sizeof long is 32bit */
+ spec->numberArgType = 1;
+#endif
+ spec->isWCharOrLong = 1;
+ }
+ *format = fmt;
+}
+
+/*
+ * Decode %I %I43 %I64 %Id %Ii %Io ...
+ * Set finishFlag to 1 finish Flag
+ */
+SECUREC_INLINE void SecDecodeScanQualifierI(const SecUnsignedChar **format, SecScanSpec *spec, int *finishFlag)
+{
+ const SecUnsignedChar *fmt = *format;
+ if ((*(fmt + 1) == SECUREC_CHAR('6')) &&
+ (*(fmt + 2) == SECUREC_CHAR('4'))) { /* Offset 2 for I64 */
+ spec->numberArgType = 1;
+ *format = *format + 2; /* Add 2 to skip I64 point to '4' next loop will inc */
+ } else if ((*(fmt + 1) == SECUREC_CHAR('3')) &&
+ (*(fmt + 2) == SECUREC_CHAR('2'))) { /* Offset 2 for I32 */
+ *format = *format + 2; /* Add 2 to skip I32 point to '2' next loop will inc */
+ } else if ((*(fmt + 1) == SECUREC_CHAR('d')) ||
+ (*(fmt + 1) == SECUREC_CHAR('i')) ||
+ (*(fmt + 1) == SECUREC_CHAR('o')) ||
+ (*(fmt + 1) == SECUREC_CHAR('x')) ||
+ (*(fmt + 1) == SECUREC_CHAR('X'))) {
+ spec->numberArgType = SecNumberArgType(sizeof(void *));
+ } else {
+ /* For %I */
+ spec->numberArgType = SecNumberArgType(sizeof(void *));
+ *finishFlag = 1;
+ }
+}
+
+SECUREC_INLINE int SecDecodeScanWidth(const SecUnsignedChar **format, SecScanSpec *spec)
+{
+ const SecUnsignedChar *fmt = *format;
+ while (SecIsDigit((SecInt)(int)(*fmt)) != 0) {
+ spec->widthSet = 1;
+ if (SECUREC_MUL_TEN_ADD_BEYOND_MAX(spec->width)) {
+ return -1;
+ }
+ spec->width = (int)SECUREC_MUL_TEN((unsigned int)spec->width) + (unsigned char)(*fmt - SECUREC_CHAR('0'));
+ ++fmt;
+ }
+ *format = fmt;
+ return 0;
+}
+
+/*
+ * Init default flags for each format. do not init ch this variable is context-dependent
+ */
+SECUREC_INLINE void SecSetDefaultScanSpec(SecScanSpec *spec)
+{
+ /* The ch and charCount member variables cannot be initialized here */
+ spec->argPtr = NULL;
+ spec->arrayWidth = 0;
+ spec->number64 = 0;
+ spec->number = 0;
+ spec->numberWidth = SECUREC_NUM_WIDTH_INT; /* 0 = SHORT, 1 = int, > 1 long or L_DOUBLE */
+ spec->numberArgType = 0; /* 1 for 64-bit integer, 0 otherwise */
+ spec->width = 0;
+ spec->widthSet = 0;
+ spec->convChr = 0;
+ spec->oriConvChr = 0;
+ spec->isWCharOrLong = 0;
+ spec->suppress = 0;
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ spec->beyondMax = 0;
+#endif
+ spec->negative = 0;
+ spec->numberState = SECUREC_NUMBER_STATE_DEFAULT;
+}
+
+/*
+ * Decode qualifier %I %L %h ...
+ * Set finishFlag to 1 finish Flag
+ */
+SECUREC_INLINE void SecDecodeScanQualifier(const SecUnsignedChar **format, SecScanSpec *spec, int *finishFlag)
+{
+ switch (**format) {
+ case SECUREC_CHAR('F'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('N'):
+ break;
+ case SECUREC_CHAR('h'):
+ --spec->numberWidth; /* The h for SHORT , hh for CHAR */
+ spec->isWCharOrLong = -1;
+ break;
+#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
+ case SECUREC_CHAR('j'):
+ spec->numberWidth = SECUREC_NUM_WIDTH_LONG_LONG; /* For intmax_t or uintmax_t */
+ spec->numberArgType = 1;
+ break;
+ case SECUREC_CHAR('t'): /* fall-through */ /* FALLTHRU */
+#endif
+#if SECUREC_IN_KERNEL
+ case SECUREC_CHAR('Z'): /* fall-through */ /* FALLTHRU */
+#endif
+ case SECUREC_CHAR('z'):
+#ifdef SECUREC_ON_64BITS
+ spec->numberWidth = SECUREC_NUM_WIDTH_LONG_LONG;
+ spec->numberArgType = 1;
+#else
+ spec->numberWidth = SECUREC_NUM_WIDTH_LONG;
+#endif
+ break;
+ case SECUREC_CHAR('L'): /* For long double */ /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('q'):
+ spec->numberWidth = SECUREC_NUM_WIDTH_LONG_LONG;
+ spec->numberArgType = 1;
+ break;
+ case SECUREC_CHAR('l'):
+ SecDecodeScanQualifierL(format, spec);
+ break;
+ case SECUREC_CHAR('w'):
+ spec->isWCharOrLong = 1;
+ break;
+ case SECUREC_CHAR('*'):
+ spec->suppress = 1;
+ break;
+ case SECUREC_CHAR('I'):
+ SecDecodeScanQualifierI(format, spec, finishFlag);
+ break;
+ default:
+ *finishFlag = 1;
+ break;
+ }
+}
+/*
+ * Decode width and qualifier in format
+ */
+SECUREC_INLINE int SecDecodeScanFlag(const SecUnsignedChar **format, SecScanSpec *spec)
+{
+ const SecUnsignedChar *fmt = *format;
+ int finishFlag = 0;
+
+ do {
+ ++fmt; /* First skip % , next seek fmt */
+ /* May %*6d , so put it inside the loop */
+ if (SecDecodeScanWidth(&fmt, spec) != 0) {
+ return -1;
+ }
+ SecDecodeScanQualifier(&fmt, spec, &finishFlag);
+ } while (finishFlag == 0);
+ *format = fmt;
+ return 0;
+}
+
+/*
+ * Judging whether a zeroing buffer is needed according to different formats
+ */
+SECUREC_INLINE int SecDecodeClearFormat(const SecUnsignedChar *format, int *convChr)
+{
+ const SecUnsignedChar *fmt = format;
+ /* To lowercase */
+ int ch = SECUREC_TO_LOWERCASE(*fmt);
+ if (!(ch == 'c' || ch == 's' || ch == SECUREC_BRACE)) {
+ return -1; /* First argument is not a string type */
+ }
+ if (ch == SECUREC_BRACE) {
+#if !(defined(SECUREC_COMPATIBLE_WIN_FORMAT))
+ if (*fmt == SECUREC_CHAR('{')) {
+ return -1;
+ }
+#endif
+ ++fmt;
+ if (*fmt == SECUREC_CHAR('^')) {
+ ++fmt;
+ }
+ if (*fmt == SECUREC_CHAR(']')) {
+ ++fmt;
+ }
+ while (*fmt != SECUREC_CHAR('\0') && *fmt != SECUREC_CHAR(']')) {
+ ++fmt;
+ }
+ if (*fmt == SECUREC_CHAR('\0')) {
+ return -1; /* Trunc'd format string */
+ }
+ }
+ *convChr = ch;
+ return 0;
+}
+
+/*
+ * Add L'\0' for wchar string , add '\0' for char string
+ */
+SECUREC_INLINE void SecAddEndingZero(void *ptr, const SecScanSpec *spec)
+{
+ if (spec->suppress == 0) {
+ *(char *)ptr = '\0';
+#if SECUREC_HAVE_WCHART
+ if (spec->isWCharOrLong > 0) {
+ *(wchar_t UNALIGNED *)ptr = L'\0';
+ }
+#endif
+ }
+}
+
+SECUREC_INLINE void SecDecodeClearArg(SecScanSpec *spec, va_list argList)
+{
+ va_list argListSave; /* Backup for argList value, this variable don't need initialized */
+ (void)memset(&argListSave, 0, sizeof(va_list)); /* To clear e530 argListSave not initialized */
+#if defined(va_copy)
+ va_copy(argListSave, argList);
+#elif defined(__va_copy) /* For vxworks */
+ __va_copy(argListSave, argList);
+#else
+ argListSave = argList;
+#endif
+ spec->argPtr = (void *)va_arg(argListSave, void *);
+ /* Get the next argument, size of the array in characters */
+ /* Use 0xffffffffUL mask to Support pass integer as array length */
+ spec->arrayWidth = ((size_t)(va_arg(argListSave, size_t))) & 0xffffffffUL;
+ va_end(argListSave);
+ /* To clear e438 last value assigned not used , the compiler will optimize this code */
+ (void)argListSave;
+}
+
+#ifdef SECUREC_FOR_WCHAR
+/*
+ * Clean up the first %s %c buffer to zero for wchar version
+ */
+void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, va_list argList)
+#else
+/*
+ * Clean up the first %s %c buffer to zero for char version
+ */
+void SecClearDestBuf(const char *buffer, const char *format, va_list argList)
+#endif
+{
+ SecScanSpec spec;
+ int convChr = 0;
+ const SecUnsignedChar *fmt = (const SecUnsignedChar *)format;
+ if (fmt == NULL) {
+ return;
+ }
+
+ /* Find first % */
+ while (*fmt != SECUREC_CHAR('\0') && *fmt != SECUREC_CHAR('%')) {
+ ++fmt;
+ }
+ if (*fmt == SECUREC_CHAR('\0')) {
+ return;
+ }
+
+ SecSetDefaultScanSpec(&spec);
+ if (SecDecodeScanFlag(&fmt, &spec) != 0) {
+ return;
+ }
+
+ /* Update wchar flag for %S %C */
+ SecUpdateWcharFlagByType(*fmt, &spec);
+ if (spec.suppress != 0) {
+ return;
+ }
+
+ if (SecDecodeClearFormat(fmt, &convChr) != 0) {
+ return;
+ }
+
+ if (buffer != NULL && *buffer != SECUREC_CHAR('\0') && convChr != 's') {
+ /*
+ * When buffer not empty just clear %s.
+ * Example call sscanf by argment of (" \n", "%s", s, sizeof(s))
+ */
+ return;
+ }
+
+ SecDecodeClearArg(&spec, argList);
+ /* There is no need to judge the upper limit */
+ if (spec.arrayWidth == 0 || spec.argPtr == NULL) {
+ return;
+ }
+ /* Clear one char */
+ SecAddEndingZero(spec.argPtr, &spec);
+ return;
+}
+
+/*
+ * Assign number to output buffer
+ */
+SECUREC_INLINE void SecAssignNumber(const SecScanSpec *spec)
+{
+ void *argPtr = spec->argPtr;
+ if (spec->numberArgType != 0) {
+#if defined(SECUREC_VXWORKS_PLATFORM)
+#if defined(SECUREC_VXWORKS_PLATFORM_COMP)
+ *(SecInt64 UNALIGNED *)argPtr = (SecInt64)(spec->number64);
+#else
+ /* Take number64 as unsigned number unsigned to int clear Compile warning */
+ *(SecInt64 UNALIGNED *)argPtr = *(SecUnsignedInt64 *)(&(spec->number64));
+#endif
+#else
+ /* Take number64 as unsigned number */
+ *(SecInt64 UNALIGNED *)argPtr = (SecInt64)(spec->number64);
+#endif
+ return;
+ }
+ if (spec->numberWidth > SECUREC_NUM_WIDTH_INT) {
+ /* Take number as unsigned number */
+ *(long UNALIGNED *)argPtr = (long)(spec->number);
+ } else if (spec->numberWidth == SECUREC_NUM_WIDTH_INT) {
+ *(int UNALIGNED *)argPtr = (int)(spec->number);
+ } else if (spec->numberWidth == SECUREC_NUM_WIDTH_SHORT) {
+ /* Take number as unsigned number */
+ *(short UNALIGNED *)argPtr = (short)(spec->number);
+ } else { /* < 0 for hh format modifier */
+ /* Take number as unsigned number */
+ *(char UNALIGNED *)argPtr = (char)(spec->number);
+ }
+}
+
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+/*
+ * Judge the long bit width
+ */
+SECUREC_INLINE int SecIsLongBitEqual(int bitNum)
+{
+ return (int)((unsigned int)bitNum == SECUREC_LONG_BIT_NUM);
+}
+#endif
+
+/*
+ * Convert hexadecimal characters to decimal value
+ */
+SECUREC_INLINE int SecHexValueOfChar(SecInt ch)
+{
+ /* Use isdigt Causing tool false alarms */
+ return (int)((ch >= '0' && ch <= '9') ? ((unsigned char)ch - '0') :
+ ((((unsigned char)ch | (unsigned char)('a' - 'A')) - ('a')) + 10)); /* Adding 10 is to hex value */
+}
+
+/*
+ * Parse decimal character to integer for 32bit .
+ */
+static void SecDecodeNumberDecimal(SecScanSpec *spec)
+{
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ unsigned long decimalEdge = SECUREC_MAX_32BITS_VALUE_DIV_TEN;
+#ifdef SECUREC_ON_64BITS
+ if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) {
+ decimalEdge = (unsigned long)SECUREC_MAX_64BITS_VALUE_DIV_TEN;
+ }
+#endif
+ if (spec->number > decimalEdge) {
+ spec->beyondMax = 1;
+ }
+#endif
+ spec->number = SECUREC_MUL_TEN(spec->number);
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ if (spec->number == SECUREC_MUL_TEN(decimalEdge)) {
+ /* This code is specially converted to unsigned long type for compatibility */
+ SecUnsignedInt64 number64As = (unsigned long)SECUREC_MAX_64BITS_VALUE - spec->number;
+ if (number64As < (SecUnsignedInt64)((SecUnsignedInt)spec->ch - SECUREC_CHAR('0'))) {
+ spec->beyondMax = 1;
+ }
+ }
+#endif
+ spec->number += (unsigned long)((SecUnsignedInt)spec->ch - SECUREC_CHAR('0'));
+}
+
+/*
+ * Parse Hex character to integer for 32bit .
+ */
+static void SecDecodeNumberHex(SecScanSpec *spec)
+{
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ if (SECUREC_LONG_HEX_BEYOND_MAX(spec->number)) {
+ spec->beyondMax = 1;
+ }
+#endif
+ spec->number = SECUREC_MUL_SIXTEEN(spec->number);
+ spec->number += (unsigned long)(unsigned int)SecHexValueOfChar(spec->ch);
+}
+
+/*
+ * Parse Octal character to integer for 32bit .
+ */
+static void SecDecodeNumberOctal(SecScanSpec *spec)
+{
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ if (SECUREC_LONG_OCTAL_BEYOND_MAX(spec->number)) {
+ spec->beyondMax = 1;
+ }
+#endif
+ spec->number = SECUREC_MUL_EIGHT(spec->number);
+ spec->number += (unsigned long)((SecUnsignedInt)spec->ch - SECUREC_CHAR('0'));
+}
+
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+/* Compatible with integer negative values other than int */
+SECUREC_INLINE void SecFinishNumberNegativeOther(SecScanSpec *spec)
+{
+ if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) {
+ if (spec->number > SECUREC_MIN_LONG_NEG_VALUE) {
+ spec->number = SECUREC_MIN_LONG_NEG_VALUE;
+ } else {
+ spec->number = (unsigned long)(0U - spec->number); /* Wrap with unsigned long numbers */
+ }
+ if (spec->beyondMax != 0) {
+ if (spec->numberWidth < SECUREC_NUM_WIDTH_INT) {
+ spec->number = 0;
+ }
+ if (spec->numberWidth == SECUREC_NUM_WIDTH_LONG) {
+ spec->number = SECUREC_MIN_LONG_NEG_VALUE;
+ }
+ }
+ } else { /* For o, u, x, X, p */
+ spec->number = (unsigned long)(0U - spec->number); /* Wrap with unsigned long numbers */
+ if (spec->beyondMax != 0) {
+ spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE;
+ }
+ }
+}
+/* Compatible processing of integer negative numbers */
+SECUREC_INLINE void SecFinishNumberNegativeInt(SecScanSpec *spec)
+{
+ if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) {
+#ifdef SECUREC_ON_64BITS
+ if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) {
+ if ((spec->number > SECUREC_MIN_64BITS_NEG_VALUE)) {
+ spec->number = 0;
+ } else {
+ spec->number = (unsigned int)(0U - (unsigned int)spec->number); /* Wrap with unsigned int numbers */
+ }
+ }
+#else
+ if (SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH) != 0) {
+ if ((spec->number > SECUREC_MIN_32BITS_NEG_VALUE)) {
+ spec->number = SECUREC_MIN_32BITS_NEG_VALUE;
+ } else {
+ spec->number = (unsigned int)(0U - (unsigned int)spec->number); /* Wrap with unsigned int numbers */
+ }
+ }
+#endif
+ if (spec->beyondMax != 0) {
+#ifdef SECUREC_ON_64BITS
+ if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) {
+ spec->number = 0;
+ }
+#else
+ if (SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH) != 0) {
+ spec->number = SECUREC_MIN_32BITS_NEG_VALUE;
+ }
+#endif
+ }
+ } else { /* For o, u, x, X ,p */
+#ifdef SECUREC_ON_64BITS
+ if (spec->number > SECUREC_MAX_32BITS_VALUE_INC) {
+ spec->number = SECUREC_MAX_32BITS_VALUE;
+ } else {
+ spec->number = (unsigned int)(0U - (unsigned int)spec->number); /* Wrap with unsigned int numbers */
+ }
+#else
+ spec->number = (unsigned int)(0U - (unsigned int)spec->number); /* Wrap with unsigned int numbers */
+#endif
+ if (spec->beyondMax != 0) {
+ spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE;
+ }
+ }
+}
+
+/* Compatible with integer positive values other than int */
+SECUREC_INLINE void SecFinishNumberPositiveOther(SecScanSpec *spec)
+{
+ if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) {
+ if (spec->number > SECUREC_MAX_LONG_POS_VALUE) {
+ spec->number = SECUREC_MAX_LONG_POS_VALUE;
+ }
+ if ((spec->beyondMax != 0 && spec->numberWidth < SECUREC_NUM_WIDTH_INT)) {
+ spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE;
+ }
+ if (spec->beyondMax != 0 && spec->numberWidth == SECUREC_NUM_WIDTH_LONG) {
+ spec->number = SECUREC_MAX_LONG_POS_VALUE;
+ }
+ } else {
+ if (spec->beyondMax != 0) {
+ spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE;
+ }
+ }
+}
+
+/* Compatible processing of integer positive numbers */
+SECUREC_INLINE void SecFinishNumberPositiveInt(SecScanSpec *spec)
+{
+ if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) {
+#ifdef SECUREC_ON_64BITS
+ if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) {
+ if (spec->number > SECUREC_MAX_64BITS_POS_VALUE) {
+ spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE;
+ }
+ }
+ if (spec->beyondMax != 0 && SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) {
+ spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE;
+ }
+#else
+ if (SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH) != 0) {
+ if (spec->number > SECUREC_MAX_32BITS_POS_VALUE) {
+ spec->number = SECUREC_MAX_32BITS_POS_VALUE;
+ }
+ }
+ if (spec->beyondMax != 0 && SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH) != 0) {
+ spec->number = SECUREC_MAX_32BITS_POS_VALUE;
+ }
+#endif
+ } else { /* For o,u,x,X,p */
+ if (spec->beyondMax != 0) {
+ spec->number = SECUREC_MAX_32BITS_VALUE;
+ }
+ }
+}
+
+#endif
+
+/*
+ * Parse decimal character to integer for 64bit .
+ */
+static void SecDecodeNumber64Decimal(SecScanSpec *spec)
+{
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ if (spec->number64 > SECUREC_MAX_64BITS_VALUE_DIV_TEN) {
+ spec->beyondMax = 1;
+ }
+#endif
+ spec->number64 = SECUREC_MUL_TEN(spec->number64);
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ if (spec->number64 == SECUREC_MAX_64BITS_VALUE_CUT_LAST_DIGIT) {
+ SecUnsignedInt64 number64As = (SecUnsignedInt64)SECUREC_MAX_64BITS_VALUE - spec->number64;
+ if (number64As < (SecUnsignedInt64)((SecUnsignedInt)spec->ch - SECUREC_CHAR('0'))) {
+ spec->beyondMax = 1;
+ }
+ }
+#endif
+ spec->number64 += (SecUnsignedInt64)((SecUnsignedInt)spec->ch - SECUREC_CHAR('0'));
+}
+
+/*
+ * Parse Hex character to integer for 64bit .
+ */
+static void SecDecodeNumber64Hex(SecScanSpec *spec)
+{
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ if (SECUREC_QWORD_HEX_BEYOND_MAX(spec->number64)) {
+ spec->beyondMax = 1;
+ }
+#endif
+ spec->number64 = SECUREC_MUL_SIXTEEN(spec->number64);
+ spec->number64 += (SecUnsignedInt64)(unsigned int)SecHexValueOfChar(spec->ch);
+}
+
+/*
+ * Parse Octal character to integer for 64bit .
+ */
+static void SecDecodeNumber64Octal(SecScanSpec *spec)
+{
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ if (SECUREC_QWORD_OCTAL_BEYOND_MAX(spec->number64)) {
+ spec->beyondMax = 1;
+ }
+#endif
+ spec->number64 = SECUREC_MUL_EIGHT(spec->number64);
+ spec->number64 += (SecUnsignedInt64)((SecUnsignedInt)spec->ch - SECUREC_CHAR('0'));
+}
+
+#define SECUREC_DECODE_NUMBER_FUNC_NUM 2
+
+/*
+ * Parse 64-bit integer formatted input, return 0 when ch is a number.
+ */
+SECUREC_INLINE int SecDecodeNumber(SecScanSpec *spec)
+{
+ /* Function name cannot add address symbol, causing 546 alarm */
+ static void (*secDecodeNumberHex[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = {
+ SecDecodeNumberHex, SecDecodeNumber64Hex
+ };
+ static void (*secDecodeNumberOctal[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = {
+ SecDecodeNumberOctal, SecDecodeNumber64Octal
+ };
+ static void (*secDecodeNumberDecimal[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = {
+ SecDecodeNumberDecimal, SecDecodeNumber64Decimal
+ };
+ if (spec->convChr == 'x' || spec->convChr == 'p') {
+ if (SecIsXdigit(spec->ch) != 0) {
+ (*secDecodeNumberHex[spec->numberArgType])(spec);
+ } else {
+ return -1;
+ }
+ return 0;
+ }
+ if (SecIsDigit(spec->ch) == 0) {
+ return -1;
+ }
+ if (spec->convChr == 'o') {
+ if (spec->ch < SECUREC_CHAR('8')) { /* Octal maximum limit '8' */
+ (*secDecodeNumberOctal[spec->numberArgType])(spec);
+ } else {
+ return -1;
+ }
+ } else { /* The convChr is 'd' */
+ (*secDecodeNumberDecimal[spec->numberArgType])(spec);
+ }
+ return 0;
+}
+
+/*
+ * Complete the final 32-bit integer formatted input
+ */
+static void SecFinishNumber(SecScanSpec *spec)
+{
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ if (spec->negative != 0) {
+ if (spec->numberWidth == SECUREC_NUM_WIDTH_INT) {
+ SecFinishNumberNegativeInt(spec);
+ } else {
+ SecFinishNumberNegativeOther(spec);
+ }
+ } else {
+ if (spec->numberWidth == SECUREC_NUM_WIDTH_INT) {
+ SecFinishNumberPositiveInt(spec);
+ } else {
+ SecFinishNumberPositiveOther(spec);
+ }
+ }
+#else
+ if (spec->negative != 0) {
+#if defined(__hpux)
+ if (spec->oriConvChr != 'p') {
+ spec->number = (unsigned long)(0U - spec->number); /* Wrap with unsigned long numbers */
+ }
+#else
+ spec->number = (unsigned long)(0U - spec->number); /* Wrap with unsigned long numbers */
+#endif
+ }
+#endif
+ return;
+}
+
+/*
+ * Complete the final 64-bit integer formatted input
+ */
+static void SecFinishNumber64(SecScanSpec *spec)
+{
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX)))
+ if (spec->negative != 0) {
+ if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) {
+ if (spec->number64 > SECUREC_MIN_64BITS_NEG_VALUE) {
+ spec->number64 = SECUREC_MIN_64BITS_NEG_VALUE;
+ } else {
+ spec->number64 = (SecUnsignedInt64)(0U - spec->number64); /* Wrap with unsigned int64 numbers */
+ }
+ if (spec->beyondMax != 0) {
+ spec->number64 = SECUREC_MIN_64BITS_NEG_VALUE;
+ }
+ } else { /* For o, u, x, X, p */
+ spec->number64 = (SecUnsignedInt64)(0U - spec->number64); /* Wrap with unsigned int64 numbers */
+ if (spec->beyondMax != 0) {
+ spec->number64 = SECUREC_MAX_64BITS_VALUE;
+ }
+ }
+ } else {
+ if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) {
+ if (spec->number64 > SECUREC_MAX_64BITS_POS_VALUE) {
+ spec->number64 = SECUREC_MAX_64BITS_POS_VALUE;
+ }
+ if (spec->beyondMax != 0) {
+ spec->number64 = SECUREC_MAX_64BITS_POS_VALUE;
+ }
+ } else {
+ if (spec->beyondMax != 0) {
+ spec->number64 = SECUREC_MAX_64BITS_VALUE;
+ }
+ }
+ }
+#else
+ if (spec->negative != 0) {
+#if defined(__hpux)
+ if (spec->oriConvChr != 'p') {
+ spec->number64 = (SecUnsignedInt64)(0U - spec->number64); /* Wrap with unsigned int64 numbers */
+ }
+#else
+ spec->number64 = (SecUnsignedInt64)(0U - spec->number64); /* Wrap with unsigned int64 numbers */
+#endif
+ }
+#endif
+ return;
+}
+
+#if SECUREC_ENABLE_SCANF_FILE
+
+/*
+ * Adjust the pointer position of the file stream
+ */
+SECUREC_INLINE void SecSeekStream(SecFileStream *stream)
+{
+ if (stream->count == 0) {
+ if (feof(stream->pf) != 0) {
+ /* File pointer at the end of file, don't need to seek back */
+ stream->base[0] = '\0';
+ return;
+ }
+ }
+ /* Seek to original position, for file read, but nothing to input */
+ if (fseek(stream->pf, stream->oriFilePos, SEEK_SET) != 0) {
+ /* Seek failed, ignore it */
+ stream->oriFilePos = 0;
+ return;
+ }
+
+ if (stream->fileRealRead > 0) { /* Do not seek without input data */
+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+ size_t residue = stream->fileRealRead % SECUREC_BUFFERED_BLOK_SIZE;
+ size_t loops;
+ for (loops = 0; loops < (stream->fileRealRead / SECUREC_BUFFERED_BLOK_SIZE); ++loops) {
+ if (fread(stream->base, (size_t)SECUREC_BUFFERED_BLOK_SIZE, (size_t)1, stream->pf) != (size_t)1) {
+ break;
+ }
+ }
+ if (residue != 0) {
+ long curFilePos;
+ if (fread(stream->base, residue, (size_t)1, stream->pf) != (size_t)1) {
+ return;
+ }
+ curFilePos = ftell(stream->pf);
+ if (curFilePos < stream->oriFilePos ||
+ (size_t)(unsigned long)(curFilePos - stream->oriFilePos) < stream->fileRealRead) {
+ /* Try to remedy the problem */
+ (void)fseek(stream->pf, (long)stream->fileRealRead, SEEK_CUR);
+ }
+ }
+#else
+ /* Seek from oriFilePos. Regardless of the integer sign problem, call scanf will not read very large data */
+ if (fseek(stream->pf, (long)stream->fileRealRead, SEEK_CUR) != 0) {
+ /* Seek failed, ignore it */
+ stream->oriFilePos = 0;
+ return;
+ }
+#endif
+ }
+ return;
+}
+
+/*
+ * Adjust the pointer position of the file stream and free memory
+ */
+SECUREC_INLINE void SecAdjustStream(SecFileStream *stream)
+{
+ if (stream != NULL && (stream->flag & SECUREC_FILE_STREAM_FLAG) != 0 && stream->base != NULL) {
+ SecSeekStream(stream);
+ SECUREC_FREE(stream->base);
+ stream->base = NULL;
+ }
+ return;
+}
+#endif
+
+SECUREC_INLINE void SecSkipSpaceFormat(const SecUnsignedChar **format)
+{
+ const SecUnsignedChar *fmt = *format;
+ while (SecIsSpace((SecInt)(int)(*fmt)) != 0) {
+ ++fmt;
+ }
+ *format = fmt;
+}
+
+#if !defined(SECUREC_FOR_WCHAR) && defined(SECUREC_COMPATIBLE_VERSION)
+/*
+ * Handling multi-character characters
+ */
+SECUREC_INLINE int SecDecodeLeadByte(SecScanSpec *spec, const SecUnsignedChar **format, SecFileStream *stream)
+{
+#if SECUREC_HAVE_MBTOWC
+ const SecUnsignedChar *fmt = *format;
+ int ch1 = (int)spec->ch;
+ int ch2 = SecGetChar(stream, &(spec->charCount));
+ spec->ch = (SecInt)ch2;
+ if (*fmt == SECUREC_CHAR('\0') || (int)(*fmt) != ch2) {
+ /* LSD in console mode, ungetc twice may cause problem */
+ SecUnGetChar(ch2, stream, &(spec->charCount));
+ SecUnGetChar(ch1, stream, &(spec->charCount));
+ return -1;
+ }
+ ++fmt;
+ if ((unsigned int)MB_CUR_MAX >= SECUREC_UTF8_BOM_HEADER_SIZE &&
+ (((unsigned char)ch1 & SECUREC_UTF8_LEAD_1ST) == SECUREC_UTF8_LEAD_1ST) &&
+ (((unsigned char)ch2 & SECUREC_UTF8_LEAD_2ND) == SECUREC_UTF8_LEAD_2ND)) {
+ /* This char is very likely to be a UTF-8 char */
+ wchar_t tempWChar;
+ char temp[SECUREC_MULTI_BYTE_MAX_LEN];
+ int ch3 = (int)SecGetChar(stream, &(spec->charCount));
+ spec->ch = (SecInt)ch3;
+ if (*fmt == SECUREC_CHAR('\0') || (int)(*fmt) != ch3) {
+ SecUnGetChar(ch3, stream, &(spec->charCount));
+ return -1;
+ }
+ temp[0] = (char)ch1;
+ temp[1] = (char)ch2; /* 1 index of second character */
+ temp[2] = (char)ch3; /* 2 index of third character */
+ temp[3] = '\0'; /* 3 of string terminator position */
+ if (mbtowc(&tempWChar, temp, sizeof(temp)) > 0) {
+ /* Succeed */
+ ++fmt;
+ --spec->charCount;
+ } else {
+ SecUnGetChar(ch3, stream, &(spec->charCount));
+ }
+ }
+ --spec->charCount; /* Only count as one character read */
+ *format = fmt;
+ return 0;
+#else
+ SecUnGetChar(spec->ch, stream, &(spec->charCount));
+ (void)format; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+ return -1;
+#endif
+}
+#endif
+
+/*
+ * Resolving sequence of characters from %[ format, format wile point to ']'
+ */
+SECUREC_INLINE int SecSetupBracketTable(const SecUnsignedChar **format, SecBracketTable *bracketTable)
+{
+ const SecUnsignedChar *fmt = *format;
+ SecUnsignedChar prevChar = 0;
+#if !(defined(SECUREC_COMPATIBLE_WIN_FORMAT))
+ if (*fmt == SECUREC_CHAR('{')) {
+ return -1;
+ }
+#endif
+ /* For building "table" data */
+ ++fmt; /* Skip [ */
+ bracketTable->mask = 0; /* Set all bits to 0 */
+ if (*fmt == SECUREC_CHAR('^')) {
+ ++fmt;
+ bracketTable->mask = (unsigned char)0xffU; /* Use 0xffU to set all bits to 1 */
+ }
+ if (*fmt == SECUREC_CHAR(']')) {
+ prevChar = SECUREC_CHAR(']');
+ ++fmt;
+ SecBracketSetBit(bracketTable->table, SECUREC_CHAR(']'));
+ }
+ while (*fmt != SECUREC_CHAR('\0') && *fmt != SECUREC_CHAR(']')) {
+ SecUnsignedChar expCh = *fmt;
+ ++fmt;
+ if (expCh != SECUREC_CHAR('-') || prevChar == 0 || *fmt == SECUREC_CHAR(']')) {
+ /* Normal character */
+ prevChar = expCh;
+ SecBracketSetBit(bracketTable->table, expCh);
+ } else {
+ /* For %[a-z] */
+ expCh = *fmt; /* Get end of range */
+ ++fmt;
+ if (prevChar <= expCh) { /* %[a-z] %[a-a] */
+ SecBracketSetBitRange(bracketTable->table, prevChar, expCh);
+ } else {
+ /* For %[z-a] */
+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+ /* Swap start and end characters */
+ SecBracketSetBitRange(bracketTable->table, expCh, prevChar);
+#else
+ SecBracketSetBit(bracketTable->table, SECUREC_CHAR('-'));
+ SecBracketSetBit(bracketTable->table, expCh);
+#endif
+ }
+ prevChar = 0;
+ }
+ }
+ *format = fmt;
+ return 0;
+}
+
+#ifdef SECUREC_FOR_WCHAR
+SECUREC_INLINE int SecInputForWchar(SecScanSpec *spec)
+{
+ void *endPtr = spec->argPtr;
+ if (spec->isWCharOrLong > 0) {
+ *(wchar_t UNALIGNED *)endPtr = (wchar_t)spec->ch;
+ endPtr = (wchar_t *)endPtr + 1;
+ --spec->arrayWidth;
+ } else {
+#if SECUREC_HAVE_WCTOMB
+ int temp;
+ char tmpBuf[SECUREC_MB_LEN + 1];
+ SECUREC_MASK_MSVC_CRT_WARNING temp = wctomb(tmpBuf, (wchar_t)spec->ch);
+ SECUREC_END_MASK_MSVC_CRT_WARNING
+ if (temp <= 0 || (size_t)(unsigned int)temp > sizeof(tmpBuf)) {
+ /* If wctomb error, then ignore character */
+ return 0;
+ }
+ if (((size_t)(unsigned int)temp) > spec->arrayWidth) {
+ return -1;
+ }
+ if (memcpy_s(endPtr, spec->arrayWidth, tmpBuf, (size_t)(unsigned int)temp) != EOK) {
+ return -1;
+ }
+ endPtr = (char *)endPtr + temp;
+ spec->arrayWidth -= (size_t)(unsigned int)temp;
+#else
+ return -1;
+#endif
+ }
+ spec->argPtr = endPtr;
+ return 0;
+}
+#endif
+
+#ifndef SECUREC_FOR_WCHAR
+#if SECUREC_HAVE_WCHART
+SECUREC_INLINE wchar_t SecConvertInputCharToWchar(SecScanSpec *spec, SecFileStream *stream)
+{
+ wchar_t tempWChar = L'?'; /* Set default char is ? */
+#if SECUREC_HAVE_MBTOWC
+ char temp[SECUREC_MULTI_BYTE_MAX_LEN + 1];
+ temp[0] = (char)spec->ch;
+ temp[1] = '\0';
+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+ if (SecIsLeadByte(spec->ch) != 0) {
+ spec->ch = SecGetChar(stream, &(spec->charCount));
+ temp[1] = (char)spec->ch;
+ temp[2] = '\0'; /* 2 of string terminator position */
+ }
+ if (mbtowc(&tempWChar, temp, sizeof(temp)) <= 0) {
+ /* No string termination error for tool */
+ tempWChar = L'?';
+ }
+#else
+ if (SecIsLeadByte(spec->ch) != 0) {
+ int convRes = 0;
+ int di = 1;
+ /* On Linux like system, the string is encoded in UTF-8 */
+ while (convRes <= 0 && di < (int)MB_CUR_MAX && di < SECUREC_MULTI_BYTE_MAX_LEN) {
+ spec->ch = SecGetChar(stream, &(spec->charCount));
+ temp[di] = (char)spec->ch;
+ ++di;
+ temp[di] = '\0';
+ convRes = mbtowc(&tempWChar, temp, sizeof(temp));
+ }
+ if (convRes <= 0) {
+ tempWChar = L'?';
+ }
+ } else {
+ if (mbtowc(&tempWChar, temp, sizeof(temp)) <= 0) {
+ tempWChar = L'?';
+ }
+ }
+#endif
+#else
+ (void)spec; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+ (void)stream; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+#endif /* SECUREC_HAVE_MBTOWC */
+
+ return tempWChar;
+}
+#endif /* SECUREC_HAVE_WCHART */
+
+SECUREC_INLINE int SecInputForChar(SecScanSpec *spec, SecFileStream *stream)
+{
+ void *endPtr = spec->argPtr;
+ if (spec->isWCharOrLong > 0) {
+#if SECUREC_HAVE_WCHART
+ *(wchar_t UNALIGNED *)endPtr = SecConvertInputCharToWchar(spec, stream);
+ endPtr = (wchar_t *)endPtr + 1;
+ --spec->arrayWidth;
+#else
+ (void)stream; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+ return -1;
+#endif
+ } else {
+ *(char *)endPtr = (char)spec->ch;
+ endPtr = (char *)endPtr + 1;
+ --spec->arrayWidth;
+ }
+ spec->argPtr = endPtr;
+ return 0;
+}
+#endif
+
+/*
+ * Scan digital part of %d %i %o %u %x %p.
+ * Return 0 OK
+ */
+SECUREC_INLINE int SecInputNumberDigital(SecFileStream *stream, SecScanSpec *spec)
+{
+ static void (*secFinishNumber[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = {
+ SecFinishNumber, SecFinishNumber64
+ };
+ while (SECUREC_FILED_WIDTH_ENOUGH(spec)) {
+ spec->ch = SecGetChar(stream, &(spec->charCount));
+ /* Decode ch to number */
+ if (SecDecodeNumber(spec) != 0) {
+ SecUnGetChar(spec->ch, stream, &(spec->charCount));
+ break;
+ }
+ SECUREC_FILED_WIDTH_DEC(spec); /* Must be behind un get char, otherwise the logic is incorrect */
+ spec->numberState = SECUREC_NUMBER_STATE_STARTED;
+ }
+ /* Handling integer negative numbers and beyond max */
+ (*secFinishNumber[spec->numberArgType])(spec);
+ if (spec->numberState == SECUREC_NUMBER_STATE_STARTED) {
+ return 0;
+ }
+ return -1;
+}
+
+/*
+ * Scan %d %i %o %u %x %p.
+ * Return 0 OK
+ */
+SECUREC_INLINE int SecInputNumber(SecFileStream *stream, SecScanSpec *spec)
+{
+ /* Character already read */
+ if (spec->ch == SECUREC_CHAR('+') || spec->ch == SECUREC_CHAR('-')) {
+ if (spec->ch == SECUREC_CHAR('-')) {
+ spec->negative = 1;
+#if SECUREC_IN_KERNEL
+ /* In kernel Refuse to enter negative number */
+ if (SECUREC_CONVERT_IS_UNSIGNED(spec->oriConvChr)) {
+ return -1;
+ }
+#endif
+ }
+ SECUREC_FILED_WIDTH_DEC(spec); /* Do not need to check width here, must be greater than 0 */
+ spec->ch = SecGetChar(stream, &(spec->charCount)); /* Eat + or - */
+ spec->ch = SecGetChar(stream, &(spec->charCount)); /* Get next character, used for the '0' judgments */
+ SecUnGetChar(spec->ch, stream, &(spec->charCount)); /* Not sure if it was actually read, so push back */
+ }
+
+ if (spec->oriConvChr == 'i') {
+ spec->convChr = 'd'; /* The i could be d, o, or x, use d as default */
+ }
+
+ if (spec->ch == SECUREC_CHAR('0') && (spec->oriConvChr == 'x' || spec->oriConvChr == 'i') &&
+ SECUREC_FILED_WIDTH_ENOUGH(spec)) {
+ /* Input string begin with 0, may be 0x123 0X123 0123 0x 01 0yy 09 0 0ab 00 */
+ SECUREC_FILED_WIDTH_DEC(spec);
+ spec->ch = SecGetChar(stream, &(spec->charCount)); /* ch is '0' */
+
+ /* Read only '0' due to width limitation */
+ if (!SECUREC_FILED_WIDTH_ENOUGH(spec)) {
+ /* The number or number64 in spec has been set 0 */
+ return 0;
+ }
+
+ spec->ch = SecGetChar(stream, &(spec->charCount)); /* Get next char to check x or X, do not dec width */
+ if ((SecChar)spec->ch == SECUREC_CHAR('x') || (SecChar)spec->ch == SECUREC_CHAR('X')) {
+ spec->convChr = 'x';
+ SECUREC_FILED_WIDTH_DEC(spec); /* Make incorrect width for x or X */
+ } else {
+ if (spec->oriConvChr == 'i') {
+ spec->convChr = 'o';
+ }
+ /* For "0y" "08" "01" "0a" ... ,push the 'y' '8' '1' 'a' back */
+ SecUnGetChar(spec->ch, stream, &(spec->charCount));
+ /* Since 0 has been read, it indicates that a valid character has been read */
+ spec->numberState = SECUREC_NUMBER_STATE_STARTED;
+ }
+ }
+ return SecInputNumberDigital(stream, spec);
+}
+
+/*
+ * Scan %c %s %[
+ * Return 0 OK
+ */
+SECUREC_INLINE int SecInputString(SecFileStream *stream, SecScanSpec *spec,
+ const SecBracketTable *bracketTable, int *doneCount)
+{
+ void *startPtr = spec->argPtr;
+ int suppressed = 0;
+ int errNoMem = 0;
+
+ while (SECUREC_FILED_WIDTH_ENOUGH(spec)) {
+ SECUREC_FILED_WIDTH_DEC(spec);
+ spec->ch = SecGetChar(stream, &(spec->charCount));
+ /*
+ * The char condition or string condition and bracket condition.
+ * Only supports wide characters with a maximum length of two bytes
+ */
+ if (spec->ch != SECUREC_EOF && (SecCanInputCharacter(spec->convChr) != 0 ||
+ SecCanInputString(spec->convChr, spec->ch) != 0 ||
+ SecCanInputForBracket(spec->convChr, spec->ch, bracketTable) != 0)) {
+ if (spec->suppress != 0) {
+ /* Used to identify processed data for %*, use argPtr to identify will cause 613, so use suppressed */
+ suppressed = 1;
+ continue;
+ }
+ /* Now suppress is not set */
+ if (spec->arrayWidth == 0) {
+ errNoMem = 1; /* We have exhausted the user's buffer */
+ break;
+ }
+#ifdef SECUREC_FOR_WCHAR
+ errNoMem = SecInputForWchar(spec);
+#else
+ errNoMem = SecInputForChar(spec, stream);
+#endif
+ if (errNoMem != 0) {
+ break;
+ }
+ } else {
+ SecUnGetChar(spec->ch, stream, &(spec->charCount));
+ break;
+ }
+ }
+
+ if (errNoMem != 0) {
+ /* In case of error, blank out the input buffer */
+ SecAddEndingZero(startPtr, spec);
+ return -1;
+ }
+ if ((spec->suppress != 0 && suppressed == 0) ||
+ (spec->suppress == 0 && startPtr == spec->argPtr)) {
+ /* No input was scanned */
+ return -1;
+ }
+ if (spec->convChr != 'c') {
+ /* Add null-terminate for strings */
+ SecAddEndingZero(spec->argPtr, spec);
+ }
+ if (spec->suppress == 0) {
+ *doneCount = *doneCount + 1;
+ }
+ return 0;
+}
+
+#ifdef SECUREC_FOR_WCHAR
+/*
+ * Alloce buffer for wchar version of %[.
+ * Return 0 OK
+ */
+SECUREC_INLINE int SecAllocBracketTable(SecBracketTable *bracketTable)
+{
+ if (bracketTable->table == NULL) {
+ /* Table should be freed after use */
+ bracketTable->table = (unsigned char *)SECUREC_MALLOC(SECUREC_BRACKET_TABLE_SIZE);
+ if (bracketTable->table == NULL) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Free buffer for wchar version of %[
+ */
+SECUREC_INLINE void SecFreeBracketTable(SecBracketTable *bracketTable)
+{
+ if (bracketTable->table != NULL) {
+ SECUREC_FREE(bracketTable->table);
+ bracketTable->table = NULL;
+ }
+}
+#endif
+
+#ifdef SECUREC_FOR_WCHAR
+/*
+ * Formatting input core functions for wchar version.Called by a function such as vswscanf_s
+ */
+int SecInputSW(SecFileStream *stream, const wchar_t *cFormat, va_list argList)
+#else
+/*
+ * Formatting input core functions for char version.Called by a function such as vsscanf_s
+ */
+int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList)
+#endif
+{
+ const SecUnsignedChar *format = (const SecUnsignedChar *)cFormat;
+ SecBracketTable bracketTable = SECUREC_INIT_BRACKET_TABLE;
+ SecScanSpec spec;
+ int doneCount = 0;
+ int formatError = 0;
+ int paraIsNull = 0;
+ int match = 0; /* When % is found , inc this value */
+ int errRet = 0;
+#if SECUREC_ENABLE_SCANF_FLOAT
+ SecFloatSpec floatSpec;
+ SecInitFloatSpec(&floatSpec);
+#endif
+ spec.ch = 0; /* Need to initialize to 0 */
+ spec.charCount = 0; /* Need to initialize to 0 */
+
+ /* Format must not NULL, use err < 1 to claer 845 */
+ while (errRet < 1 && *format != SECUREC_CHAR('\0')) {
+ /* Skip space in format and space in input */
+ if (SecIsSpace((SecInt)(int)(*format)) != 0) {
+ /* Read first no space char */
+ spec.ch = SecSkipSpaceChar(stream, &(spec.charCount));
+ /* Read the EOF cannot be returned directly here, because the case of " %n" needs to be handled */
+ /* Put fist no space char backup. put EOF back is also OK, and to modify the character count */
+ SecUnGetChar(spec.ch, stream, &(spec.charCount));
+ SecSkipSpaceFormat(&format);
+ continue;
+ }
+
+ if (*format != SECUREC_CHAR('%')) {
+ spec.ch = SecGetChar(stream, &(spec.charCount));
+ if ((int)(*format) != (int)(spec.ch)) {
+ SecUnGetChar(spec.ch, stream, &(spec.charCount));
+ break;
+ }
+ ++format;
+#if !defined(SECUREC_FOR_WCHAR) && defined(SECUREC_COMPATIBLE_VERSION)
+ if (SecIsLeadByte(spec.ch) != 0) {
+ if (SecDecodeLeadByte(&spec, &format, stream) != 0) {
+ break;
+ }
+ }
+#endif
+ continue;
+ }
+
+ /* Now *format is % */
+ /* Set default value for each % */
+ SecSetDefaultScanSpec(&spec);
+ if (SecDecodeScanFlag(&format, &spec) != 0) {
+ formatError = 1;
+ ++errRet;
+ continue;
+ }
+ if (!SECUREC_FILED_WIDTH_ENOUGH(&spec)) {
+ /* 0 width in format */
+ ++errRet;
+ continue;
+ }
+
+ /* Update wchar flag for %S %C */
+ SecUpdateWcharFlagByType(*format, &spec);
+
+ spec.convChr = SECUREC_TO_LOWERCASE(*format);
+ spec.oriConvChr = spec.convChr; /* convChr may be modified to handle integer logic */
+ if (spec.convChr != 'n') {
+ if (spec.convChr != 'c' && spec.convChr != SECUREC_BRACE) {
+ spec.ch = SecSkipSpaceChar(stream, &(spec.charCount));
+ } else {
+ spec.ch = SecGetChar(stream, &(spec.charCount));
+ }
+ if (spec.ch == SECUREC_EOF) {
+ ++errRet;
+ continue;
+ }
+ }
+
+ /* Now no 0 width in format and get one char from input */
+ switch (spec.oriConvChr) {
+ case 'c': /* Also 'C' */
+ if (spec.widthSet == 0) {
+ spec.widthSet = 1;
+ spec.width = 1;
+ }
+ /* fall-through */ /* FALLTHRU */
+ case 's': /* Also 'S': */
+ /* fall-through */ /* FALLTHRU */
+ case SECUREC_BRACE:
+ /* Unset last char to stream */
+ SecUnGetChar(spec.ch, stream, &(spec.charCount));
+ /* Check dest buffer and size */
+ if (spec.suppress == 0) {
+ spec.argPtr = (void *)va_arg(argList, void *);
+ if (spec.argPtr == NULL) {
+ paraIsNull = 1;
+ ++errRet;
+ continue;
+ }
+ /* Get the next argument, size of the array in characters */
+#ifdef SECUREC_ON_64BITS
+ /* Use 0xffffffffUL mask to Support pass integer as array length */
+ spec.arrayWidth = ((size_t)(va_arg(argList, size_t))) & 0xffffffffUL;
+#else /* !SECUREC_ON_64BITS */
+ spec.arrayWidth = (size_t)va_arg(argList, size_t);
+#endif
+ if (SECUREC_ARRAY_WIDTH_IS_WRONG(spec)) {
+ /* Do not clear buffer just go error */
+ ++errRet;
+ continue;
+ }
+ /* One element is needed for '\0' for %s and %[ */
+ if (spec.convChr != 'c') {
+ --spec.arrayWidth;
+ }
+ } else {
+ /* Set argPtr to NULL is necessary, in supress mode we don't use argPtr to store data */
+ spec.argPtr = NULL;
+ }
+
+ if (spec.convChr == SECUREC_BRACE) {
+ /* Malloc when first %[ is meet for wchar version */
+#ifdef SECUREC_FOR_WCHAR
+ if (SecAllocBracketTable(&bracketTable) != 0) {
+ ++errRet;
+ continue;
+ }
+#endif
+ (void)memset(bracketTable.table, 0, (size_t)SECUREC_BRACKET_TABLE_SIZE);
+ if (SecSetupBracketTable(&format, &bracketTable) != 0) {
+ ++errRet;
+ continue;
+ }
+
+ if (*format == SECUREC_CHAR('\0')) {
+ /* Default add string terminator */
+ SecAddEndingZero(spec.argPtr, &spec);
+ ++errRet;
+ /* Truncated format */
+ continue;
+ }
+ }
+
+ /* Set completed. Now read string or character */
+ if (SecInputString(stream, &spec, &bracketTable, &doneCount) != 0) {
+ ++errRet;
+ continue;
+ }
+ break;
+ case 'p':
+ /* Make %hp same as %p */
+ spec.numberWidth = SECUREC_NUM_WIDTH_INT;
+#ifdef SECUREC_ON_64BITS
+ spec.numberArgType = 1;
+#endif
+ /* fall-through */ /* FALLTHRU */
+ case 'o': /* fall-through */ /* FALLTHRU */
+ case 'u': /* fall-through */ /* FALLTHRU */
+ case 'd': /* fall-through */ /* FALLTHRU */
+ case 'i': /* fall-through */ /* FALLTHRU */
+ case 'x':
+ /* Unset last char to stream */
+ SecUnGetChar(spec.ch, stream, &(spec.charCount));
+ if (SecInputNumber(stream, &spec) != 0) {
+ ++errRet;
+ continue;
+ }
+ if (spec.suppress == 0) {
+ spec.argPtr = (void *)va_arg(argList, void *);
+ if (spec.argPtr == NULL) {
+ paraIsNull = 1;
+ ++errRet;
+ continue;
+ }
+ SecAssignNumber(&spec);
+ ++doneCount;
+ }
+ break;
+ case 'n': /* Char count */
+ if (spec.suppress == 0) {
+ spec.argPtr = (void *)va_arg(argList, void *);
+ if (spec.argPtr == NULL) {
+ paraIsNull = 1;
+ ++errRet;
+ continue;
+ }
+ spec.number = (unsigned long)(unsigned int)(spec.charCount);
+ spec.numberArgType = 0;
+ SecAssignNumber(&spec);
+ }
+ break;
+ case 'e': /* fall-through */ /* FALLTHRU */
+ case 'f': /* fall-through */ /* FALLTHRU */
+ case 'g': /* Scan a float */
+ /* Unset last char to stream */
+ SecUnGetChar(spec.ch, stream, &(spec.charCount));
+#if SECUREC_ENABLE_SCANF_FLOAT
+ if (SecInputFloat(stream, &spec, &floatSpec) != 0) {
+ ++errRet;
+ continue;
+ }
+ if (spec.suppress == 0) {
+ spec.argPtr = (void *)va_arg(argList, void *);
+ if (spec.argPtr == NULL) {
+ ++errRet;
+ paraIsNull = 1;
+ continue;
+ }
+#ifdef SECUREC_FOR_WCHAR
+ if (SecAssignFloatW(&floatSpec, &spec) != 0) {
+ ++errRet;
+ continue;
+ }
+#else
+ SecAssignFloat(floatSpec.floatStr, spec.numberWidth, spec.argPtr);
+#endif
+ ++doneCount;
+ }
+ break;
+#else /* SECUREC_ENABLE_SCANF_FLOAT */
+ ++errRet;
+ continue;
+#endif
+ default:
+ if ((int)(*format) != (int)spec.ch) {
+ SecUnGetChar(spec.ch, stream, &(spec.charCount));
+ formatError = 1;
+ ++errRet;
+ continue;
+ } else {
+ --match; /* Compensate for the self-increment of the following code */
+ }
+ break;
+ }
+ ++match;
+ ++format;
+ }
+
+#ifdef SECUREC_FOR_WCHAR
+ SecFreeBracketTable(&bracketTable);
+#endif
+
+#if SECUREC_ENABLE_SCANF_FLOAT
+ SecFreeFloatSpec(&floatSpec, &doneCount);
+#endif
+
+#if SECUREC_ENABLE_SCANF_FILE
+ SecAdjustStream(stream);
+#endif
+
+ if (spec.ch == SECUREC_EOF) {
+ return ((doneCount != 0 || match != 0) ? doneCount : SECUREC_SCANF_EINVAL);
+ }
+ if (formatError != 0 || paraIsNull != 0) {
+ /* Invalid Input Format or parameter, but not meet EOF */
+ return SECUREC_SCANF_ERROR_PARA;
+ }
+ return doneCount;
+}
+
+#if SECUREC_ENABLE_SCANF_FILE
+#if SECUREC_USE_STD_UNGETC
+/*
+ * Get char from stream use std function
+ */
+SECUREC_INLINE SecInt SecGetCharFromStream(const SecFileStream *stream)
+{
+ SecInt ch;
+ ch = SECUREC_GETC(stream->pf);
+ return ch;
+}
+#else
+/*
+ * Get char from stream or buffer
+ */
+SECUREC_INLINE SecInt SecGetCharFromStream(SecFileStream *stream)
+{
+ SecInt ch;
+ if (stream->fUnGet == 1) {
+ ch = (SecInt) stream->lastChar;
+ stream->fUnGet = 0;
+ } else {
+ ch = SECUREC_GETC(stream->pf);
+ stream->lastChar = (unsigned int)ch;
+ }
+ return ch;
+}
+#endif
+
+/*
+ * Try to read the BOM header, when meet a BOM head, discard it, then data is Aligned to base
+ */
+SECUREC_INLINE void SecReadAndSkipBomHeader(SecFileStream *stream)
+{
+ /* Use size_t type conversion to clean e747 */
+ stream->count = fread(stream->base, (size_t)1, (size_t)SECUREC_BOM_HEADER_SIZE, stream->pf);
+ if (stream->count > SECUREC_BOM_HEADER_SIZE) {
+ stream->count = 0;
+ }
+ if (SECUREC_BEGIN_WITH_BOM(stream->base, stream->count)) {
+ /* It's BOM header, discard it */
+ stream->count = 0;
+ }
+}
+
+/*
+ * Get char from file stream or buffer
+ */
+SECUREC_INLINE SecInt SecGetCharFromFile(SecFileStream *stream)
+{
+ SecInt ch;
+ if (stream->count < sizeof(SecChar)) {
+ /* Load file to buffer */
+ size_t len;
+ if (stream->base != NULL) {
+ /* Put the last unread data in the buffer head */
+ for (len = 0; len < stream->count; ++len) {
+ stream->base[len] = stream->cur[len];
+ }
+ } else {
+ stream->oriFilePos = ftell(stream->pf); /* Save original file read position */
+ if (stream->oriFilePos == -1) {
+ /* It may be a pipe stream */
+ stream->flag = SECUREC_PIPE_STREAM_FLAG;
+ return SecGetCharFromStream(stream);
+ }
+ /* Reserve the length of BOM head */
+ stream->base = (char *)SECUREC_MALLOC(SECUREC_BUFFERED_BLOK_SIZE +
+ SECUREC_BOM_HEADER_SIZE + sizeof(SecChar)); /* To store '\0' and aligned to wide char */
+ if (stream->base == NULL) {
+ return SECUREC_EOF;
+ }
+ /* First read file */
+ if (stream->oriFilePos == 0) {
+ /* Make sure the data is aligned to base */
+ SecReadAndSkipBomHeader(stream);
+ }
+ }
+
+ /* Skip existing data and read data */
+ len = fread(stream->base + stream->count, (size_t)1, (size_t)SECUREC_BUFFERED_BLOK_SIZE, stream->pf);
+ if (len > SECUREC_BUFFERED_BLOK_SIZE) { /* It won't happen, */
+ len = 0;
+ }
+ stream->count += len;
+ stream->cur = stream->base;
+ stream->flag |= SECUREC_LOAD_FILE_TO_MEM_FLAG;
+ stream->base[stream->count] = '\0'; /* For tool Warning string null */
+ }
+
+ SECUREC_GET_CHAR(stream, &ch);
+ if (ch != SECUREC_EOF) {
+ stream->fileRealRead += sizeof(SecChar);
+ }
+ return ch;
+}
+#endif
+
+/*
+ * Get char for wchar version
+ */
+SECUREC_INLINE SecInt SecGetChar(SecFileStream *stream, int *counter)
+{
+ *counter = *counter + 1; /* Always plus 1 */
+ /* The main scenario is scanf str */
+ if ((stream->flag & SECUREC_MEM_STR_FLAG) != 0) {
+ SecInt ch;
+ SECUREC_GET_CHAR(stream, &ch);
+ return ch;
+ }
+#if SECUREC_ENABLE_SCANF_FILE
+ if ((stream->flag & SECUREC_FILE_STREAM_FLAG) != 0) {
+ return SecGetCharFromFile(stream);
+ }
+ if ((stream->flag & SECUREC_PIPE_STREAM_FLAG) != 0) {
+ return SecGetCharFromStream(stream);
+ }
+#endif
+ return SECUREC_EOF;
+}
+
+/*
+ * Unget Public realizatio char for wchar and char version
+ */
+SECUREC_INLINE void SecUnGetCharImpl(SecInt ch, SecFileStream *stream)
+{
+ if ((stream->flag & SECUREC_MEM_STR_FLAG) != 0) {
+ SECUREC_UN_GET_CHAR(stream);
+ return;
+ }
+#if SECUREC_ENABLE_SCANF_FILE
+ if ((stream->flag & SECUREC_LOAD_FILE_TO_MEM_FLAG) != 0) {
+ SECUREC_UN_GET_CHAR(stream);
+ if (stream->fileRealRead > 0) {
+ stream->fileRealRead -= sizeof(SecChar);
+ }
+ return;
+ }
+ if ((stream->flag & SECUREC_PIPE_STREAM_FLAG) != 0) {
+#if SECUREC_USE_STD_UNGETC
+ (void)SECUREC_UN_GETC(ch, stream->pf);
+#else
+ stream->lastChar = (unsigned int)ch;
+ stream->fUnGet = 1;
+#endif
+ return;
+ }
+#else
+ (void)ch; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+#endif
+}
+
+/*
+ * Unget char for char version
+ */
+SECUREC_INLINE void SecUnGetChar(SecInt ch, SecFileStream *stream, int *counter)
+{
+ *counter = *counter - 1; /* Always mius 1 */
+ if (ch != SECUREC_EOF) {
+ SecUnGetCharImpl(ch, stream);
+ }
+}
+
+/*
+ * Skip space char by isspace
+ */
+SECUREC_INLINE SecInt SecSkipSpaceChar(SecFileStream *stream, int *counter)
+{
+ SecInt ch;
+ do {
+ ch = SecGetChar(stream, counter);
+ if (ch == SECUREC_EOF) {
+ break;
+ }
+ } while (SecIsSpace(ch) != 0);
+ return ch;
+}
+#endif /* INPUT_INL_5D13A042_DC3F_4ED9_A8D1_882811274C27 */
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/memcpy_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/memcpy_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..4062a322d25576d499877e81f9b728de2156506b
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/memcpy_s.c
@@ -0,0 +1,564 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: memcpy_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+/*
+ * [Standardize-exceptions] Use unsafe function: Portability
+ * [reason] Use unsafe function to implement security function to maintain platform compatibility.
+ * And sufficient input validation is performed before calling
+ */
+
+#include "securecutil.h"
+
+#ifndef SECUREC_MEMCOPY_WITH_PERFORMANCE
+#define SECUREC_MEMCOPY_WITH_PERFORMANCE 0
+#endif
+
+#if SECUREC_WITH_PERFORMANCE_ADDONS || SECUREC_MEMCOPY_WITH_PERFORMANCE
+#ifndef SECUREC_MEMCOPY_THRESHOLD_SIZE
+#define SECUREC_MEMCOPY_THRESHOLD_SIZE 64UL
+#endif
+
+#define SECUREC_SMALL_MEM_COPY(dest, src, count) do { \
+ if (SECUREC_ADDR_ALIGNED_8(dest) && SECUREC_ADDR_ALIGNED_8(src)) { \
+ /* Use struct assignment */ \
+ switch (count) { \
+ case 1: \
+ *(unsigned char *)(dest) = *(const unsigned char *)(src); \
+ break; \
+ case 2: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 2); \
+ break; \
+ case 3: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 3); \
+ break; \
+ case 4: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 4); \
+ break; \
+ case 5: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 5); \
+ break; \
+ case 6: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 6); \
+ break; \
+ case 7: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 7); \
+ break; \
+ case 8: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 8); \
+ break; \
+ case 9: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 9); \
+ break; \
+ case 10: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 10); \
+ break; \
+ case 11: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 11); \
+ break; \
+ case 12: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 12); \
+ break; \
+ case 13: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 13); \
+ break; \
+ case 14: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 14); \
+ break; \
+ case 15: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 15); \
+ break; \
+ case 16: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 16); \
+ break; \
+ case 17: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 17); \
+ break; \
+ case 18: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 18); \
+ break; \
+ case 19: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 19); \
+ break; \
+ case 20: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 20); \
+ break; \
+ case 21: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 21); \
+ break; \
+ case 22: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 22); \
+ break; \
+ case 23: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 23); \
+ break; \
+ case 24: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 24); \
+ break; \
+ case 25: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 25); \
+ break; \
+ case 26: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 26); \
+ break; \
+ case 27: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 27); \
+ break; \
+ case 28: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 28); \
+ break; \
+ case 29: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 29); \
+ break; \
+ case 30: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 30); \
+ break; \
+ case 31: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 31); \
+ break; \
+ case 32: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 32); \
+ break; \
+ case 33: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 33); \
+ break; \
+ case 34: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 34); \
+ break; \
+ case 35: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 35); \
+ break; \
+ case 36: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 36); \
+ break; \
+ case 37: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 37); \
+ break; \
+ case 38: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 38); \
+ break; \
+ case 39: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 39); \
+ break; \
+ case 40: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 40); \
+ break; \
+ case 41: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 41); \
+ break; \
+ case 42: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 42); \
+ break; \
+ case 43: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 43); \
+ break; \
+ case 44: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 44); \
+ break; \
+ case 45: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 45); \
+ break; \
+ case 46: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 46); \
+ break; \
+ case 47: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 47); \
+ break; \
+ case 48: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 48); \
+ break; \
+ case 49: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 49); \
+ break; \
+ case 50: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 50); \
+ break; \
+ case 51: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 51); \
+ break; \
+ case 52: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 52); \
+ break; \
+ case 53: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 53); \
+ break; \
+ case 54: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 54); \
+ break; \
+ case 55: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 55); \
+ break; \
+ case 56: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 56); \
+ break; \
+ case 57: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 57); \
+ break; \
+ case 58: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 58); \
+ break; \
+ case 59: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 59); \
+ break; \
+ case 60: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 60); \
+ break; \
+ case 61: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 61); \
+ break; \
+ case 62: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 62); \
+ break; \
+ case 63: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 63); \
+ break; \
+ case 64: \
+ SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 64); \
+ break; \
+ default: \
+ /* Do nothing */ \
+ break; \
+ } /* END switch */ \
+ } else { \
+ unsigned char *tmpDest_ = (unsigned char *)(dest); \
+ const unsigned char *tmpSrc_ = (const unsigned char *)(src); \
+ switch (count) { \
+ case 64: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 63: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 62: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 61: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 60: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 59: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 58: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 57: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 56: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 55: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 54: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 53: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 52: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 51: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 50: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 49: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 48: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 47: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 46: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 45: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 44: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 43: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 42: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 41: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 40: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 39: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 38: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 37: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 36: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 35: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 34: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 33: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 32: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 31: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 30: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 29: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 28: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 27: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 26: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 25: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 24: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 23: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 22: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 21: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 20: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 19: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 18: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 17: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 16: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 15: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 14: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 13: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 12: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 11: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 10: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 9: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 8: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 7: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 6: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 5: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 4: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 3: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 2: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 1: \
+ *(tmpDest_++) = *(tmpSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ default: \
+ /* Do nothing */ \
+ break; \
+ } \
+ } \
+} SECUREC_WHILE_ZERO
+
+/*
+ * Performance optimization
+ */
+#define SECUREC_MEMCPY_OPT(dest, src, count) do { \
+ if ((count) > SECUREC_MEMCOPY_THRESHOLD_SIZE) { \
+ SECUREC_MEMCPY_WARP_OPT((dest), (src), (count)); \
+ } else { \
+ SECUREC_SMALL_MEM_COPY((dest), (src), (count)); \
+ } \
+} SECUREC_WHILE_ZERO
+#endif
+
+/*
+ * Handling errors
+ */
+SECUREC_INLINE errno_t SecMemcpyError(void *dest, size_t destMax, const void *src, size_t count)
+{
+ if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("memcpy_s");
+ return ERANGE;
+ }
+ if (dest == NULL || src == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("memcpy_s");
+ if (dest != NULL) {
+ (void)memset(dest, 0, destMax);
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+ if (count > destMax) {
+ (void)memset(dest, 0, destMax);
+ SECUREC_ERROR_INVALID_RANGE("memcpy_s");
+ return ERANGE_AND_RESET;
+ }
+ if (SECUREC_MEMORY_IS_OVERLAP(dest, src, count)) {
+ (void)memset(dest, 0, destMax);
+ SECUREC_ERROR_BUFFER_OVERLAP("memcpy_s");
+ return EOVERLAP_AND_RESET;
+ }
+ /* Count is 0 or dest equal src also ret EOK */
+ return EOK;
+}
+
+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+ /*
+ * The fread API in windows will call memcpy_s and pass 0xffffffff to destMax.
+ * To avoid the failure of fread, we don't check desMax limit.
+ */
+#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) (SECUREC_LIKELY((count) <= (destMax) && \
+ (dest) != NULL && (src) != NULL && \
+ (count) > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count))))
+#else
+#define SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count) (SECUREC_LIKELY((count) <= (destMax) && \
+ (dest) != NULL && (src) != NULL && (destMax) <= SECUREC_MEM_MAX_LEN && \
+ (count) > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count))))
+#endif
+
+/*
+ *
+ * The memcpy_s function copies n characters from the object pointed to by src into the object pointed to by dest
+ *
+ *
+ * dest Destination buffer.
+ * destMax Size of the destination buffer.
+ * src Buffer to copy from.
+ * count Number of characters to copy
+ *
+ *
+ * dest buffer is updated.
+ *
+ *
+ * EOK Success
+ * EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
+ * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
+ * ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0
+ * ERANGE_AND_RESET count > destMax and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
+ * and dest != NULL and src != NULL
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
+ * count <= destMax destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL
+ * and src != NULL and dest != src
+ *
+ * if an error occured, dest will be filled with 0.
+ * If the source and destination overlap, the behavior of memcpy_s is undefined.
+ * Use memmove_s to handle overlapping regions.
+ */
+errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count)
+{
+ if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) {
+#if SECUREC_MEMCOPY_WITH_PERFORMANCE
+ SECUREC_MEMCPY_OPT(dest, src, count);
+#else
+ SECUREC_MEMCPY_WARP_OPT(dest, src, count);
+#endif
+ return EOK;
+ }
+ /* Meet some runtime violation, return error code */
+ return SecMemcpyError(dest, destMax, src, count);
+}
+
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(memcpy_s);
+#endif
+
+#if SECUREC_WITH_PERFORMANCE_ADDONS
+/*
+ * Performance optimization
+ */
+errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count)
+{
+ if (SECUREC_MEMCPY_PARAM_OK(dest, destMax, src, count)) {
+ SECUREC_MEMCPY_OPT(dest, src, count);
+ return EOK;
+ }
+ /* Meet some runtime violation, return error code */
+ return SecMemcpyError(dest, destMax, src, count);
+}
+
+/* Trim judgement on "destMax <= SECUREC_MEM_MAX_LEN" */
+errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count)
+{
+ if (SECUREC_LIKELY(count <= destMax && dest != NULL && src != NULL && \
+ count > 0 && SECUREC_MEMORY_NO_OVERLAP((dest), (src), (count)))) {
+ SECUREC_MEMCPY_OPT(dest, src, count);
+ return EOK;
+ }
+ /* Meet some runtime violation, return error code */
+ return SecMemcpyError(dest, destMax, src, count);
+}
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/memmove_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/memmove_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..417df8828956f1fc1219535cd52dd7a9f66d21a1
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/memmove_s.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: memmove_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+#ifdef SECUREC_NOT_CALL_LIBC_CORE_API
+/*
+ * Implementing memory data movement
+ */
+SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count)
+{
+ unsigned char *pDest = (unsigned char *)dst;
+ const unsigned char *pSrc = (const unsigned char *)src;
+ size_t maxCount = count;
+
+ if (dst <= src || pDest >= (pSrc + maxCount)) {
+ /*
+ * Non-Overlapping Buffers
+ * Copy from lower addresses to higher addresses
+ */
+ while (maxCount > 0) {
+ --maxCount;
+ *pDest = *pSrc;
+ ++pDest;
+ ++pSrc;
+ }
+ } else {
+ /*
+ * Overlapping Buffers
+ * Copy from higher addresses to lower addresses
+ */
+ pDest = pDest + maxCount - 1;
+ pSrc = pSrc + maxCount - 1;
+ while (maxCount > 0) {
+ --maxCount;
+ *pDest = *pSrc;
+ --pDest;
+ --pSrc;
+ }
+ }
+}
+#endif
+
+/*
+ *
+ * The memmove_s function copies count bytes of characters from src to dest.
+ * This function can be assigned correctly when memory overlaps.
+ *
+ * dest Destination object.
+ * destMax Size of the destination buffer.
+ * src Source object.
+ * count Number of characters to copy.
+ *
+ *
+ * dest buffer is uptdated.
+ *
+ *
+ * EOK Success
+ * EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
+ * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
+ * ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0
+ * ERANGE_AND_RESET count > destMax and dest != NULL and src != NULL and destMax != 0
+ * and destMax <= SECUREC_MEM_MAX_LEN
+ *
+ * If an error occured, dest will be filled with 0 when dest and destMax valid.
+ * If some regions of the source area and the destination overlap, memmove_s
+ * ensures that the original source bytes in the overlapping region are copied
+ * before being overwritten.
+ */
+errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count)
+{
+ if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("memmove_s");
+ return ERANGE;
+ }
+ if (dest == NULL || src == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("memmove_s");
+ if (dest != NULL) {
+ (void)memset(dest, 0, destMax);
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+ if (count > destMax) {
+ (void)memset(dest, 0, destMax);
+ SECUREC_ERROR_INVALID_RANGE("memmove_s");
+ return ERANGE_AND_RESET;
+ }
+ if (dest == src) {
+ return EOK;
+ }
+
+ if (count > 0) {
+#ifdef SECUREC_NOT_CALL_LIBC_CORE_API
+ SecUtilMemmove(dest, src, count);
+#else
+ /* Use underlying memmove for performance consideration */
+ (void)memmove(dest, src, count);
+#endif
+ }
+ return EOK;
+}
+
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(memmove_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/memset_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/memset_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..fc0cdbe6d59e94cee0d20b47052ac06455f08c17
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/memset_s.c
@@ -0,0 +1,509 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: memset_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+#define SECUREC_MEMSET_PARAM_OK(dest, destMax, count) (SECUREC_LIKELY((destMax) <= SECUREC_MEM_MAX_LEN && \
+ (dest) != NULL && (count) <= (destMax)))
+
+#if SECUREC_WITH_PERFORMANCE_ADDONS
+
+/* Use union to clear strict-aliasing warning */
+typedef union {
+ SecStrBuf32 buf32;
+ SecStrBuf31 buf31;
+ SecStrBuf30 buf30;
+ SecStrBuf29 buf29;
+ SecStrBuf28 buf28;
+ SecStrBuf27 buf27;
+ SecStrBuf26 buf26;
+ SecStrBuf25 buf25;
+ SecStrBuf24 buf24;
+ SecStrBuf23 buf23;
+ SecStrBuf22 buf22;
+ SecStrBuf21 buf21;
+ SecStrBuf20 buf20;
+ SecStrBuf19 buf19;
+ SecStrBuf18 buf18;
+ SecStrBuf17 buf17;
+ SecStrBuf16 buf16;
+ SecStrBuf15 buf15;
+ SecStrBuf14 buf14;
+ SecStrBuf13 buf13;
+ SecStrBuf12 buf12;
+ SecStrBuf11 buf11;
+ SecStrBuf10 buf10;
+ SecStrBuf9 buf9;
+ SecStrBuf8 buf8;
+ SecStrBuf7 buf7;
+ SecStrBuf6 buf6;
+ SecStrBuf5 buf5;
+ SecStrBuf4 buf4;
+ SecStrBuf3 buf3;
+ SecStrBuf2 buf2;
+} SecStrBuf32Union;
+/* C standard initializes the first member of the consortium. */
+static const SecStrBuf32 g_allZero = {{
+ '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+ '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+ '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+ '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
+}};
+static const SecStrBuf32 g_allFF = {{
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+}};
+
+/* Clear coversion warning strict aliasing" */
+SECUREC_INLINE const SecStrBuf32Union *SecStrictAliasingCast(const SecStrBuf32 *buf)
+{
+ return (const SecStrBuf32Union *)buf;
+}
+
+#ifndef SECUREC_MEMSET_THRESHOLD_SIZE
+#define SECUREC_MEMSET_THRESHOLD_SIZE 32UL
+#endif
+
+#define SECUREC_UNALIGNED_SET(dest, c, count) do { \
+ unsigned char *pDest_ = (unsigned char *)(dest); \
+ switch (count) { \
+ case 32: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 31: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 30: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 29: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 28: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 27: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 26: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 25: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 24: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 23: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 22: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 21: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 20: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 19: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 18: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 17: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 16: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 15: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 14: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 13: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 12: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 11: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 10: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 9: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 8: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 7: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 6: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 5: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 4: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 3: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 2: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 1: \
+ *(pDest_++) = (unsigned char)(c); \
+ /* fall-through */ /* FALLTHRU */ \
+ default: \
+ /* Do nothing */ \
+ break; \
+ } \
+} SECUREC_WHILE_ZERO
+
+#define SECUREC_SET_VALUE_BY_STRUCT(dest, dataName, n) do { \
+ *(SecStrBuf##n *)(dest) = *(const SecStrBuf##n *)(&((SecStrictAliasingCast(&(dataName)))->buf##n)); \
+} SECUREC_WHILE_ZERO
+
+#define SECUREC_ALIGNED_SET_OPT_ZERO_FF(dest, c, count) do { \
+ switch (c) { \
+ case 0: \
+ switch (count) { \
+ case 1: \
+ *(unsigned char *)(dest) = (unsigned char)0; \
+ break; \
+ case 2: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 2); \
+ break; \
+ case 3: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 3); \
+ break; \
+ case 4: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 4); \
+ break; \
+ case 5: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 5); \
+ break; \
+ case 6: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 6); \
+ break; \
+ case 7: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 7); \
+ break; \
+ case 8: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 8); \
+ break; \
+ case 9: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 9); \
+ break; \
+ case 10: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 10); \
+ break; \
+ case 11: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 11); \
+ break; \
+ case 12: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 12); \
+ break; \
+ case 13: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 13); \
+ break; \
+ case 14: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 14); \
+ break; \
+ case 15: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 15); \
+ break; \
+ case 16: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 16); \
+ break; \
+ case 17: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 17); \
+ break; \
+ case 18: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 18); \
+ break; \
+ case 19: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 19); \
+ break; \
+ case 20: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 20); \
+ break; \
+ case 21: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 21); \
+ break; \
+ case 22: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 22); \
+ break; \
+ case 23: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 23); \
+ break; \
+ case 24: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 24); \
+ break; \
+ case 25: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 25); \
+ break; \
+ case 26: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 26); \
+ break; \
+ case 27: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 27); \
+ break; \
+ case 28: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 28); \
+ break; \
+ case 29: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 29); \
+ break; \
+ case 30: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 30); \
+ break; \
+ case 31: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 31); \
+ break; \
+ case 32: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 32); \
+ break; \
+ default: \
+ /* Do nothing */ \
+ break; \
+ } \
+ break; \
+ case 0xFF: \
+ switch (count) { \
+ case 1: \
+ *(unsigned char *)(dest) = (unsigned char)0xffU; \
+ break; \
+ case 2: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 2); \
+ break; \
+ case 3: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 3); \
+ break; \
+ case 4: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 4); \
+ break; \
+ case 5: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 5); \
+ break; \
+ case 6: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 6); \
+ break; \
+ case 7: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 7); \
+ break; \
+ case 8: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 8); \
+ break; \
+ case 9: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 9); \
+ break; \
+ case 10: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 10); \
+ break; \
+ case 11: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 11); \
+ break; \
+ case 12: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 12); \
+ break; \
+ case 13: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 13); \
+ break; \
+ case 14: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 14); \
+ break; \
+ case 15: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 15); \
+ break; \
+ case 16: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 16); \
+ break; \
+ case 17: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 17); \
+ break; \
+ case 18: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 18); \
+ break; \
+ case 19: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 19); \
+ break; \
+ case 20: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 20); \
+ break; \
+ case 21: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 21); \
+ break; \
+ case 22: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 22); \
+ break; \
+ case 23: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 23); \
+ break; \
+ case 24: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 24); \
+ break; \
+ case 25: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 25); \
+ break; \
+ case 26: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 26); \
+ break; \
+ case 27: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 27); \
+ break; \
+ case 28: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 28); \
+ break; \
+ case 29: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 29); \
+ break; \
+ case 30: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 30); \
+ break; \
+ case 31: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 31); \
+ break; \
+ case 32: \
+ SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 32); \
+ break; \
+ default: \
+ /* Do nothing */ \
+ break; \
+ } \
+ break; \
+ default: \
+ SECUREC_UNALIGNED_SET((dest), (c), (count)); \
+ break; \
+ } /* END switch */ \
+} SECUREC_WHILE_ZERO
+
+#define SECUREC_SMALL_MEM_SET(dest, c, count) do { \
+ if (SECUREC_ADDR_ALIGNED_8((dest))) { \
+ SECUREC_ALIGNED_SET_OPT_ZERO_FF((dest), (c), (count)); \
+ } else { \
+ SECUREC_UNALIGNED_SET((dest), (c), (count)); \
+ } \
+} SECUREC_WHILE_ZERO
+
+/*
+ * Performance optimization
+ */
+#define SECUREC_MEMSET_OPT(dest, c, count) do { \
+ if ((count) > SECUREC_MEMSET_THRESHOLD_SIZE) { \
+ SECUREC_MEMSET_WARP_OPT((dest), (c), (count)); \
+ } else { \
+ SECUREC_SMALL_MEM_SET((dest), (c), (count)); \
+ } \
+} SECUREC_WHILE_ZERO
+#endif
+
+/*
+ * Handling errors
+ */
+SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c, size_t count)
+{
+ /* Check destMax is 0 compatible with _sp macro */
+ if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("memset_s");
+ return ERANGE;
+ }
+ if (dest == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("memset_s");
+ return EINVAL;
+ }
+ if (count > destMax) {
+ (void)memset(dest, c, destMax); /* Set entire buffer to value c */
+ SECUREC_ERROR_INVALID_RANGE("memset_s");
+ return ERANGE_AND_RESET;
+ }
+ return EOK;
+}
+
+/*
+ *
+ * The memset_s function copies the value of c (converted to an unsigned char)
+ * into each of the first count characters of the object pointed to by dest.
+ *
+ *
+ * dest Pointer to destination.
+ * destMax The size of the buffer.
+ * c Character to set.
+ * count Number of characters.
+ *
+ *
+ * dest buffer is uptdated.
+ *
+ *
+ * EOK Success
+ * EINVAL dest == NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
+ * ERANGE destMax > SECUREC_MEM_MAX_LEN or (destMax is 0 and count > destMax)
+ * ERANGE_AND_RESET count > destMax and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN and dest != NULL
+ *
+ * if return ERANGE_AND_RESET then fill dest to c ,fill length is destMax
+ */
+errno_t memset_s(void *dest, size_t destMax, int c, size_t count)
+{
+ if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) {
+ SECUREC_MEMSET_WARP_OPT(dest, c, count);
+ return EOK;
+ }
+ /* Meet some runtime violation, return error code */
+ return SecMemsetError(dest, destMax, c, count);
+}
+
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(memset_s);
+#endif
+
+#if SECUREC_WITH_PERFORMANCE_ADDONS
+/*
+ * Performance optimization
+ */
+errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count)
+{
+ if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) {
+ SECUREC_MEMSET_OPT(dest, c, count);
+ return EOK;
+ }
+ /* Meet some runtime violation, return error code */
+ return SecMemsetError(dest, destMax, c, count);
+}
+
+/*
+ * Performance optimization, trim judgement on "destMax <= SECUREC_MEM_MAX_LEN"
+ */
+errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count)
+{
+ if (SECUREC_LIKELY(count <= destMax && dest != NULL)) {
+ SECUREC_MEMSET_OPT(dest, c, count);
+ return EOK;
+ }
+ /* Meet some runtime violation, return error code */
+ return SecMemsetError(dest, destMax, c, count);
+}
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/output.inl b/3rd/gstor/dependency/Huawei_Secure_C/src/output.inl
new file mode 100644
index 0000000000000000000000000000000000000000..20dd4b3bd87771848a0cc2bc3606cf0dc92e32c6
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/output.inl
@@ -0,0 +1,1668 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: Used by secureprintoutput_a.c and secureprintoutput_w.c to include.
+ * This file provides a template function for ANSI and UNICODE compiling
+ * by different type definition. The functions of SecOutputS or
+ * SecOutputSW provides internal implementation for printf family API, such as sprintf, swprintf_s.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef OUTPUT_INL_2B263E9C_43D8_44BB_B17A_6D2033DECEE5
+#define OUTPUT_INL_2B263E9C_43D8_44BB_B17A_6D2033DECEE5
+
+#ifndef SECUREC_ENABLE_SPRINTF_LONG_DOUBLE
+/* Some compilers do not support long double */
+#define SECUREC_ENABLE_SPRINTF_LONG_DOUBLE 1
+#endif
+
+#define SECUREC_NULL_STRING_SIZE 8
+#define SECUREC_STATE_TABLE_SIZE 337
+
+#if defined(SECUREC_VXWORKS_VERSION_5_4) && !defined(SECUREC_ON_64BITS)
+#define SECUREC_DIV_QUOTIENT_OCTAL(val64) ((val64) >> 3ULL)
+#define SECUREC_DIV_RESIDUE_OCTAL(val64) ((val64) & 7ULL)
+
+#define SECUREC_DIV_QUOTIENT_HEX(val64) ((val64) >> 4ULL)
+#define SECUREC_DIV_RESIDUE_HEX(val64) ((val64) & 0xfULL)
+#endif
+
+#define SECUREC_RADIX_OCTAL 8U
+#define SECUREC_RADIX_DECIMAL 10U
+#define SECUREC_RADIX_HEX 16U
+#define SECUREC_PREFIX_LEN 2
+/* Size include '+' and '\0' */
+#define SECUREC_FLOAT_BUF_EXT 2
+
+/* Sign extend or Zero-extend */
+#define SECUREC_GET_LONG_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \
+ (SecInt64)(long)va_arg(argList, long) : \
+ (SecInt64)(unsigned long)va_arg(argList, long))
+
+/* Sign extend or Zero-extend */
+#define SECUREC_GET_CHAR_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \
+ SecUpdateNegativeChar(&(attr), ((char)va_arg(argList, int))) : \
+ (SecInt64)(unsigned char)va_arg(argList, int))
+
+/* Sign extend or Zero-extend */
+#define SECUREC_GET_SHORT_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \
+ (SecInt64)(short)va_arg(argList, int) : \
+ (SecInt64)(unsigned short)va_arg(argList, int))
+
+/* Sign extend or Zero-extend */
+#define SECUREC_GET_INT_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \
+ (SecInt64)(int)va_arg(argList, int) : \
+ (SecInt64)(unsigned int)va_arg(argList, int))
+
+#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
+/* Sign extend or Zero-extend. No suitable macros were found to handle the branch */
+#define SECUREC_GET_SIZE_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \
+ ((SecIsSameSize(sizeof(size_t), sizeof(long)) != 0) ? (SecInt64)(long)va_arg(argList, long) : \
+ ((SecIsSameSize(sizeof(size_t), sizeof(long long)) != 0) ? (SecInt64)(long long)va_arg(argList, long long) : \
+ (SecInt64)(int)va_arg(argList, int))) : \
+ (SecInt64)(size_t)va_arg(argList, size_t))
+#endif
+
+typedef union {
+ /* Integer formatting refers to the end of the buffer, plus 1 to prevent tool alarms */
+ char str[SECUREC_BUFFER_SIZE + 1];
+#if SECUREC_HAVE_WCHART
+ wchar_t wStr[SECUREC_WCHAR_BUFFER_SIZE]; /* Just for %lc */
+#endif
+} SecBuffer;
+
+typedef union {
+ char *str; /* Not a null terminated string */
+#if SECUREC_HAVE_WCHART
+ wchar_t *wStr;
+#endif
+} SecFormatBuf;
+
+typedef struct {
+ const char *digits; /* Point to the hexadecimal subset */
+ SecFormatBuf text; /* Point to formated string */
+ int textLen; /* Length of the text */
+ int textIsWide; /* Flag for text is wide chars ; 0 is not wide char */
+ unsigned int radix; /* Use for output number , default set to 10 */
+ unsigned int flags;
+ int fldWidth;
+ int precision;
+ int dynWidth; /* %* 1 width from variable parameter ;0 not */
+ int dynPrecision; /* %.* 1 precision from variable parameter ;0 not */
+ int padding; /* Padding len */
+ int prefixLen; /* Length of prefix, 0 or 1 or 2 */
+ SecChar prefix[SECUREC_PREFIX_LEN]; /* Prefix is 0 or 0x */
+ SecBuffer buffer;
+} SecFormatAttr;
+
+#if SECUREC_ENABLE_SPRINTF_FLOAT
+#ifdef SECUREC_STACK_SIZE_LESS_THAN_1K
+#define SECUREC_FMT_STR_LEN 8
+#else
+#define SECUREC_FMT_STR_LEN 16
+#endif
+typedef struct {
+ char buffer[SECUREC_FMT_STR_LEN];
+ char *fmtStr; /* Initialization must point to buffer */
+ char *allocatedFmtStr; /* Initialization must be NULL to store alloced point */
+ char *floatBuffer; /* Use heap memory if the SecFormatAttr.buffer is not enough */
+ int bufferSize; /* The size of floatBuffer */
+} SecFloatAdapt;
+#endif
+
+/* Use 20 to Align the data */
+#define SECUREC_DIGITS_BUF_SIZE 20
+/* Some systems can not use pointers to point to string literals, but can use string arrays. */
+/* For example, when handling code under uboot, there is a problem with the pointer */
+static const char g_itoaUpperDigits[SECUREC_DIGITS_BUF_SIZE] = "0123456789ABCDEFX";
+static const char g_itoaLowerDigits[SECUREC_DIGITS_BUF_SIZE] = "0123456789abcdefx";
+
+#if SECUREC_ENABLE_SPRINTF_FLOAT
+/* Call system sprintf to format float value */
+SECUREC_INLINE int SecFormatFloat(char *strDest, const char *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ SECUREC_MASK_MSVC_CRT_WARNING
+ ret = vsprintf(strDest, format, argList);
+ SECUREC_END_MASK_MSVC_CRT_WARNING
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+
+#if defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && SECUREC_ENABLE_SPRINTF_LONG_DOUBLE
+/* Out put long double value to dest */
+SECUREC_INLINE void SecFormatLongDouble(SecFormatAttr *attr, const SecFloatAdapt *floatAdapt, long double ldValue)
+{
+ int fldWidth = (((attr->flags & SECUREC_FLAG_LEFT) != 0) ? (-attr->fldWidth) : attr->fldWidth);
+ if (attr->dynWidth != 0 && attr->dynPrecision != 0) {
+ attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, fldWidth, attr->precision, ldValue);
+ } else if (attr->dynWidth != 0) {
+ attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, fldWidth, ldValue);
+ } else if (attr->dynPrecision != 0) {
+ attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, attr->precision, ldValue);
+ } else {
+ attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, ldValue);
+ }
+ if (attr->textLen < 0 || attr->textLen >= floatAdapt->bufferSize) {
+ attr->textLen = 0;
+ }
+}
+#endif
+
+/* Out put double value to dest */
+SECUREC_INLINE void SecFormatDouble(SecFormatAttr *attr, const SecFloatAdapt *floatAdapt, double dValue)
+{
+ int fldWidth = (((attr->flags & SECUREC_FLAG_LEFT) != 0) ? (-attr->fldWidth) : attr->fldWidth);
+ if (attr->dynWidth != 0 && attr->dynPrecision != 0) {
+ attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, fldWidth, attr->precision, dValue);
+ } else if (attr->dynWidth != 0) {
+ attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, fldWidth, dValue);
+ } else if (attr->dynPrecision != 0) {
+ attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, attr->precision, dValue);
+ } else {
+ attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, dValue);
+ }
+ if (attr->textLen < 0 || attr->textLen >= floatAdapt->bufferSize) {
+ attr->textLen = 0;
+ }
+}
+#endif
+
+#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
+/* To clear e506 warning */
+SECUREC_INLINE int SecIsSameSize(size_t sizeA, size_t sizeB)
+{
+ return (int)(sizeA == sizeB);
+}
+#endif
+
+#ifndef SECUREC_ON_64BITS
+/*
+ * Compiler Optimized Division 8.
+ * The text.str point to buffer end, must be Large enough
+ */
+SECUREC_INLINE void SecNumber32ToOctalString(SecUnsignedInt32 number, SecFormatAttr *attr)
+{
+ SecUnsignedInt32 val32 = number;
+ do {
+ --attr->text.str;
+ /* Just use lowerDigits for 0 - 9 */
+ *(attr->text.str) = g_itoaLowerDigits[val32 % SECUREC_RADIX_OCTAL];
+ val32 /= SECUREC_RADIX_OCTAL;
+ } while (val32 != 0);
+}
+
+#ifdef _AIX
+/*
+ * Compiler Optimized Division 10.
+ * The text.str point to buffer end, must be Large enough
+ */
+SECUREC_INLINE void SecNumber32ToDecString(SecUnsignedInt32 number, SecFormatAttr *attr)
+{
+ SecUnsignedInt32 val32 = number;
+ do {
+ --attr->text.str;
+ /* Just use lowerDigits for 0 - 9 */
+ *(attr->text.str) = g_itoaLowerDigits[val32 % SECUREC_RADIX_DECIMAL];
+ val32 /= SECUREC_RADIX_DECIMAL;
+ } while (val32 != 0);
+}
+#endif
+/*
+ * Compiler Optimized Division 16.
+ * The text.str point to buffer end, must be Large enough
+ */
+SECUREC_INLINE void SecNumber32ToHexString(SecUnsignedInt32 number, SecFormatAttr *attr)
+{
+ SecUnsignedInt32 val32 = number;
+ do {
+ --attr->text.str;
+ *(attr->text.str) = attr->digits[val32 % SECUREC_RADIX_HEX];
+ val32 /= SECUREC_RADIX_HEX;
+ } while (val32 != 0);
+}
+
+#ifndef _AIX
+/* Use fast div 10 */
+SECUREC_INLINE void SecNumber32ToDecStringFast(SecUnsignedInt32 number, SecFormatAttr *attr)
+{
+ SecUnsignedInt32 val32 = number;
+ do {
+ SecUnsignedInt32 quotient;
+ SecUnsignedInt32 remain;
+ --attr->text.str;
+ *(attr->text.str) = g_itoaLowerDigits[val32 % SECUREC_RADIX_DECIMAL];
+ quotient = (val32 >> 1U) + (val32 >> 2U); /* Fast div magic 2 */
+ quotient = quotient + (quotient >> 4U); /* Fast div magic 4 */
+ quotient = quotient + (quotient >> 8U); /* Fast div magic 8 */
+ quotient = quotient + (quotient >> 16U); /* Fast div magic 16 */
+ quotient = quotient >> 3U; /* Fast div magic 3 */
+ remain = val32 - SECUREC_MUL_TEN(quotient);
+ val32 = (remain > 9U) ? (quotient + 1U) : quotient; /* Fast div magic 9 */
+ } while (val32 != 0);
+}
+#endif
+
+SECUREC_INLINE void SecNumber32ToString(SecUnsignedInt32 number, SecFormatAttr *attr)
+{
+ switch (attr->radix) {
+ case SECUREC_RADIX_HEX:
+ SecNumber32ToHexString(number, attr);
+ break;
+ case SECUREC_RADIX_OCTAL:
+ SecNumber32ToOctalString(number, attr);
+ break;
+ case SECUREC_RADIX_DECIMAL:
+#ifdef _AIX
+ /* The compiler will optimize div 10 */
+ SecNumber32ToDecString(number, attr);
+#else
+ SecNumber32ToDecStringFast(number, attr);
+#endif
+ break;
+ default:
+ /* Do nothing */
+ break;
+ }
+}
+#endif
+
+#if defined(SECUREC_USE_SPECIAL_DIV64) || (defined(SECUREC_VXWORKS_VERSION_5_4) && !defined(SECUREC_ON_64BITS))
+/*
+ * This function just to clear warning, on sume vxworks compiler shift 32 bit make warnigs
+ */
+SECUREC_INLINE SecUnsignedInt64 SecU64Shr32(SecUnsignedInt64 number)
+{
+ return (((number) >> 16U) >> 16U); /* Two shifts of 16 bits to realize shifts of 32 bits */
+}
+/*
+ * Fast divide by 10 algorithm.
+ * Calculation divisor multiply 0xcccccccccccccccdULL, resultHi64 >> 3 as quotient
+ */
+SECUREC_INLINE void SecU64Div10(SecUnsignedInt64 divisor, SecUnsignedInt64 *quotient, SecUnsignedInt32 *residue)
+{
+ SecUnsignedInt64 mask = 0xffffffffULL; /* Use 0xffffffffULL as 32 bit mask */
+ SecUnsignedInt64 magicHi = 0xccccccccULL; /* Fast divide 10 magic numbers high 32bit 0xccccccccULL */
+ SecUnsignedInt64 magicLow = 0xcccccccdULL; /* Fast divide 10 magic numbers low 32bit 0xcccccccdULL */
+ SecUnsignedInt64 divisorHi = (SecUnsignedInt64)(SecU64Shr32(divisor)); /* High 32 bit use */
+ SecUnsignedInt64 divisorLow = (SecUnsignedInt64)(divisor & mask); /* Low 32 bit mask */
+ SecUnsignedInt64 factorHi = divisorHi * magicHi;
+ SecUnsignedInt64 factorLow1 = divisorHi * magicLow;
+ SecUnsignedInt64 factorLow2 = divisorLow * magicHi;
+ SecUnsignedInt64 factorLow3 = divisorLow * magicLow;
+ SecUnsignedInt64 carry = (factorLow1 & mask) + (factorLow2 & mask) + SecU64Shr32(factorLow3);
+ SecUnsignedInt64 resultHi64 = factorHi + SecU64Shr32(factorLow1) + SecU64Shr32(factorLow2) + SecU64Shr32(carry);
+
+ *quotient = resultHi64 >> 3U; /* Fast divide 10 magic numbers 3 */
+ *residue = (SecUnsignedInt32)(divisor - ((*quotient) * 10)); /* Quotient mul 10 */
+ return;
+}
+#if defined(SECUREC_VXWORKS_VERSION_5_4) && !defined(SECUREC_ON_64BITS)
+/*
+ * Divide function for VXWORKS
+ */
+SECUREC_INLINE int SecU64Div32(SecUnsignedInt64 divisor, SecUnsignedInt32 radix,
+ SecUnsignedInt64 *quotient, SecUnsignedInt32 *residue)
+{
+ switch (radix) {
+ case SECUREC_RADIX_DECIMAL:
+ SecU64Div10(divisor, quotient, residue);
+ break;
+ case SECUREC_RADIX_HEX:
+ *quotient = SECUREC_DIV_QUOTIENT_HEX(divisor);
+ *residue = (SecUnsignedInt32)SECUREC_DIV_RESIDUE_HEX(divisor);
+ break;
+ case SECUREC_RADIX_OCTAL:
+ *quotient = SECUREC_DIV_QUOTIENT_OCTAL(divisor);
+ *residue = (SecUnsignedInt32)SECUREC_DIV_RESIDUE_OCTAL(divisor);
+ break;
+ default:
+ return -1; /* This does not happen in the current file */
+ }
+ return 0;
+}
+SECUREC_INLINE void SecNumber64ToStringSpecial(SecUnsignedInt64 number, SecFormatAttr *attr)
+{
+ SecUnsignedInt64 val64 = number;
+ do {
+ SecUnsignedInt32 digit = 0; /* Ascii value of digit */
+ SecUnsignedInt64 quotient = 0;
+ if (SecU64Div32(val64, (SecUnsignedInt32)attr->radix, "ient, &digit) != 0) {
+ /* Just break, when enter this function, no error is returned */
+ break;
+ }
+ --attr->text.str;
+ *(attr->text.str) = attr->digits[digit];
+ val64 = quotient;
+ } while (val64 != 0);
+}
+#endif
+#endif
+
+#if defined(SECUREC_ON_64BITS) || !defined(SECUREC_VXWORKS_VERSION_5_4)
+#if defined(SECUREC_USE_SPECIAL_DIV64)
+/* The compiler does not provide 64 bit division problems */
+SECUREC_INLINE void SecNumber64ToDecString(SecUnsignedInt64 number, SecFormatAttr *attr)
+{
+ SecUnsignedInt64 val64 = number;
+ do {
+ SecUnsignedInt64 quotient = 0;
+ SecUnsignedInt32 digit = 0;
+ SecU64Div10(val64, "ient, &digit);
+ --attr->text.str;
+ /* Just use lowerDigits for 0 - 9 */
+ *(attr->text.str) = g_itoaLowerDigits[digit];
+ val64 = quotient;
+ } while (val64 != 0);
+}
+#else
+/*
+ * Compiler Optimized Division 10.
+ * The text.str point to buffer end, must be Large enough
+ */
+SECUREC_INLINE void SecNumber64ToDecString(SecUnsignedInt64 number, SecFormatAttr *attr)
+{
+ SecUnsignedInt64 val64 = number;
+ do {
+ --attr->text.str;
+ /* Just use lowerDigits for 0 - 9 */
+ *(attr->text.str) = g_itoaLowerDigits[val64 % SECUREC_RADIX_DECIMAL];
+ val64 /= SECUREC_RADIX_DECIMAL;
+ } while (val64 != 0);
+}
+#endif
+
+/*
+ * Compiler Optimized Division 8.
+ * The text.str point to buffer end, must be Large enough
+ */
+SECUREC_INLINE void SecNumber64ToOctalString(SecUnsignedInt64 number, SecFormatAttr *attr)
+{
+ SecUnsignedInt64 val64 = number;
+ do {
+ --attr->text.str;
+ /* Just use lowerDigits for 0 - 9 */
+ *(attr->text.str) = g_itoaLowerDigits[val64 % SECUREC_RADIX_OCTAL];
+ val64 /= SECUREC_RADIX_OCTAL;
+ } while (val64 != 0);
+}
+/*
+ * Compiler Optimized Division 16.
+ * The text.str point to buffer end, must be Large enough
+ */
+SECUREC_INLINE void SecNumber64ToHexString(SecUnsignedInt64 number, SecFormatAttr *attr)
+{
+ SecUnsignedInt64 val64 = number;
+ do {
+ --attr->text.str;
+ *(attr->text.str) = attr->digits[val64 % SECUREC_RADIX_HEX];
+ val64 /= SECUREC_RADIX_HEX;
+ } while (val64 != 0);
+}
+
+SECUREC_INLINE void SecNumber64ToString(SecUnsignedInt64 number, SecFormatAttr *attr)
+{
+ switch (attr->radix) {
+ /* The compiler will optimize div 10 */
+ case SECUREC_RADIX_DECIMAL:
+ SecNumber64ToDecString(number, attr);
+ break;
+ case SECUREC_RADIX_OCTAL:
+ SecNumber64ToOctalString(number, attr);
+ break;
+ case SECUREC_RADIX_HEX:
+ SecNumber64ToHexString(number, attr);
+ break;
+ default:
+ /* Do nothing */
+ break;
+ }
+}
+#endif
+
+/*
+ * Converting integers to string
+ */
+SECUREC_INLINE void SecNumberToString(SecUnsignedInt64 number, SecFormatAttr *attr)
+{
+#ifdef SECUREC_ON_64BITS
+ SecNumber64ToString(number, attr);
+#else /* For 32 bits system */
+ if (number <= 0xffffffffUL) { /* Use 0xffffffffUL to check if the value is in the 32-bit range */
+ /* In most case, the value to be converted is small value */
+ SecUnsignedInt32 n32Tmp = (SecUnsignedInt32)number;
+ SecNumber32ToString(n32Tmp, attr);
+ } else {
+ /* The value to be converted is greater than 4G */
+#if defined(SECUREC_VXWORKS_VERSION_5_4)
+ SecNumber64ToStringSpecial(number, attr);
+#else
+ SecNumber64ToString(number, attr);
+#endif
+ }
+#endif
+}
+
+SECUREC_INLINE int SecIsNumberNeedTo32Bit(const SecFormatAttr *attr)
+{
+ return (int)(((attr->flags & SECUREC_FLAG_I64) == 0) &&
+#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
+ ((attr->flags & SECUREC_FLAG_INTMAX) == 0) &&
+#endif
+#ifdef SECUREC_ON_64BITS
+ ((attr->flags & SECUREC_FLAG_PTRDIFF) == 0) &&
+ ((attr->flags & SECUREC_FLAG_SIZE) == 0) &&
+#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) /* on window 64 system sizeof long is 32bit */
+ ((attr->flags & SECUREC_FLAG_LONG) == 0) &&
+#endif
+#endif
+ ((attr->flags & SECUREC_FLAG_LONGLONG) == 0));
+}
+
+SECUREC_INLINE void SecNumberToBuffer(SecFormatAttr *attr, SecInt64 num64)
+{
+ SecUnsignedInt64 number;
+ /* Check for negative; copy into number */
+ if ((attr->flags & SECUREC_FLAG_SIGNED) != 0 && num64 < 0) {
+ number = (SecUnsignedInt64)(0 - (SecUnsignedInt64)num64); /* Wrap with unsigned int64 numbers */
+ attr->flags |= SECUREC_FLAG_NEGATIVE;
+ } else {
+ number = (SecUnsignedInt64)num64;
+ }
+ if (SecIsNumberNeedTo32Bit(attr) != 0) {
+ number = (number & (SecUnsignedInt64)0xffffffffUL); /* Use 0xffffffff as 32 bit mask */
+ }
+
+ /* The text.str must be point to buffer.str, this pointer is used outside the function */
+ attr->text.str = &attr->buffer.str[SECUREC_BUFFER_SIZE];
+
+ if (number == 0) {
+ /* Turn off hex prefix default, and textLen is zero */
+ attr->prefixLen = 0;
+ attr->textLen = 0;
+ return;
+ }
+
+ /* Convert integer to string. It must be invoked when number > 0, otherwise the following logic is incorrect */
+ SecNumberToString(number, attr);
+ /* Compute length of number, text.str must be in buffer.str */
+ attr->textLen = (int)(size_t)((char *)&attr->buffer.str[SECUREC_BUFFER_SIZE] - attr->text.str);
+}
+
+/* Use loop copy char or wchar_t string */
+SECUREC_INLINE void SecWriteStringToStreamOpt(SecPrintfStream *stream, const SecChar *str, int len)
+{
+ int i;
+ const SecChar *tmp = str;
+ for (i = 0; i < len; ++i) {
+ *((SecChar *)(void *)(stream->cur)) = *(const SecChar *)(tmp);
+ stream->cur += sizeof(SecChar);
+ tmp = tmp + 1;
+ }
+ stream->count -= len * (int)(sizeof(SecChar));
+}
+
+SECUREC_INLINE void SecWriteStringToStream(SecPrintfStream *stream, const SecChar *str, int len)
+{
+ if (len < 12) { /* Performance optimization for mobile number length 12 */
+ SecWriteStringToStreamOpt(stream, str, len);
+ } else {
+ size_t count = (size_t)(unsigned int)len * (sizeof(SecChar));
+ SECUREC_MEMCPY_WARP_OPT(stream->cur, str, count);
+ stream->cur += (size_t)((size_t)(unsigned int)len * (sizeof(SecChar)));
+ stream->count -= len * (int)(sizeof(SecChar));
+ }
+}
+
+/*
+ * Return if buffer length is enough
+ * The count variable can be reduced to 0, and the external function complements the \0 terminator.
+ */
+SECUREC_INLINE int SecIsStreamBufEnough(const SecPrintfStream *stream, int needLen)
+{
+ return ((int)(stream->count - (needLen * (int)(sizeof(SecChar)))) >= 0);
+}
+
+#ifdef SECUREC_FOR_WCHAR
+SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten);
+SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten);
+#define SECUREC_WRITE_MULTI_CHAR SecWriteMultiCharW
+#define SECUREC_WRITE_STRING SecWriteStringW
+#else
+SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten);
+SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten);
+#define SECUREC_WRITE_MULTI_CHAR SecWriteMultiChar
+#define SECUREC_WRITE_STRING SecWriteString
+#endif
+
+/* Write left padding */
+SECUREC_INLINE void SecWriteLeftPadding(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut)
+{
+ if ((attr->flags & (SECUREC_FLAG_LEFT | SECUREC_FLAG_LEADZERO)) == 0 && attr->padding > 0) {
+ /* Pad on left with blanks */
+ SECUREC_WRITE_MULTI_CHAR(SECUREC_CHAR(' '), attr->padding, stream, charsOut);
+ }
+}
+
+/* Write prefix */
+SECUREC_INLINE void SecWritePrefix(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut)
+{
+ if (attr->prefixLen > 0) {
+ if (SecIsStreamBufEnough(stream, attr->prefixLen) != 0) {
+ /* Max prefix len is 2, use loop copy */
+ SecWriteStringToStreamOpt(stream, attr->prefix, attr->prefixLen);
+ *charsOut += attr->prefixLen;
+ } else {
+ SECUREC_WRITE_STRING(attr->prefix, attr->prefixLen, stream, charsOut);
+ }
+ }
+}
+
+/* Write leading zeros */
+SECUREC_INLINE void SecWriteLeadingZero(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut)
+{
+ if ((attr->flags & SECUREC_FLAG_LEADZERO) != 0 && (attr->flags & SECUREC_FLAG_LEFT) == 0 &&
+ attr->padding > 0) {
+ SECUREC_WRITE_MULTI_CHAR(SECUREC_CHAR('0'), attr->padding, stream, charsOut);
+ }
+}
+
+/* Write right padding */
+SECUREC_INLINE void SecWriteRightPadding(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut)
+{
+ if (*charsOut >= 0 && (attr->flags & SECUREC_FLAG_LEFT) != 0 && attr->padding > 0) {
+ /* Pad on right with blanks */
+ SECUREC_WRITE_MULTI_CHAR(SECUREC_CHAR(' '), attr->padding, stream, charsOut);
+ }
+}
+
+/* Write text string */
+SECUREC_INLINE void SecWriteStringChk(SecPrintfStream *stream, const SecChar *str, int len, int *charsOut)
+{
+ if (SecIsStreamBufEnough(stream, len) != 0) {
+ SecWriteStringToStream(stream, str, len);
+ *charsOut += len;
+ } else {
+ SECUREC_WRITE_STRING(str, len, stream, charsOut);
+ }
+}
+
+#ifdef SECUREC_FOR_WCHAR
+#if SECUREC_HAVE_MBTOWC
+SECUREC_INLINE void SecWriteTextAfterMbtowc(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut)
+{
+ const char *p = attr->text.str;
+ int count = attr->textLen;
+ while (count > 0) {
+ wchar_t wChar = L'\0';
+ int retVal = mbtowc(&wChar, p, (size_t)MB_CUR_MAX);
+ if (retVal <= 0) {
+ *charsOut = -1;
+ break;
+ }
+ SecWriteCharW(wChar, stream, charsOut);
+ if (*charsOut == -1) {
+ break;
+ }
+ p += retVal;
+ count -= retVal;
+ }
+}
+#endif
+#else /* Not SECUREC_FOR_WCHAR */
+#if SECUREC_HAVE_WCTOMB
+SECUREC_INLINE void SecWriteTextAfterWctomb(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut)
+{
+ const wchar_t *p = attr->text.wStr;
+ int count = attr->textLen;
+ while (count > 0) {
+ char tmpBuf[SECUREC_MB_LEN + 1];
+ SECUREC_MASK_MSVC_CRT_WARNING
+ int retVal = wctomb(tmpBuf, *p);
+ SECUREC_END_MASK_MSVC_CRT_WARNING
+ if (retVal <= 0) {
+ *charsOut = -1;
+ break;
+ }
+ SecWriteString(tmpBuf, retVal, stream, charsOut);
+ if (*charsOut == -1) {
+ break;
+ }
+ --count;
+ ++p;
+ }
+}
+#endif
+#endif
+
+#if SECUREC_ENABLE_SPRINTF_FLOAT
+/*
+ * Write text of float
+ * Using independent functions to optimize the expansion of inline functions by the compiler
+ */
+SECUREC_INLINE void SecWriteFloatText(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut)
+{
+#ifdef SECUREC_FOR_WCHAR
+#if SECUREC_HAVE_MBTOWC
+ SecWriteTextAfterMbtowc(stream, attr, charsOut);
+#else
+ *charsOut = -1;
+ (void)stream; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+ (void)attr; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+#endif
+#else /* Not SECUREC_FOR_WCHAR */
+ SecWriteString(attr->text.str, attr->textLen, stream, charsOut);
+#endif
+}
+#endif
+
+/* Write text of integer or string ... */
+SECUREC_INLINE void SecWriteText(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut)
+{
+#ifdef SECUREC_FOR_WCHAR
+ if (attr->textIsWide != 0) {
+ SecWriteStringChk(stream, attr->text.wStr, attr->textLen, charsOut);
+ } else {
+#if SECUREC_HAVE_MBTOWC
+ SecWriteTextAfterMbtowc(stream, attr, charsOut);
+#else
+ *charsOut = -1;
+#endif
+ }
+
+#else /* Not SECUREC_FOR_WCHAR */
+ if (attr->textIsWide != 0) {
+#if SECUREC_HAVE_WCTOMB
+ SecWriteTextAfterWctomb(stream, attr, charsOut);
+#else
+ *charsOut = -1;
+#endif
+ } else {
+ SecWriteStringChk(stream, attr->text.str, attr->textLen, charsOut);
+ }
+#endif
+}
+
+#define SECUREC_FMT_STATE_OFFSET 256
+
+SECUREC_INLINE SecFmtState SecDecodeState(SecChar ch, SecFmtState lastState)
+{
+ static const unsigned char stateTable[SECUREC_STATE_TABLE_SIZE] = {
+ /*
+ * Type
+ * 0: nospecial meanin;
+ * 1: '%'
+ * 2: '.'
+ * 3: '*'
+ * 4: '0'
+ * 5: '1' ... '9'
+ * 6: ' ', '+', '-', '#'
+ * 7: 'h', 'l', 'L', 'w' , 'N', 'z', 'q', 't', 'j'
+ * 8: 'd', 'o', 'u', 'i', 'x', 'X', 'e', 'f', 'g', 'E', 'F', 'G', 's', 'c', '[', 'p'
+ */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x06, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x00, 0x06, 0x02, 0x00,
+ 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00,
+ 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x08, 0x07, 0x00, 0x07, 0x00, 0x00, 0x08,
+ 0x08, 0x07, 0x00, 0x08, 0x07, 0x08, 0x00, 0x07, 0x08, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* Fill zero for normal char 128 byte for 0x80 - 0xff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /*
+ * State
+ * 0: normal
+ * 1: percent
+ * 2: flag
+ * 3: width
+ * 4: dot
+ * 5: precis
+ * 6: size
+ * 7: type
+ * 8: invalid
+ */
+ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x01, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08,
+ 0x01, 0x00, 0x00, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x03, 0x03, 0x08, 0x05,
+ 0x08, 0x08, 0x00, 0x00, 0x00, 0x02, 0x02, 0x03, 0x05, 0x05, 0x08, 0x00, 0x00, 0x00, 0x03, 0x03,
+ 0x03, 0x05, 0x05, 0x08, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00,
+ 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
+ 0x00
+ };
+
+#ifdef SECUREC_FOR_WCHAR
+ /* Convert to unsigned char to clear gcc 4.3.4 warning */
+ unsigned char fmtType = (unsigned char)((((unsigned int)(int)(ch)) <= (unsigned int)(int)(L'~')) ? \
+ (stateTable[(unsigned char)(ch)]) : 0);
+ return (SecFmtState)(stateTable[fmtType * ((unsigned char)STAT_INVALID + 1) +
+ (unsigned char)(lastState) + SECUREC_FMT_STATE_OFFSET]);
+#else
+ unsigned char fmtType = stateTable[(unsigned char)(ch)];
+ return (SecFmtState)(stateTable[fmtType * ((unsigned char)STAT_INVALID + 1) +
+ (unsigned char)(lastState) + SECUREC_FMT_STATE_OFFSET]);
+#endif
+}
+
+SECUREC_INLINE void SecDecodeFlags(SecChar ch, SecFormatAttr *attr)
+{
+ switch (ch) {
+ case SECUREC_CHAR(' '):
+ attr->flags |= SECUREC_FLAG_SIGN_SPACE;
+ break;
+ case SECUREC_CHAR('+'):
+ attr->flags |= SECUREC_FLAG_SIGN;
+ break;
+ case SECUREC_CHAR('-'):
+ attr->flags |= SECUREC_FLAG_LEFT;
+ break;
+ case SECUREC_CHAR('0'):
+ attr->flags |= SECUREC_FLAG_LEADZERO; /* Add zero th the front */
+ break;
+ case SECUREC_CHAR('#'):
+ attr->flags |= SECUREC_FLAG_ALTERNATE; /* Output %x with 0x */
+ break;
+ default:
+ /* Do nothing */
+ break;
+ }
+ return;
+}
+
+/*
+ * Decoded size identifier in format string to Reduce the number of lines of function code
+ */
+SECUREC_INLINE int SecDecodeSizeI(SecFormatAttr *attr, const SecChar **format)
+{
+#ifdef SECUREC_ON_64BITS
+ attr->flags |= SECUREC_FLAG_I64; /* %I to INT64 */
+#endif
+ if ((**format == SECUREC_CHAR('6')) && (*((*format) + 1) == SECUREC_CHAR('4'))) {
+ (*format) += 2; /* Add 2 to skip I64 */
+ attr->flags |= SECUREC_FLAG_I64; /* %I64 to INT64 */
+ } else if ((**format == SECUREC_CHAR('3')) && (*((*format) + 1) == SECUREC_CHAR('2'))) {
+ (*format) += 2; /* Add 2 to skip I32 */
+ attr->flags &= ~SECUREC_FLAG_I64; /* %I64 to INT32 */
+ } else if ((**format == SECUREC_CHAR('d')) || (**format == SECUREC_CHAR('i')) ||
+ (**format == SECUREC_CHAR('o')) || (**format == SECUREC_CHAR('u')) ||
+ (**format == SECUREC_CHAR('x')) || (**format == SECUREC_CHAR('X'))) {
+ /* Do nothing */
+ } else {
+ /* Compatibility code for "%I" just print I */
+ return -1;
+ }
+ return 0;
+}
+/*
+ * Decoded size identifier in format string, and skip format to next charater
+ */
+SECUREC_INLINE int SecDecodeSize(SecChar ch, SecFormatAttr *attr, const SecChar **format)
+{
+ switch (ch) {
+ case SECUREC_CHAR('l'):
+ if (**format == SECUREC_CHAR('l')) {
+ *format = *format + 1;
+ attr->flags |= SECUREC_FLAG_LONGLONG; /* For long long */
+ } else {
+ attr->flags |= SECUREC_FLAG_LONG; /* For long int or wchar_t */
+ }
+ break;
+#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
+ case SECUREC_CHAR('z'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('Z'):
+ attr->flags |= SECUREC_FLAG_SIZE;
+ break;
+ case SECUREC_CHAR('j'):
+ attr->flags |= SECUREC_FLAG_INTMAX;
+ break;
+#endif
+ case SECUREC_CHAR('t'):
+ attr->flags |= SECUREC_FLAG_PTRDIFF;
+ break;
+ case SECUREC_CHAR('q'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('L'):
+ attr->flags |= (SECUREC_FLAG_LONGLONG | SECUREC_FLAG_LONG_DOUBLE);
+ break;
+ case SECUREC_CHAR('I'):
+ if (SecDecodeSizeI(attr, format) != 0) {
+ /* Compatibility code for "%I" just print I */
+ return -1;
+ }
+ break;
+ case SECUREC_CHAR('h'):
+ if (**format == SECUREC_CHAR('h')) {
+ *format = *format + 1;
+ attr->flags |= SECUREC_FLAG_CHAR; /* For char */
+ } else {
+ attr->flags |= SECUREC_FLAG_SHORT; /* For short int */
+ }
+ break;
+ case SECUREC_CHAR('w'):
+ attr->flags |= SECUREC_FLAG_WIDECHAR; /* For wide char */
+ break;
+ default:
+ /* Do nothing */
+ break;
+ }
+ return 0;
+}
+
+/*
+ * Decoded char type identifier
+ */
+SECUREC_INLINE void SecDecodeTypeC(SecFormatAttr *attr, unsigned int c)
+{
+ attr->textLen = 1; /* Only 1 wide character */
+
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT)) && !(defined(__hpux)) && !(defined(SECUREC_ON_SOLARIS))
+ attr->flags &= ~SECUREC_FLAG_LEADZERO;
+#endif
+
+#ifdef SECUREC_FOR_WCHAR
+ if ((attr->flags & SECUREC_FLAG_SHORT) != 0) {
+ /* Get multibyte character from argument */
+ attr->buffer.str[0] = (char)c;
+ attr->text.str = attr->buffer.str;
+ attr->textIsWide = 0;
+ } else {
+ attr->buffer.wStr[0] = (wchar_t)c;
+ attr->text.wStr = attr->buffer.wStr;
+ attr->textIsWide = 1;
+ }
+#else /* Not SECUREC_FOR_WCHAR */
+ if ((attr->flags & (SECUREC_FLAG_LONG | SECUREC_FLAG_WIDECHAR)) != 0) {
+#if SECUREC_HAVE_WCHART
+ attr->buffer.wStr[0] = (wchar_t)c;
+ attr->text.wStr = attr->buffer.wStr;
+ attr->textIsWide = 1;
+#else
+ attr->textLen = 0; /* Ignore unsupported characters */
+ attr->fldWidth = 0; /* No paddings */
+#endif
+ } else {
+ /* Get multibyte character from argument */
+ attr->buffer.str[0] = (char)c;
+ attr->text.str = attr->buffer.str;
+ attr->textIsWide = 0;
+ }
+#endif
+}
+
+SECUREC_INLINE void SecDecodeTypeSchar(SecFormatAttr *attr)
+{
+ if (attr->text.str == NULL) {
+ /*
+ * Literal string to print null ptr, define it as array rather than const text area
+ * To avoid gcc warning with pointing const text with variable
+ */
+ static char strNullString[SECUREC_NULL_STRING_SIZE] = "(null)";
+ attr->text.str = strNullString;
+ }
+ if (attr->precision == -1) {
+ /* Precision NOT assigned */
+ /* The strlen performance is high when the string length is greater than 32 */
+ attr->textLen = (int)strlen(attr->text.str);
+ } else {
+ /* Precision assigned */
+ size_t textLen;
+ SECUREC_CALC_STR_LEN(attr->text.str, (size_t)(unsigned int)attr->precision, &textLen);
+ attr->textLen = (int)textLen;
+ }
+}
+
+SECUREC_INLINE void SecDecodeTypeSwchar(SecFormatAttr *attr)
+{
+#if SECUREC_HAVE_WCHART
+ size_t textLen;
+ attr->textIsWide = 1;
+ if (attr->text.wStr == NULL) {
+ /*
+ * Literal string to print null ptr, define it as array rather than const text area
+ * To avoid gcc warning with pointing const text with variable
+ */
+ static wchar_t wStrNullString[SECUREC_NULL_STRING_SIZE] = { L'(', L'n', L'u', L'l', L'l', L')', L'\0', L'\0' };
+ attr->text.wStr = wStrNullString;
+ }
+ /* The textLen in wchar_t,when precision is -1, it is unlimited */
+ SECUREC_CALC_WSTR_LEN(attr->text.wStr, (size_t)(unsigned int)attr->precision, &textLen);
+ attr->textLen = (int)textLen;
+#else
+ attr->textLen = 0;
+#endif
+}
+
+/*
+ * Decoded string identifier
+ */
+SECUREC_INLINE void SecDecodeTypeS(SecFormatAttr *attr, char *argPtr)
+{
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT)) && (!defined(SECUREC_ON_UNIX))
+ attr->flags &= ~SECUREC_FLAG_LEADZERO;
+#endif
+ attr->text.str = argPtr;
+#ifdef SECUREC_FOR_WCHAR
+#if defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
+ if ((attr->flags & SECUREC_FLAG_LONG) == 0) {
+ attr->flags |= SECUREC_FLAG_SHORT;
+ }
+#endif
+ if ((attr->flags & SECUREC_FLAG_SHORT) != 0) {
+ /* The textLen now contains length in multibyte chars */
+ SecDecodeTypeSchar(attr);
+ } else {
+ /* The textLen now contains length in wide chars */
+ SecDecodeTypeSwchar(attr);
+ }
+#else /* SECUREC_FOR_WCHAR */
+ if ((attr->flags & (SECUREC_FLAG_LONG | SECUREC_FLAG_WIDECHAR)) != 0) {
+ /* The textLen now contains length in wide chars */
+ SecDecodeTypeSwchar(attr);
+ } else {
+ /* The textLen now contains length in multibyte chars */
+ SecDecodeTypeSchar(attr);
+ }
+#endif /* SECUREC_FOR_WCHAR */
+ if (attr->textLen < 0) {
+ attr->textLen = 0;
+ }
+}
+
+/*
+ * Write one character to dest buffer
+ */
+SECUREC_INLINE void SecOutputOneChar(SecChar ch, SecPrintfStream *stream, int *counter)
+{
+ /* Count must be reduced first, In order to identify insufficient length */
+ stream->count -= (int)(sizeof(SecChar));
+ if (stream->count >= 0) {
+ *((SecChar *)(void *)(stream->cur)) = (SecChar)ch;
+ stream->cur += sizeof(SecChar);
+ *counter = *(counter) + 1;
+ return;
+ }
+ /* No enough length */
+ *counter = -1;
+}
+
+/*
+ * Check precison in format
+ */
+SECUREC_INLINE int SecDecodePrecision(SecChar ch, SecFormatAttr *attr)
+{
+ if (attr->dynPrecision == 0) {
+ /* Add digit to current precision */
+ if (SECUREC_MUL_TEN_ADD_BEYOND_MAX(attr->precision)) {
+ return -1;
+ }
+ attr->precision = (int)SECUREC_MUL_TEN((unsigned int)attr->precision) +
+ (unsigned char)(ch - SECUREC_CHAR('0'));
+ } else {
+ if (attr->precision < 0) {
+ attr->precision = -1;
+ }
+ if (attr->precision > SECUREC_MAX_WIDTH_LEN) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Check width in format
+ */
+SECUREC_INLINE int SecDecodeWidth(SecChar ch, SecFormatAttr *attr, SecFmtState lastState)
+{
+ if (attr->dynWidth == 0) {
+ if (lastState != STAT_WIDTH) {
+ attr->fldWidth = 0;
+ }
+ if (SECUREC_MUL_TEN_ADD_BEYOND_MAX(attr->fldWidth)) {
+ return -1;
+ }
+ attr->fldWidth = (int)SECUREC_MUL_TEN((unsigned int)attr->fldWidth) +
+ (unsigned char)(ch - SECUREC_CHAR('0'));
+ } else {
+ if (attr->fldWidth < 0) {
+ attr->flags |= SECUREC_FLAG_LEFT;
+ attr->fldWidth = (-attr->fldWidth);
+ if (attr->fldWidth > SECUREC_MAX_WIDTH_LEN) {
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * The sprintf_s function processes the wide character as a parameter for %C
+ * The swprintf_s function processes the multiple character as a parameter for %C
+ */
+SECUREC_INLINE void SecUpdateWcharFlags(SecFormatAttr *attr)
+{
+ if ((attr->flags & (SECUREC_FLAG_SHORT | SECUREC_FLAG_LONG | SECUREC_FLAG_WIDECHAR)) == 0) {
+#ifdef SECUREC_FOR_WCHAR
+ attr->flags |= SECUREC_FLAG_SHORT;
+#else
+ attr->flags |= SECUREC_FLAG_WIDECHAR;
+#endif
+ }
+}
+/*
+ * When encountering %S, current just same as %C
+ */
+SECUREC_INLINE void SecUpdateWstringFlags(SecFormatAttr *attr)
+{
+ SecUpdateWcharFlags(attr);
+}
+
+#if SECUREC_IN_KERNEL
+SECUREC_INLINE void SecUpdatePointFlagsForKernel(SecFormatAttr *attr)
+{
+ /* Width is not set */
+ if (attr->fldWidth <= 0) {
+ attr->flags |= SECUREC_FLAG_LEADZERO;
+ attr->fldWidth = 2 * sizeof(void *); /* 2 x byte number is the length of hex */
+ }
+ if ((attr->flags & SECUREC_FLAG_ALTERNATE) != 0) {
+ /* Alternate form means '0x' prefix */
+ attr->prefix[0] = SECUREC_CHAR('0');
+ attr->prefix[1] = SECUREC_CHAR('x');
+ attr->prefixLen = SECUREC_PREFIX_LEN;
+ }
+ attr->flags |= SECUREC_FLAG_LONG; /* Converting a long */
+}
+#endif
+
+SECUREC_INLINE void SecUpdatePointFlags(SecFormatAttr *attr)
+{
+ attr->flags |= SECUREC_FLAG_POINTER;
+#if SECUREC_IN_KERNEL
+ SecUpdatePointFlagsForKernel(attr);
+#else
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) || defined(SECUREC_VXWORKS_PLATFORM)) && (!defined(SECUREC_ON_UNIX))
+#if defined(SECUREC_VXWORKS_PLATFORM)
+ attr->precision = 1;
+#else
+ attr->precision = 0;
+#endif
+ attr->flags |= SECUREC_FLAG_ALTERNATE; /* "0x" is not default prefix in UNIX */
+ attr->digits = g_itoaLowerDigits;
+#else /* On unix or win */
+#if defined(_AIX) || defined(SECUREC_ON_SOLARIS)
+ attr->precision = 1;
+#else
+ attr->precision = 2 * sizeof(void *); /* 2 x byte number is the length of hex */
+#endif
+#if defined(SECUREC_ON_UNIX)
+ attr->digits = g_itoaLowerDigits;
+#else
+ attr->digits = g_itoaUpperDigits;
+#endif
+#endif
+
+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+ attr->flags &= ~SECUREC_FLAG_LEADZERO;
+#endif
+
+#ifdef SECUREC_ON_64BITS
+ attr->flags |= SECUREC_FLAG_I64; /* Converting an int64 */
+#else
+ attr->flags |= SECUREC_FLAG_LONG; /* Converting a long */
+#endif
+ /* Set up for %#p on different system */
+ if ((attr->flags & SECUREC_FLAG_ALTERNATE) != 0) {
+ /* Alternate form means '0x' prefix */
+ attr->prefix[0] = SECUREC_CHAR('0');
+#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) || defined(SECUREC_VXWORKS_PLATFORM))
+ attr->prefix[1] = SECUREC_CHAR('x');
+#else
+ attr->prefix[1] = (SecChar)(attr->digits[16]); /* 16 for 'x' or 'X' */
+#endif
+#if defined(_AIX) || defined(SECUREC_ON_SOLARIS)
+ attr->prefixLen = 0;
+#else
+ attr->prefixLen = SECUREC_PREFIX_LEN;
+#endif
+ }
+#endif
+}
+
+SECUREC_INLINE void SecUpdateXpxFlags(SecFormatAttr *attr, SecChar ch)
+{
+ /* Use unsigned lower hex output for 'x' */
+ attr->digits = g_itoaLowerDigits;
+ attr->radix = SECUREC_RADIX_HEX;
+ switch (ch) {
+ case SECUREC_CHAR('p'):
+ /* Print a pointer */
+ SecUpdatePointFlags(attr);
+ break;
+ case SECUREC_CHAR('X'): /* fall-through */ /* FALLTHRU */
+ /* Unsigned upper hex output */
+ attr->digits = g_itoaUpperDigits;
+ /* fall-through */ /* FALLTHRU */
+ default:
+ /* For %#x or %#X */
+ if ((attr->flags & SECUREC_FLAG_ALTERNATE) != 0) {
+ /* Alternate form means '0x' prefix */
+ attr->prefix[0] = SECUREC_CHAR('0');
+ attr->prefix[1] = (SecChar)(attr->digits[16]); /* 16 for 'x' or 'X' */
+ attr->prefixLen = SECUREC_PREFIX_LEN;
+ }
+ break;
+ }
+}
+SECUREC_INLINE void SecUpdateOudiFlags(SecFormatAttr *attr, SecChar ch)
+{
+ /* Do not set digits here */
+ switch (ch) {
+ case SECUREC_CHAR('i'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('d'): /* fall-through */ /* FALLTHRU */
+ /* For signed decimal output */
+ attr->flags |= SECUREC_FLAG_SIGNED;
+ /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('u'):
+ attr->radix = SECUREC_RADIX_DECIMAL;
+ attr->digits = g_itoaLowerDigits;
+ break;
+ case SECUREC_CHAR('o'):
+ /* For unsigned octal output */
+ attr->radix = SECUREC_RADIX_OCTAL;
+ attr->digits = g_itoaLowerDigits;
+ if ((attr->flags & SECUREC_FLAG_ALTERNATE) != 0) {
+ /* Alternate form means force a leading 0 */
+ attr->flags |= SECUREC_FLAG_FORCE_OCTAL;
+ }
+ break;
+ default:
+ /* Do nothing */
+ break;
+ }
+}
+
+#if SECUREC_ENABLE_SPRINTF_FLOAT
+SECUREC_INLINE void SecFreeFloatBuffer(SecFloatAdapt *floatAdapt)
+{
+ if (floatAdapt->floatBuffer != NULL) {
+ SECUREC_FREE(floatAdapt->floatBuffer);
+ }
+ if (floatAdapt->allocatedFmtStr != NULL) {
+ SECUREC_FREE(floatAdapt->allocatedFmtStr);
+ }
+ floatAdapt->floatBuffer = NULL;
+ floatAdapt->allocatedFmtStr = NULL;
+ floatAdapt->fmtStr = NULL;
+ floatAdapt->bufferSize = 0;
+}
+
+SECUREC_INLINE void SecSeekToFrontPercent(const SecChar **format)
+{
+ const SecChar *fmt = *format;
+ while (*fmt != SECUREC_CHAR('%')) { /* Must meet '%' */
+ --fmt;
+ }
+ *format = fmt;
+}
+
+/* Init float format, return 0 is OK */
+SECUREC_INLINE int SecInitFloatFmt(SecFloatAdapt *floatFmt, const SecChar *format)
+{
+ const SecChar *fmt = format - 2; /* Sub 2 to the position before 'f' or 'g' */
+ int fmtStrLen;
+ int i;
+
+ SecSeekToFrontPercent(&fmt);
+ /* Now fmt point to '%' */
+ fmtStrLen = (int)(size_t)(format - fmt) + 1; /* With ending terminator */
+ if (fmtStrLen > (int)sizeof(floatFmt->buffer)) {
+ /* When buffer is NOT enough, alloc a new buffer */
+ floatFmt->allocatedFmtStr = (char *)SECUREC_MALLOC((size_t)((unsigned int)fmtStrLen));
+ if (floatFmt->allocatedFmtStr == NULL) {
+ return -1;
+ }
+ floatFmt->fmtStr = floatFmt->allocatedFmtStr;
+ } else {
+ floatFmt->fmtStr = floatFmt->buffer;
+ floatFmt->allocatedFmtStr = NULL; /* Must set to NULL, later code free memory based on this identity */
+ }
+
+ for (i = 0; i < fmtStrLen - 1; ++i) {
+ /* Convert wchar to char */
+ floatFmt->fmtStr[i] = (char)(fmt[i]); /* Copy the format string */
+ }
+ floatFmt->fmtStr[fmtStrLen - 1] = '\0';
+
+ return 0;
+}
+
+/* Init float buffer and format, return 0 is OK */
+SECUREC_INLINE int SecInitFloatBuffer(SecFloatAdapt *floatAdapt, const SecChar *format, SecFormatAttr *attr)
+{
+ floatAdapt->allocatedFmtStr = NULL;
+ floatAdapt->fmtStr = NULL;
+ floatAdapt->floatBuffer = NULL;
+ /* Compute the precision value */
+ if (attr->precision < 0) {
+ attr->precision = SECUREC_FLOAT_DEFAULT_PRECISION;
+ }
+ /*
+ * Calc buffer size to store double value
+ * The maximum length of SECUREC_MAX_WIDTH_LEN is enough
+ */
+ if ((attr->flags & SECUREC_FLAG_LONG_DOUBLE) != 0) {
+ if (attr->precision > (SECUREC_MAX_WIDTH_LEN - SECUREC_FLOAT_BUFSIZE_LB)) {
+ return -1;
+ }
+ /* Long double needs to meet the basic print length */
+ floatAdapt->bufferSize = SECUREC_FLOAT_BUFSIZE_LB + attr->precision + SECUREC_FLOAT_BUF_EXT;
+ } else {
+ if (attr->precision > (SECUREC_MAX_WIDTH_LEN - SECUREC_FLOAT_BUFSIZE)) {
+ return -1;
+ }
+ /* Double needs to meet the basic print length */
+ floatAdapt->bufferSize = SECUREC_FLOAT_BUFSIZE + attr->precision + SECUREC_FLOAT_BUF_EXT;
+ }
+ if (attr->fldWidth > floatAdapt->bufferSize) {
+ floatAdapt->bufferSize = attr->fldWidth + SECUREC_FLOAT_BUF_EXT;
+ }
+
+ if (floatAdapt->bufferSize > SECUREC_BUFFER_SIZE) {
+ /* The current vlaue of SECUREC_BUFFER_SIZE could NOT store the formatted float string */
+ floatAdapt->floatBuffer = (char *)SECUREC_MALLOC(((size_t)(unsigned int)floatAdapt->bufferSize));
+ if (floatAdapt->floatBuffer == NULL) {
+ return -1;
+ }
+ attr->text.str = floatAdapt->floatBuffer;
+ } else {
+ attr->text.str = attr->buffer.str; /* Output buffer for float string with default size */
+ }
+
+ if (SecInitFloatFmt(floatAdapt, format) != 0) {
+ if (floatAdapt->floatBuffer != NULL) {
+ SECUREC_FREE(floatAdapt->floatBuffer);
+ floatAdapt->floatBuffer = NULL;
+ }
+ return -1;
+ }
+ return 0;
+}
+#endif
+
+SECUREC_INLINE SecInt64 SecUpdateNegativeChar(SecFormatAttr *attr, char ch)
+{
+ SecInt64 num64 = ch; /* Sign extend */
+ if (num64 >= 128) { /* 128 on some platform, char is always unsigned */
+ unsigned char tmp = (unsigned char)(~((unsigned char)ch));
+ num64 = tmp + 1;
+ attr->flags |= SECUREC_FLAG_NEGATIVE;
+ }
+ return num64;
+}
+
+/*
+ * If the precision is not satisfied, zero is added before the string
+ */
+SECUREC_INLINE void SecNumberSatisfyPrecision(SecFormatAttr *attr)
+{
+ int precision;
+ if (attr->precision < 0) {
+ precision = 1; /* Default precision 1 */
+ } else {
+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+ attr->flags &= ~SECUREC_FLAG_LEADZERO;
+#else
+ if ((attr->flags & SECUREC_FLAG_POINTER) == 0) {
+ attr->flags &= ~SECUREC_FLAG_LEADZERO;
+ }
+#endif
+ if (attr->precision > SECUREC_MAX_PRECISION) {
+ attr->precision = SECUREC_MAX_PRECISION;
+ }
+ precision = attr->precision;
+ }
+ while (attr->textLen < precision) {
+ --attr->text.str;
+ *(attr->text.str) = '0';
+ ++attr->textLen;
+ }
+}
+
+/*
+ * Add leading zero for %#o
+ */
+SECUREC_INLINE void SecNumberForceOctal(SecFormatAttr *attr)
+{
+ /* Force a leading zero if FORCEOCTAL flag set */
+ if ((attr->flags & SECUREC_FLAG_FORCE_OCTAL) != 0 &&
+ (attr->textLen == 0 || attr->text.str[0] != '0')) {
+ --attr->text.str;
+ *(attr->text.str) = '0';
+ ++attr->textLen;
+ }
+}
+
+SECUREC_INLINE void SecUpdateSignedNumberPrefix(SecFormatAttr *attr)
+{
+ if ((attr->flags & SECUREC_FLAG_SIGNED) == 0) {
+ return;
+ }
+ if ((attr->flags & SECUREC_FLAG_NEGATIVE) != 0) {
+ /* Prefix is '-' */
+ attr->prefix[0] = SECUREC_CHAR('-');
+ attr->prefixLen = 1;
+ return;
+ }
+ if ((attr->flags & SECUREC_FLAG_SIGN) != 0) {
+ /* Prefix is '+' */
+ attr->prefix[0] = SECUREC_CHAR('+');
+ attr->prefixLen = 1;
+ return;
+ }
+ if ((attr->flags & SECUREC_FLAG_SIGN_SPACE) != 0) {
+ /* Prefix is ' ' */
+ attr->prefix[0] = SECUREC_CHAR(' ');
+ attr->prefixLen = 1;
+ return;
+ }
+ return;
+}
+
+SECUREC_INLINE void SecNumberCompatZero(SecFormatAttr *attr)
+{
+#if SECUREC_IN_KERNEL
+ if ((attr->flags & SECUREC_FLAG_POINTER) != 0) {
+ static char strNullPointer[SECUREC_NULL_STRING_SIZE] = "(null)";
+ attr->text.str = strNullPointer;
+ attr->textLen = 6; /* Length of (null) is 6 */
+ attr->flags &= ~SECUREC_FLAG_LEADZERO;
+ attr->prefixLen = 0;
+ if (attr->precision >= 0 && attr->precision < attr->textLen) {
+ attr->textLen = attr->precision;
+ }
+ }
+ if ((attr->flags & SECUREC_FLAG_POINTER) == 0 && attr->radix == SECUREC_RADIX_HEX &&
+ (attr->flags & SECUREC_FLAG_ALTERNATE) != 0) {
+ /* Add 0x prefix for %x or %X, the prefix string has been set before */
+ attr->prefixLen = SECUREC_PREFIX_LEN;
+ }
+#elif defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && (!defined(SECUREC_ON_UNIX))
+ if ((attr->flags & SECUREC_FLAG_POINTER) != 0) {
+ static char strNullPointer[SECUREC_NULL_STRING_SIZE] = "(nil)";
+ attr->text.str = strNullPointer;
+ attr->textLen = 5; /* Length of (nil) is 5 */
+ attr->flags &= ~SECUREC_FLAG_LEADZERO;
+ }
+#elif defined(SECUREC_VXWORKS_PLATFORM) || defined(__hpux)
+ if ((attr->flags & SECUREC_FLAG_POINTER) != 0 && (attr->flags & SECUREC_FLAG_ALTERNATE) != 0) {
+ /* Add 0x prefix for %p, the prefix string has been set before */
+ attr->prefixLen = SECUREC_PREFIX_LEN;
+ }
+#endif
+ (void)attr; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+}
+
+#ifdef SECUREC_FOR_WCHAR
+/*
+ * Formatting output core functions for wchar version.Called by a function such as vswprintf_s
+ * The argList must not be declare as const
+ */
+SECUREC_INLINE int SecOutputSW(SecPrintfStream *stream, const wchar_t *cFormat, va_list argList)
+#else
+/*
+ * Formatting output core functions for char version.Called by a function such as vsnprintf_s
+ */
+SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_list argList)
+#endif
+{
+ const SecChar *format = cFormat;
+ int charsOut; /* Characters written */
+ int noOutput = 0; /* Must be initialized or compiler alerts */
+ SecFmtState state;
+ SecFormatAttr formatAttr;
+
+ formatAttr.flags = 0;
+ formatAttr.textIsWide = 0; /* Flag for buffer contains wide chars */
+ formatAttr.fldWidth = 0;
+ formatAttr.precision = 0;
+ formatAttr.dynWidth = 0;
+ formatAttr.dynPrecision = 0;
+ formatAttr.digits = g_itoaUpperDigits;
+ formatAttr.radix = SECUREC_RADIX_DECIMAL;
+ formatAttr.padding = 0;
+ formatAttr.textLen = 0;
+ formatAttr.text.str = NULL;
+ formatAttr.prefixLen = 0;
+ formatAttr.prefix[0] = SECUREC_CHAR('\0');
+ formatAttr.prefix[1] = SECUREC_CHAR('\0');
+ charsOut = 0;
+ state = STAT_NORMAL; /* Starting state */
+
+ /* Loop each format character */
+ while (*format != SECUREC_CHAR('\0') && charsOut >= 0) {
+ SecFmtState lastState = state;
+ SecChar ch = *format; /* Currently read character */
+ ++format;
+ state = SecDecodeState(ch, lastState);
+ switch (state) {
+ case STAT_NORMAL:
+ SecOutputOneChar(ch, stream, &charsOut);
+ continue;
+ case STAT_PERCENT:
+ /* Set default values */
+ noOutput = 0;
+ formatAttr.prefixLen = 0;
+ formatAttr.textLen = 0;
+ formatAttr.flags = 0;
+ formatAttr.fldWidth = 0;
+ formatAttr.precision = -1;
+ formatAttr.textIsWide = 0;
+ formatAttr.dynWidth = 0;
+ formatAttr.dynPrecision = 0;
+ break;
+ case STAT_FLAG:
+ /* Set flag based on which flag character */
+ SecDecodeFlags(ch, &formatAttr);
+ break;
+ case STAT_WIDTH:
+ /* Update width value */
+ if (ch == SECUREC_CHAR('*')) {
+ /* get width from arg list */
+ formatAttr.fldWidth = (int)va_arg(argList, int);
+ formatAttr.dynWidth = 1;
+ }
+ if (SecDecodeWidth(ch, &formatAttr, lastState) != 0) {
+ return -1;
+ }
+ break;
+ case STAT_DOT:
+ formatAttr.precision = 0;
+ break;
+ case STAT_PRECIS:
+ /* Update precison value */
+ if (ch == SECUREC_CHAR('*')) {
+ /* Get precision from arg list */
+ formatAttr.precision = (int)va_arg(argList, int);
+ formatAttr.dynPrecision = 1;
+ }
+ if (SecDecodePrecision(ch, &formatAttr) != 0) {
+ return -1;
+ }
+ break;
+ case STAT_SIZE:
+ /* Read a size specifier, set the formatAttr.flags based on it, and skip format to next charater */
+ if (SecDecodeSize(ch, &formatAttr, &format) != 0) {
+ /* Compatibility code for "%I" just print I */
+ SecOutputOneChar(ch, stream, &charsOut);
+ state = STAT_NORMAL;
+ continue;
+ }
+ break;
+ case STAT_TYPE:
+ switch (ch) {
+ case SECUREC_CHAR('C'): /* Wide char */
+ SecUpdateWcharFlags(&formatAttr);
+ /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('c'): {
+ unsigned int cValue = (unsigned int)va_arg(argList, int);
+ SecDecodeTypeC(&formatAttr, cValue);
+ break;
+ }
+ case SECUREC_CHAR('S'): /* Wide char string */
+ SecUpdateWstringFlags(&formatAttr);
+ /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('s'): {
+ char *argPtr = (char *)va_arg(argList, char *);
+ SecDecodeTypeS(&formatAttr, argPtr);
+ break;
+ }
+ case SECUREC_CHAR('G'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('g'): /* fall-through */ /* FALLTHRU */
+ /* Default precision is 1 for g or G */
+ if (formatAttr.precision == 0) {
+ formatAttr.precision = 1;
+ }
+ /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('E'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('F'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('e'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('f'): {
+#if SECUREC_ENABLE_SPRINTF_FLOAT
+ /* Add following code to call system sprintf API for float number */
+ SecFloatAdapt floatAdapt;
+ noOutput = 1; /* It's no more data needs to be written */
+
+ /* Now format is pointer to the next character of 'f' */
+ if (SecInitFloatBuffer(&floatAdapt, format, &formatAttr) != 0) {
+ break;
+ }
+
+ if ((formatAttr.flags & SECUREC_FLAG_LONG_DOUBLE) != 0) {
+#if defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && SECUREC_ENABLE_SPRINTF_LONG_DOUBLE
+ long double tmp = (long double)va_arg(argList, long double);
+ SecFormatLongDouble(&formatAttr, &floatAdapt, tmp);
+#else
+ double tmp = (double)va_arg(argList, double);
+ SecFormatDouble(&formatAttr, &floatAdapt, tmp);
+#endif
+ } else {
+ double tmp = (double)va_arg(argList, double);
+ SecFormatDouble(&formatAttr, &floatAdapt, tmp);
+ }
+
+ /* Only need write formated float string */
+ SecWriteFloatText(stream, &formatAttr, &charsOut);
+ SecFreeFloatBuffer(&floatAdapt);
+ break;
+#else
+ return -1;
+#endif
+ }
+ case SECUREC_CHAR('X'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('p'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('x'): /* fall-through */ /* FALLTHRU */
+ SecUpdateXpxFlags(&formatAttr, ch);
+ /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('i'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('d'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('u'): /* fall-through */ /* FALLTHRU */
+ case SECUREC_CHAR('o'): {
+ SecInt64 num64;
+ SecUpdateOudiFlags(&formatAttr, ch);
+ /* Read argument into variable num64. Be careful, depend on the order of judgment */
+ if ((formatAttr.flags & SECUREC_FLAG_I64) != 0 ||
+ (formatAttr.flags & SECUREC_FLAG_LONGLONG) != 0) {
+ num64 = (SecInt64)va_arg(argList, SecInt64); /* Maximum Bit Width sign bit unchanged */
+ } else if ((formatAttr.flags & SECUREC_FLAG_LONG) != 0) {
+ num64 = SECUREC_GET_LONG_FROM_ARG(formatAttr);
+ } else if ((formatAttr.flags & SECUREC_FLAG_CHAR) != 0) {
+ num64 = SECUREC_GET_CHAR_FROM_ARG(formatAttr);
+ } else if ((formatAttr.flags & SECUREC_FLAG_SHORT) != 0) {
+ num64 = SECUREC_GET_SHORT_FROM_ARG(formatAttr);
+#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
+ } else if ((formatAttr.flags & SECUREC_FLAG_PTRDIFF) != 0) {
+ num64 = (ptrdiff_t)va_arg(argList, ptrdiff_t); /* Sign extend */
+ } else if ((formatAttr.flags & SECUREC_FLAG_SIZE) != 0) {
+ num64 = SECUREC_GET_SIZE_FROM_ARG(formatAttr);
+ } else if ((formatAttr.flags & SECUREC_FLAG_INTMAX) != 0) {
+ num64 = (SecInt64)va_arg(argList, SecInt64);
+#endif
+ } else {
+ num64 = SECUREC_GET_INT_FROM_ARG(formatAttr);
+ }
+
+ /* The order of the following calls must be correct */
+ SecNumberToBuffer(&formatAttr, num64);
+ SecNumberSatisfyPrecision(&formatAttr);
+ SecNumberForceOctal(&formatAttr);
+ SecUpdateSignedNumberPrefix(&formatAttr);
+ if (num64 == 0) {
+ SecNumberCompatZero(&formatAttr);
+ }
+ break;
+ }
+ default:
+ /* Do nothing */
+ break;
+ }
+
+ if (noOutput == 0) {
+ /* Calculate amount of padding */
+ formatAttr.padding = (formatAttr.fldWidth - formatAttr.textLen) - formatAttr.prefixLen;
+
+ /* Put out the padding, prefix, and text, in the correct order */
+ SecWriteLeftPadding(stream, &formatAttr, &charsOut);
+ SecWritePrefix(stream, &formatAttr, &charsOut);
+ SecWriteLeadingZero(stream, &formatAttr, &charsOut);
+ SecWriteText(stream, &formatAttr, &charsOut);
+ SecWriteRightPadding(stream, &formatAttr, &charsOut);
+ }
+ break;
+ case STAT_INVALID: /* fall-through */ /* FALLTHRU */
+ default:
+ return -1; /* Input format is wrong(STAT_INVALID), directly return */
+ }
+ }
+
+ if (state != STAT_NORMAL && state != STAT_TYPE) {
+ return -1;
+ }
+
+ return charsOut; /* The number of characters written */
+}
+
+/*
+ * Output one zero character zero into the SecPrintfStream structure
+ * If there is not enough space, make sure f->count is less than 0
+ */
+SECUREC_INLINE int SecPutZeroChar(SecPrintfStream *str)
+{
+ --str->count;
+ if (str->count >= 0) {
+ *(str->cur) = '\0';
+ str->cur = str->cur + 1;
+ return 0;
+ }
+ return -1;
+}
+
+#endif /* OUTPUT_INL_2B263E9C_43D8_44BB_B17A_6D2033DECEE5 */
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/scanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/scanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..0ae200e682e4a65bc9c2771c69ccf49a3f0a35b4
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/scanf_s.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: scanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securec.h"
+
+/*
+ *
+ * The scanf_s function is equivalent to fscanf_s with the argument stdin interposed before the arguments to scanf_s
+ * The scanf_s function reads data from the standard input stream stdin and
+ * writes the data into the location that's given by argument. Each argument
+ * must be a pointer to a variable of a type that corresponds to a type specifier
+ * in format. If copying occurs between strings that overlap, the behavior is
+ * undefined.
+ *
+ *
+ * format Format control string.
+ * ... Optional arguments.
+ *
+ *
+ * ... The converted value stored in user assigned address
+ *
+ *
+ * Returns the number of fields successfully converted and assigned;
+ * the return value does not include fields that were read but not assigned.
+ * A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int scanf_s(const char *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vscanf_s(format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/secinput.h b/3rd/gstor/dependency/Huawei_Secure_C/src/secinput.h
new file mode 100644
index 0000000000000000000000000000000000000000..15c10451a1112723d884b47b871ad7ffed455a25
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/secinput.h
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: Define macro, data struct, and declare function prototype,
+ * which is used by input.inl, secureinput_a.c and secureinput_w.c.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
+#define SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
+#include "securecutil.h"
+
+#define SECUREC_SCANF_EINVAL (-1)
+#define SECUREC_SCANF_ERROR_PARA (-2)
+
+/* For internal stream flag */
+#define SECUREC_MEM_STR_FLAG 0x01U
+#define SECUREC_FILE_STREAM_FLAG 0x02U
+#define SECUREC_PIPE_STREAM_FLAG 0x04U
+#define SECUREC_LOAD_FILE_TO_MEM_FLAG 0x08U
+
+#define SECUREC_UCS_BOM_HEADER_SIZE 2U
+#define SECUREC_UCS_BOM_HEADER_BE_1ST 0xfeU
+#define SECUREC_UCS_BOM_HEADER_BE_2ST 0xffU
+#define SECUREC_UCS_BOM_HEADER_LE_1ST 0xffU
+#define SECUREC_UCS_BOM_HEADER_LE_2ST 0xfeU
+#define SECUREC_UTF8_BOM_HEADER_SIZE 3U
+#define SECUREC_UTF8_BOM_HEADER_1ST 0xefU
+#define SECUREC_UTF8_BOM_HEADER_2ND 0xbbU
+#define SECUREC_UTF8_BOM_HEADER_3RD 0xbfU
+#define SECUREC_UTF8_LEAD_1ST 0xe0U
+#define SECUREC_UTF8_LEAD_2ND 0x80U
+
+#define SECUREC_BEGIN_WITH_UCS_BOM(s, len) ((len) >= SECUREC_UCS_BOM_HEADER_SIZE && \
+ (((unsigned char)((s)[0]) == SECUREC_UCS_BOM_HEADER_LE_1ST && \
+ (unsigned char)((s)[1]) == SECUREC_UCS_BOM_HEADER_LE_2ST) || \
+ ((unsigned char)((s)[0]) == SECUREC_UCS_BOM_HEADER_BE_1ST && \
+ (unsigned char)((s)[1]) == SECUREC_UCS_BOM_HEADER_BE_2ST)))
+
+#define SECUREC_BEGIN_WITH_UTF8_BOM(s, len) ((len) >= SECUREC_UTF8_BOM_HEADER_SIZE && \
+ (unsigned char)((s)[0]) == SECUREC_UTF8_BOM_HEADER_1ST && \
+ (unsigned char)((s)[1]) == SECUREC_UTF8_BOM_HEADER_2ND && \
+ (unsigned char)((s)[2]) == SECUREC_UTF8_BOM_HEADER_3RD)
+
+#ifdef SECUREC_FOR_WCHAR
+#define SECUREC_BOM_HEADER_SIZE SECUREC_UCS_BOM_HEADER_SIZE
+#define SECUREC_BEGIN_WITH_BOM(s, len) SECUREC_BEGIN_WITH_UCS_BOM((s), (len))
+#else
+#define SECUREC_BOM_HEADER_SIZE SECUREC_UTF8_BOM_HEADER_SIZE
+#define SECUREC_BEGIN_WITH_BOM(s, len) SECUREC_BEGIN_WITH_UTF8_BOM((s), (len))
+#endif
+
+typedef struct {
+ unsigned int flag; /* Mark the properties of input stream */
+ char *base; /* The pointer to the header of buffered string */
+ const char *cur; /* The pointer to next read position */
+ size_t count; /* The size of buffered string in bytes */
+#if SECUREC_ENABLE_SCANF_FILE
+ FILE *pf; /* The file pointer */
+ size_t fileRealRead;
+ long oriFilePos; /* The original position of file offset when fscanf is called */
+#if !SECUREC_USE_STD_UNGETC
+ unsigned int lastChar; /* The char code of last input */
+ int fUnGet; /* The boolean flag of pushing a char back to read stream */
+#endif
+#endif
+} SecFileStream;
+
+#if SECUREC_ENABLE_SCANF_FILE && !SECUREC_USE_STD_UNGETC
+#define SECUREC_FILE_STREAM_INIT_FILE(stream, fp) do { \
+ (stream)->pf = (fp); \
+ (stream)->fileRealRead = 0; \
+ (stream)->oriFilePos = 0; \
+ (stream)->lastChar = 0; \
+ (stream)->fUnGet = 0; \
+} SECUREC_WHILE_ZERO
+#elif SECUREC_ENABLE_SCANF_FILE && SECUREC_USE_STD_UNGETC
+#define SECUREC_FILE_STREAM_INIT_FILE(stream, fp) do { \
+ (stream)->pf = (fp); \
+ (stream)->fileRealRead = 0; \
+ (stream)->oriFilePos = 0; \
+} SECUREC_WHILE_ZERO
+#else
+/* Disable file */
+#define SECUREC_FILE_STREAM_INIT_FILE(stream, fp)
+#endif
+
+/* This initialization for eliminating redundant initialization. */
+#define SECUREC_FILE_STREAM_FROM_STRING(stream, buf, cnt) do { \
+ (stream)->flag = SECUREC_MEM_STR_FLAG; \
+ (stream)->base = NULL; \
+ (stream)->cur = (buf); \
+ (stream)->count = (cnt); \
+ SECUREC_FILE_STREAM_INIT_FILE((stream), NULL); \
+} SECUREC_WHILE_ZERO
+
+/* This initialization for eliminating redundant initialization. */
+#define SECUREC_FILE_STREAM_FROM_FILE(stream, fp) do { \
+ (stream)->flag = SECUREC_FILE_STREAM_FLAG; \
+ (stream)->base = NULL; \
+ (stream)->cur = NULL; \
+ (stream)->count = 0; \
+ SECUREC_FILE_STREAM_INIT_FILE((stream), (fp)); \
+} SECUREC_WHILE_ZERO
+
+/* This initialization for eliminating redundant initialization. */
+#define SECUREC_FILE_STREAM_FROM_STDIN(stream) do { \
+ (stream)->flag = SECUREC_PIPE_STREAM_FLAG; \
+ (stream)->base = NULL; \
+ (stream)->cur = NULL; \
+ (stream)->count = 0; \
+ SECUREC_FILE_STREAM_INIT_FILE((stream), SECUREC_STREAM_STDIN); \
+} SECUREC_WHILE_ZERO
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList);
+ void SecClearDestBuf(const char *buffer, const char *format, va_list argList);
+#ifdef SECUREC_FOR_WCHAR
+ int SecInputSW(SecFileStream *stream, const wchar_t *cFormat, va_list argList);
+ void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, va_list argList);
+#endif
+
+/* 20150105 For software and hardware decoupling,such as UMG */
+#ifdef SECUREC_SYSAPI4VXWORKS
+#ifdef feof
+#undef feof
+#endif
+ extern int feof(FILE *stream);
+#endif
+
+#if defined(SECUREC_SYSAPI4VXWORKS) || defined(SECUREC_CTYPE_MACRO_ADAPT)
+#ifndef isspace
+#define isspace(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n'))
+#endif
+#ifndef iswspace
+#define iswspace(c) (((c) == L' ') || ((c) == L'\t') || ((c) == L'\r') || ((c) == L'\n'))
+#endif
+#ifndef isascii
+#define isascii(c) (((unsigned char)(c)) <= 0x7f)
+#endif
+#ifndef isupper
+#define isupper(c) ((c) >= 'A' && (c) <= 'Z')
+#endif
+#ifndef islower
+#define islower(c) ((c) >= 'a' && (c) <= 'z')
+#endif
+#ifndef isalpha
+#define isalpha(c) (isupper(c) || (islower(c)))
+#endif
+#ifndef isdigit
+#define isdigit(c) ((c) >= '0' && (c) <= '9')
+#endif
+#ifndef isxupper
+#define isxupper(c) ((c) >= 'A' && (c) <= 'F')
+#endif
+#ifndef isxlower
+#define isxlower(c) ((c) >= 'a' && (c) <= 'f')
+#endif
+#ifndef isxdigit
+#define isxdigit(c) (isdigit(c) || isxupper(c) || isxlower(c))
+#endif
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+/* Reserved file operation macro interface, s is FILE *, i is fileno zero. */
+#ifndef SECUREC_LOCK_FILE
+#define SECUREC_LOCK_FILE(s)
+#endif
+
+#ifndef SECUREC_UNLOCK_FILE
+#define SECUREC_UNLOCK_FILE(s)
+#endif
+
+#ifndef SECUREC_LOCK_STDIN
+#define SECUREC_LOCK_STDIN(i, s)
+#endif
+
+#ifndef SECUREC_UNLOCK_STDIN
+#define SECUREC_UNLOCK_STDIN(i, s)
+#endif
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/securecutil.c b/3rd/gstor/dependency/Huawei_Secure_C/src/securecutil.c
new file mode 100644
index 0000000000000000000000000000000000000000..140cbf3c2dbd0f378e1dc295d31cee13d8933ce8
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/securecutil.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: Provides internal functions used by this library, such as memory
+ * copy and memory move. Besides, include some helper function for
+ * printf family API, such as SecVsnprintfImpl
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+/* Avoid duplicate header files,not include securecutil.h */
+#include "securecutil.h"
+
+#if defined(ANDROID) && (SECUREC_HAVE_WCTOMB || SECUREC_HAVE_MBTOWC)
+#include
+#if SECUREC_HAVE_WCTOMB
+/*
+ * Convert wide characters to narrow multi-bytes
+ */
+int wctomb(char *s, wchar_t wc)
+{
+ return wcrtomb(s, wc, NULL);
+}
+#endif
+
+#if SECUREC_HAVE_MBTOWC
+/*
+ * Converting narrow multi-byte characters to wide characters
+ */
+int mbtowc(wchar_t *pwc, const char *s, size_t n)
+{
+ return mbrtowc(pwc, s, n, NULL);
+}
+#endif
+#endif
+
+/* The V100R001C01 version num is 0x5 (High 8 bits) */
+#define SECUREC_C_VERSION 0x500U
+#define SECUREC_SPC_VERSION 0xaU
+#define SECUREC_VERSION_STR "V100R001C01SPC010B002"
+
+/*
+ * Get version string and version number.
+ * The rules for version number are as follows:
+ * 1) SPC verNumber<->verStr like:
+ * 0x201<->C01
+ * 0x202<->C01SPC001 Redefine numbers after this version
+ * 0x502<->C01SPC002
+ * 0x503<->C01SPC003
+ * ...
+ * 0X50a<->SPC010
+ * 0X50b<->SPC011
+ * ...
+ * 0x700<->C02
+ * 0x701<->C01SPC001
+ * 0x702<->C02SPC002
+ * ...
+ * 2) CP verNumber<->verStr like:
+ * 0X601<->CP0001
+ * 0X602<->CP0002
+ * ...
+ */
+const char *GetHwSecureCVersion(unsigned short *verNumber)
+{
+ if (verNumber != NULL) {
+ *verNumber = (unsigned short)(SECUREC_C_VERSION | SECUREC_SPC_VERSION);
+ }
+ return SECUREC_VERSION_STR;
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(GetHwSecureCVersion);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/securecutil.h b/3rd/gstor/dependency/Huawei_Secure_C/src/securecutil.h
new file mode 100644
index 0000000000000000000000000000000000000000..38cbd3e61ee3341bbf905402899ad37c6abe7181
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/securecutil.h
@@ -0,0 +1,559 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: Define macro, data struct, and declare internal used function prototype,
+ * which is used by secure functions.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef SECURECUTIL_H_46C86578_F8FF_4E49_8E64_9B175241761F
+#define SECURECUTIL_H_46C86578_F8FF_4E49_8E64_9B175241761F
+#include "securec.h"
+
+#if (defined(_MSC_VER)) && (_MSC_VER >= 1400)
+/* Shield compilation alerts using discarded functions and Constant expression to maximize code compatibility */
+#define SECUREC_MASK_MSVC_CRT_WARNING __pragma(warning(push)) \
+ __pragma(warning(disable : 4996 4127))
+#define SECUREC_END_MASK_MSVC_CRT_WARNING __pragma(warning(pop))
+#else
+#define SECUREC_MASK_MSVC_CRT_WARNING
+#define SECUREC_END_MASK_MSVC_CRT_WARNING
+#endif
+#define SECUREC_WHILE_ZERO SECUREC_MASK_MSVC_CRT_WARNING while (0) SECUREC_END_MASK_MSVC_CRT_WARNING
+
+/* Automatically identify the platform that supports strnlen function, and use this function to improve performance */
+#ifndef SECUREC_HAVE_STRNLEN
+#if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L)
+#if SECUREC_IN_KERNEL
+#define SECUREC_HAVE_STRNLEN 0
+#else
+#if defined(__GLIBC__) && __GLIBC__ >= 2 && defined(__GLIBC_MINOR__) && __GLIBC_MINOR__ >= 10
+#define SECUREC_HAVE_STRNLEN 1
+#else
+#define SECUREC_HAVE_STRNLEN 0
+#endif
+#endif
+#else
+#define SECUREC_HAVE_STRNLEN 0
+#endif
+#endif
+
+#if SECUREC_IN_KERNEL
+/* In kernel disbale functions */
+#ifndef SECUREC_ENABLE_SCANF_FILE
+#define SECUREC_ENABLE_SCANF_FILE 0
+#endif
+#ifndef SECUREC_ENABLE_SCANF_FLOAT
+#define SECUREC_ENABLE_SCANF_FLOAT 0
+#endif
+#ifndef SECUREC_ENABLE_SPRINTF_FLOAT
+#define SECUREC_ENABLE_SPRINTF_FLOAT 0
+#endif
+#ifndef SECUREC_HAVE_MBTOWC
+#define SECUREC_HAVE_MBTOWC 0
+#endif
+#ifndef SECUREC_HAVE_WCTOMB
+#define SECUREC_HAVE_WCTOMB 0
+#endif
+#ifndef SECUREC_HAVE_WCHART
+#define SECUREC_HAVE_WCHART 0
+#endif
+#else /* Not in kernel */
+/* Systems that do not support file, can define this macro to 0. */
+#ifndef SECUREC_ENABLE_SCANF_FILE
+#define SECUREC_ENABLE_SCANF_FILE 1
+#endif
+#ifndef SECUREC_ENABLE_SCANF_FLOAT
+#define SECUREC_ENABLE_SCANF_FLOAT 1
+#endif
+/* Systems that do not support float, can define this macro to 0. */
+#ifndef SECUREC_ENABLE_SPRINTF_FLOAT
+#define SECUREC_ENABLE_SPRINTF_FLOAT 1
+#endif
+#ifndef SECUREC_HAVE_MBTOWC
+#define SECUREC_HAVE_MBTOWC 1
+#endif
+#ifndef SECUREC_HAVE_WCTOMB
+#define SECUREC_HAVE_WCTOMB 1
+#endif
+#ifndef SECUREC_HAVE_WCHART
+#define SECUREC_HAVE_WCHART 1
+#endif
+#endif
+
+#ifndef SECUREC_USE_STD_UNGETC
+#define SECUREC_USE_STD_UNGETC 1
+#endif
+
+#ifndef SECUREC_ENABLE_INLINE
+#define SECUREC_ENABLE_INLINE 0
+#endif
+
+#ifndef SECUREC_INLINE
+#if SECUREC_ENABLE_INLINE
+#define SECUREC_INLINE static inline
+#else
+#define SECUREC_INLINE static
+#endif
+#endif
+
+#ifndef SECUREC_WARP_OUTPUT
+#if SECUREC_IN_KERNEL
+#define SECUREC_WARP_OUTPUT 1
+#else
+#define SECUREC_WARP_OUTPUT 0
+#endif
+#endif
+
+#ifndef SECUREC_STREAM_STDIN
+#define SECUREC_STREAM_STDIN stdin
+#endif
+
+#define SECUREC_MUL_SIXTEEN(x) ((x) << 4U)
+#define SECUREC_MUL_EIGHT(x) ((x) << 3U)
+#define SECUREC_MUL_TEN(x) ((((x) << 2U) + (x)) << 1U)
+/* Limited format input and output width, use signed integer */
+#define SECUREC_MAX_WIDTH_LEN_DIV_TEN 21474836
+#define SECUREC_MAX_WIDTH_LEN (SECUREC_MAX_WIDTH_LEN_DIV_TEN * 10)
+/* Is the x multiplied by 10 greater than */
+#define SECUREC_MUL_TEN_ADD_BEYOND_MAX(x) (((x) > SECUREC_MAX_WIDTH_LEN_DIV_TEN))
+
+#define SECUREC_FLOAT_BUFSIZE (309 + 40) /* Max length of double value */
+#define SECUREC_FLOAT_BUFSIZE_LB (4932 + 40) /* Max length of long double value */
+#define SECUREC_FLOAT_DEFAULT_PRECISION 6
+
+/* This macro does not handle pointer equality or integer overflow */
+#define SECUREC_MEMORY_NO_OVERLAP(dest, src, count) \
+ (((src) < (dest) && ((const char *)(src) + (count)) <= (char *)(dest)) || \
+ ((dest) < (src) && ((char *)(dest) + (count)) <= (const char *)(src)))
+
+#define SECUREC_MEMORY_IS_OVERLAP(dest, src, count) \
+ (((src) < (dest) && ((const char *)(src) + (count)) > (char *)(dest)) || \
+ ((dest) < (src) && ((char *)(dest) + (count)) > (const char *)(src)))
+
+/*
+ * Check whether the strings overlap, len is the length of the string not include terminator
+ * Length is related to data type char or wchar , do not force conversion of types
+ */
+#define SECUREC_STRING_NO_OVERLAP(dest, src, len) \
+ (((src) < (dest) && ((src) + (len)) < (dest)) || \
+ ((dest) < (src) && ((dest) + (len)) < (src)))
+
+/*
+ * Check whether the strings overlap for strcpy wcscpy function, dest len and src Len are not include terminator
+ * Length is related to data type char or wchar , do not force conversion of types
+ */
+#define SECUREC_STRING_IS_OVERLAP(dest, src, len) \
+ (((src) < (dest) && ((src) + (len)) >= (dest)) || \
+ ((dest) < (src) && ((dest) + (len)) >= (src)))
+
+/*
+ * Check whether the strings overlap for strcat wcscat function, dest len and src Len are not include terminator
+ * Length is related to data type char or wchar , do not force conversion of types
+ */
+#define SECUREC_CAT_STRING_IS_OVERLAP(dest, destLen, src, srcLen) \
+ (((dest) < (src) && ((dest) + (destLen) + (srcLen)) >= (src)) || \
+ ((src) < (dest) && ((src) + (srcLen)) >= (dest)))
+
+#if SECUREC_HAVE_STRNLEN
+#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \
+ *(outLen) = strnlen((str), (maxLen)); \
+} SECUREC_WHILE_ZERO
+#define SECUREC_CALC_STR_LEN_OPT(str, maxLen, outLen) do { \
+ if ((maxLen) > 8) { \
+ /* Optimization or len less then 8 */ \
+ if (*((str) + 0) == '\0') { \
+ *(outLen) = 0; \
+ } else if (*((str) + 1) == '\0') { \
+ *(outLen) = 1; \
+ } else if (*((str) + 2) == '\0') { \
+ *(outLen) = 2; \
+ } else if (*((str) + 3) == '\0') { \
+ *(outLen) = 3; \
+ } else if (*((str) + 4) == '\0') { \
+ *(outLen) = 4; \
+ } else if (*((str) + 5) == '\0') { \
+ *(outLen) = 5; \
+ } else if (*((str) + 6) == '\0') { \
+ *(outLen) = 6; \
+ } else if (*((str) + 7) == '\0') { \
+ *(outLen) = 7; \
+ } else if (*((str) + 8) == '\0') { \
+ /* Optimization with a length of 8 */ \
+ *(outLen) = 8; \
+ } else { \
+ /* The offset is 8 because the performance of 8 byte alignment is high */ \
+ *(outLen) = 8 + strnlen((str) + 8, (maxLen) - 8); \
+ } \
+ } else { \
+ SECUREC_CALC_STR_LEN((str), (maxLen), (outLen)); \
+ } \
+} SECUREC_WHILE_ZERO
+#else
+#define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \
+ const char *strEnd_ = (const char *)(str); \
+ size_t availableSize_ = (size_t)(maxLen); \
+ while (availableSize_ > 0 && *strEnd_ != '\0') { \
+ --availableSize_; \
+ ++strEnd_; \
+ } \
+ *(outLen) = (size_t)(strEnd_ - (str)); \
+} SECUREC_WHILE_ZERO
+#define SECUREC_CALC_STR_LEN_OPT SECUREC_CALC_STR_LEN
+#endif
+
+#define SECUREC_CALC_WSTR_LEN(str, maxLen, outLen) do { \
+ const wchar_t *strEnd_ = (const wchar_t *)(str); \
+ size_t len_ = 0; \
+ while (len_ < (maxLen) && *strEnd_ != L'\0') { \
+ ++len_; \
+ ++strEnd_; \
+ } \
+ *(outLen) = len_; \
+} SECUREC_WHILE_ZERO
+
+/*
+ * Performance optimization, product may disable inline function.
+ * Using function pointer for MEMSET to prevent compiler optimization when cleaning up memory.
+ */
+#ifdef SECUREC_USE_ASM
+#define SECUREC_MEMSET_FUNC_OPT memset_opt
+#define SECUREC_MEMCPY_FUNC_OPT memcpy_opt
+#else
+#define SECUREC_MEMSET_FUNC_OPT memset
+#define SECUREC_MEMCPY_FUNC_OPT memcpy
+#endif
+
+#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) (void)SECUREC_MEMCPY_FUNC_OPT((dest), (src), (count))
+
+#ifndef SECUREC_MEMSET_INDIRECT_USE
+/* Can be turned off for scenarios that do not allow pointer calls */
+#define SECUREC_MEMSET_INDIRECT_USE 1
+#endif
+
+#if SECUREC_MEMSET_INDIRECT_USE
+#define SECUREC_MEMSET_WARP_OPT(dest, value, count) do { \
+ void *(* const volatile fn_)(void *s_, int c_, size_t n_) = SECUREC_MEMSET_FUNC_OPT; \
+ (void)(*fn_)((dest), (value), (count)); \
+} SECUREC_WHILE_ZERO
+#else
+#define SECUREC_MEMSET_WARP_OPT(dest, value, count) (void)SECUREC_MEMSET_FUNC_OPT((dest), (value), (count))
+#endif
+
+#ifdef SECUREC_FORMAT_OUTPUT_INPUT
+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT) || defined(__ARMCC_VERSION)
+typedef __int64 SecInt64;
+typedef unsigned __int64 SecUnsignedInt64;
+#if defined(__ARMCC_VERSION)
+typedef unsigned int SecUnsignedInt32;
+#else
+typedef unsigned __int32 SecUnsignedInt32;
+#endif
+#else
+typedef unsigned int SecUnsignedInt32;
+typedef long long SecInt64;
+typedef unsigned long long SecUnsignedInt64;
+#endif
+
+#ifdef SECUREC_FOR_WCHAR
+#if defined(SECUREC_VXWORKS_PLATFORM) && !defined(__WINT_TYPE__)
+typedef wchar_t wint_t;
+#endif
+#ifndef WEOF
+#define WEOF ((wchar_t)(-1))
+#endif
+#define SECUREC_CHAR(x) L ## x
+typedef wchar_t SecChar;
+typedef wchar_t SecUnsignedChar;
+typedef wint_t SecInt;
+typedef wint_t SecUnsignedInt;
+#else /* no SECUREC_FOR_WCHAR */
+#define SECUREC_CHAR(x) (x)
+typedef char SecChar;
+typedef unsigned char SecUnsignedChar;
+typedef int SecInt;
+typedef unsigned int SecUnsignedInt;
+#endif
+#endif
+
+/*
+ * Determine whether the address is 8-byte aligned
+ * Some systems do not have uintptr_t type, so use NULL to clear tool alarm 507
+ */
+#define SECUREC_ADDR_ALIGNED_8(addr) ((((size_t)(addr)) & 7U) == 0) /* Use 7 to check aligned 8 */
+
+/*
+ * If you define the memory allocation function, you need to define the function prototype.
+ * You can define this macro as a header file.
+ */
+#if defined(SECUREC_MALLOC_PROTOTYPE)
+SECUREC_MALLOC_PROTOTYPE
+#endif
+
+#ifndef SECUREC_MALLOC
+#define SECUREC_MALLOC(x) malloc((size_t)(x))
+#endif
+
+#ifndef SECUREC_FREE
+#define SECUREC_FREE(x) free((void *)(x))
+#endif
+
+/* Improve performance with struct assignment, buf1 is not defined to avoid tool false positive */
+#define SECUREC_COPY_VALUE_BY_STRUCT(dest, src, n) do { \
+ *(SecStrBuf##n *)(void *)(dest) = *(const SecStrBuf##n *)(const void *)(src); \
+} SECUREC_WHILE_ZERO
+
+typedef struct {
+ unsigned char buf[2]; /* Performance optimization code structure assignment length 2 bytes */
+} SecStrBuf2;
+typedef struct {
+ unsigned char buf[3]; /* Performance optimization code structure assignment length 3 bytes */
+} SecStrBuf3;
+typedef struct {
+ unsigned char buf[4]; /* Performance optimization code structure assignment length 4 bytes */
+} SecStrBuf4;
+typedef struct {
+ unsigned char buf[5]; /* Performance optimization code structure assignment length 5 bytes */
+} SecStrBuf5;
+typedef struct {
+ unsigned char buf[6]; /* Performance optimization code structure assignment length 6 bytes */
+} SecStrBuf6;
+typedef struct {
+ unsigned char buf[7]; /* Performance optimization code structure assignment length 7 bytes */
+} SecStrBuf7;
+typedef struct {
+ unsigned char buf[8]; /* Performance optimization code structure assignment length 8 bytes */
+} SecStrBuf8;
+typedef struct {
+ unsigned char buf[9]; /* Performance optimization code structure assignment length 9 bytes */
+} SecStrBuf9;
+typedef struct {
+ unsigned char buf[10]; /* Performance optimization code structure assignment length 10 bytes */
+} SecStrBuf10;
+typedef struct {
+ unsigned char buf[11]; /* Performance optimization code structure assignment length 11 bytes */
+} SecStrBuf11;
+typedef struct {
+ unsigned char buf[12]; /* Performance optimization code structure assignment length 12 bytes */
+} SecStrBuf12;
+typedef struct {
+ unsigned char buf[13]; /* Performance optimization code structure assignment length 13 bytes */
+} SecStrBuf13;
+typedef struct {
+ unsigned char buf[14]; /* Performance optimization code structure assignment length 14 bytes */
+} SecStrBuf14;
+typedef struct {
+ unsigned char buf[15]; /* Performance optimization code structure assignment length 15 bytes */
+} SecStrBuf15;
+typedef struct {
+ unsigned char buf[16]; /* Performance optimization code structure assignment length 16 bytes */
+} SecStrBuf16;
+typedef struct {
+ unsigned char buf[17]; /* Performance optimization code structure assignment length 17 bytes */
+} SecStrBuf17;
+typedef struct {
+ unsigned char buf[18]; /* Performance optimization code structure assignment length 18 bytes */
+} SecStrBuf18;
+typedef struct {
+ unsigned char buf[19]; /* Performance optimization code structure assignment length 19 bytes */
+} SecStrBuf19;
+typedef struct {
+ unsigned char buf[20]; /* Performance optimization code structure assignment length 20 bytes */
+} SecStrBuf20;
+typedef struct {
+ unsigned char buf[21]; /* Performance optimization code structure assignment length 21 bytes */
+} SecStrBuf21;
+typedef struct {
+ unsigned char buf[22]; /* Performance optimization code structure assignment length 22 bytes */
+} SecStrBuf22;
+typedef struct {
+ unsigned char buf[23]; /* Performance optimization code structure assignment length 23 bytes */
+} SecStrBuf23;
+typedef struct {
+ unsigned char buf[24]; /* Performance optimization code structure assignment length 24 bytes */
+} SecStrBuf24;
+typedef struct {
+ unsigned char buf[25]; /* Performance optimization code structure assignment length 25 bytes */
+} SecStrBuf25;
+typedef struct {
+ unsigned char buf[26]; /* Performance optimization code structure assignment length 26 bytes */
+} SecStrBuf26;
+typedef struct {
+ unsigned char buf[27]; /* Performance optimization code structure assignment length 27 bytes */
+} SecStrBuf27;
+typedef struct {
+ unsigned char buf[28]; /* Performance optimization code structure assignment length 28 bytes */
+} SecStrBuf28;
+typedef struct {
+ unsigned char buf[29]; /* Performance optimization code structure assignment length 29 bytes */
+} SecStrBuf29;
+typedef struct {
+ unsigned char buf[30]; /* Performance optimization code structure assignment length 30 bytes */
+} SecStrBuf30;
+typedef struct {
+ unsigned char buf[31]; /* Performance optimization code structure assignment length 31 bytes */
+} SecStrBuf31;
+typedef struct {
+ unsigned char buf[32]; /* Performance optimization code structure assignment length 32 bytes */
+} SecStrBuf32;
+typedef struct {
+ unsigned char buf[33]; /* Performance optimization code structure assignment length 33 bytes */
+} SecStrBuf33;
+typedef struct {
+ unsigned char buf[34]; /* Performance optimization code structure assignment length 34 bytes */
+} SecStrBuf34;
+typedef struct {
+ unsigned char buf[35]; /* Performance optimization code structure assignment length 35 bytes */
+} SecStrBuf35;
+typedef struct {
+ unsigned char buf[36]; /* Performance optimization code structure assignment length 36 bytes */
+} SecStrBuf36;
+typedef struct {
+ unsigned char buf[37]; /* Performance optimization code structure assignment length 37 bytes */
+} SecStrBuf37;
+typedef struct {
+ unsigned char buf[38]; /* Performance optimization code structure assignment length 38 bytes */
+} SecStrBuf38;
+typedef struct {
+ unsigned char buf[39]; /* Performance optimization code structure assignment length 39 bytes */
+} SecStrBuf39;
+typedef struct {
+ unsigned char buf[40]; /* Performance optimization code structure assignment length 40 bytes */
+} SecStrBuf40;
+typedef struct {
+ unsigned char buf[41]; /* Performance optimization code structure assignment length 41 bytes */
+} SecStrBuf41;
+typedef struct {
+ unsigned char buf[42]; /* Performance optimization code structure assignment length 42 bytes */
+} SecStrBuf42;
+typedef struct {
+ unsigned char buf[43]; /* Performance optimization code structure assignment length 43 bytes */
+} SecStrBuf43;
+typedef struct {
+ unsigned char buf[44]; /* Performance optimization code structure assignment length 44 bytes */
+} SecStrBuf44;
+typedef struct {
+ unsigned char buf[45]; /* Performance optimization code structure assignment length 45 bytes */
+} SecStrBuf45;
+typedef struct {
+ unsigned char buf[46]; /* Performance optimization code structure assignment length 46 bytes */
+} SecStrBuf46;
+typedef struct {
+ unsigned char buf[47]; /* Performance optimization code structure assignment length 47 bytes */
+} SecStrBuf47;
+typedef struct {
+ unsigned char buf[48]; /* Performance optimization code structure assignment length 48 bytes */
+} SecStrBuf48;
+typedef struct {
+ unsigned char buf[49]; /* Performance optimization code structure assignment length 49 bytes */
+} SecStrBuf49;
+typedef struct {
+ unsigned char buf[50]; /* Performance optimization code structure assignment length 50 bytes */
+} SecStrBuf50;
+typedef struct {
+ unsigned char buf[51]; /* Performance optimization code structure assignment length 51 bytes */
+} SecStrBuf51;
+typedef struct {
+ unsigned char buf[52]; /* Performance optimization code structure assignment length 52 bytes */
+} SecStrBuf52;
+typedef struct {
+ unsigned char buf[53]; /* Performance optimization code structure assignment length 53 bytes */
+} SecStrBuf53;
+typedef struct {
+ unsigned char buf[54]; /* Performance optimization code structure assignment length 54 bytes */
+} SecStrBuf54;
+typedef struct {
+ unsigned char buf[55]; /* Performance optimization code structure assignment length 55 bytes */
+} SecStrBuf55;
+typedef struct {
+ unsigned char buf[56]; /* Performance optimization code structure assignment length 56 bytes */
+} SecStrBuf56;
+typedef struct {
+ unsigned char buf[57]; /* Performance optimization code structure assignment length 57 bytes */
+} SecStrBuf57;
+typedef struct {
+ unsigned char buf[58]; /* Performance optimization code structure assignment length 58 bytes */
+} SecStrBuf58;
+typedef struct {
+ unsigned char buf[59]; /* Performance optimization code structure assignment length 59 bytes */
+} SecStrBuf59;
+typedef struct {
+ unsigned char buf[60]; /* Performance optimization code structure assignment length 60 bytes */
+} SecStrBuf60;
+typedef struct {
+ unsigned char buf[61]; /* Performance optimization code structure assignment length 61 bytes */
+} SecStrBuf61;
+typedef struct {
+ unsigned char buf[62]; /* Performance optimization code structure assignment length 62 bytes */
+} SecStrBuf62;
+typedef struct {
+ unsigned char buf[63]; /* Performance optimization code structure assignment length 63 bytes */
+} SecStrBuf63;
+typedef struct {
+ unsigned char buf[64]; /* Performance optimization code structure assignment length 64 bytes */
+} SecStrBuf64;
+
+/*
+ * User can change the error handler by modify the following definition,
+ * such as logging the detail error in file.
+ */
+#if defined(_DEBUG) || defined(DEBUG)
+#if defined(SECUREC_ERROR_HANDLER_BY_ASSERT)
+#define SECUREC_ERROR_INVALID_PARAMTER(msg) assert(msg "invalid argument" == NULL)
+#define SECUREC_ERROR_INVALID_RANGE(msg) assert(msg "invalid dest buffer size" == NULL)
+#define SECUREC_ERROR_BUFFER_OVERLAP(msg) assert(msg "buffer overlap" == NULL)
+#elif defined(SECUREC_ERROR_HANDLER_BY_PRINTF)
+#if SECUREC_IN_KERNEL
+#define SECUREC_ERROR_INVALID_PARAMTER(msg) printk("%s invalid argument\n", msg)
+#define SECUREC_ERROR_INVALID_RANGE(msg) printk("%s invalid dest buffer size\n", msg)
+#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printk("%s buffer overlap\n", msg)
+#else
+#define SECUREC_ERROR_INVALID_PARAMTER(msg) printf("%s invalid argument\n", msg)
+#define SECUREC_ERROR_INVALID_RANGE(msg) printf("%s invalid dest buffer size\n", msg)
+#define SECUREC_ERROR_BUFFER_OVERLAP(msg) printf("%s buffer overlap\n", msg)
+#endif
+#elif defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG)
+#define SECUREC_ERROR_INVALID_PARAMTER(msg) LogSecureCRuntimeError(msg " EINVAL\n")
+#define SECUREC_ERROR_INVALID_RANGE(msg) LogSecureCRuntimeError(msg " ERANGE\n")
+#define SECUREC_ERROR_BUFFER_OVERLAP(msg) LogSecureCRuntimeError(msg " EOVERLAP\n")
+#endif
+#endif
+
+/* Default handler is none */
+#ifndef SECUREC_ERROR_INVALID_PARAMTER
+#define SECUREC_ERROR_INVALID_PARAMTER(msg)
+#endif
+#ifndef SECUREC_ERROR_INVALID_RANGE
+#define SECUREC_ERROR_INVALID_RANGE(msg)
+#endif
+#ifndef SECUREC_ERROR_BUFFER_OVERLAP
+#define SECUREC_ERROR_BUFFER_OVERLAP(msg)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Assembly language memory copy and memory set for X86 or MIPS ... */
+#ifdef SECUREC_USE_ASM
+ void *memcpy_opt(void *dest, const void *src, size_t n);
+ void *memset_opt(void *s, int c, size_t n);
+#endif
+
+#if defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG)
+ void LogSecureCRuntimeError(const char *errDetail);
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/secureinput_a.c b/3rd/gstor/dependency/Huawei_Secure_C/src/secureinput_a.c
new file mode 100644
index 0000000000000000000000000000000000000000..10b7f3571b8fc630e129ad7080c694439e3993d9
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/secureinput_a.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: By defining data type for ANSI string and including "input.inl",
+ * this file generates real underlying function used by scanf family API.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#define SECUREC_FORMAT_OUTPUT_INPUT 1
+#ifdef SECUREC_FOR_WCHAR
+#undef SECUREC_FOR_WCHAR
+#endif
+
+#include "secinput.h"
+
+#include "input.inl"
+
+SECUREC_INLINE int SecIsDigit(SecInt ch)
+{
+ /* SecInt to unsigned char clear 571, use bit mask to clear negative return of ch */
+ return isdigit((int)((unsigned int)(unsigned char)(ch) & 0xffU));
+}
+SECUREC_INLINE int SecIsXdigit(SecInt ch)
+{
+ return isxdigit((int)((unsigned int)(unsigned char)(ch) & 0xffU));
+}
+SECUREC_INLINE int SecIsSpace(SecInt ch)
+{
+ return isspace((int)((unsigned int)(unsigned char)(ch) & 0xffU));
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/secureinput_w.c b/3rd/gstor/dependency/Huawei_Secure_C/src/secureinput_w.c
new file mode 100644
index 0000000000000000000000000000000000000000..79955794edc9b7a1341eab1eeba2855297a48e7f
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/secureinput_w.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: By defining data type for UNICODE string and including "input.inl",
+ * this file generates real underlying function used by scanf family API.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+/* If some platforms don't have wchar.h, dont't include it */
+#if !(defined(SECUREC_VXWORKS_PLATFORM))
+/* If there is no macro below, it will cause vs2010 compiling alarm */
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+#ifndef __STDC_WANT_SECURE_LIB__
+/* The order of adjustment is to eliminate alarm of Duplicate Block */
+#define __STDC_WANT_SECURE_LIB__ 0
+#endif
+#ifndef _CRTIMP_ALTERNATIVE
+#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */
+#endif
+#endif
+#include
+#endif
+
+/* Disable wchar func to clear vs warning */
+#define SECUREC_ENABLE_WCHAR_FUNC 0
+#define SECUREC_FORMAT_OUTPUT_INPUT 1
+
+#ifndef SECUREC_FOR_WCHAR
+#define SECUREC_FOR_WCHAR
+#endif
+
+#include "secinput.h"
+
+#include "input.inl"
+
+SECUREC_INLINE unsigned int SecWcharHighBits(SecInt ch)
+{
+ /* Convert int to unsigned int clear 571 */
+ return ((unsigned int)(int)ch & (~0xffU));
+}
+
+SECUREC_INLINE unsigned char SecWcharLowByte(SecInt ch)
+{
+ /* Convert int to unsigned int clear 571 */
+ return (unsigned char)((unsigned int)(int)ch & 0xffU);
+}
+
+SECUREC_INLINE int SecIsDigit(SecInt ch)
+{
+ if (SecWcharHighBits(ch) != 0) {
+ return 0; /* Same as isdigit */
+ }
+ return isdigit((int)SecWcharLowByte(ch));
+}
+
+SECUREC_INLINE int SecIsXdigit(SecInt ch)
+{
+ if (SecWcharHighBits(ch) != 0) {
+ return 0; /* Same as isxdigit */
+ }
+ return isxdigit((int)SecWcharLowByte(ch));
+}
+
+SECUREC_INLINE int SecIsSpace(SecInt ch)
+{
+ return iswspace((wint_t)(int)(ch));
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/secureprintoutput.h b/3rd/gstor/dependency/Huawei_Secure_C/src/secureprintoutput.h
new file mode 100644
index 0000000000000000000000000000000000000000..843217ae0f7b5304c7fd3efde78e5f909d187051
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/secureprintoutput.h
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: Define macro, enum, data struct, and declare internal used function
+ * prototype, which is used by output.inl, secureprintoutput_w.c and
+ * secureprintoutput_a.c.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef SECUREPRINTOUTPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
+#define SECUREPRINTOUTPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
+#include "securecutil.h"
+
+/*
+ * Flag definitions.
+ * Using macros instead of enumerations is because some of the enumerated types under the compiler are 16bit.
+ */
+#define SECUREC_FLAG_SIGN 0x00001U
+#define SECUREC_FLAG_SIGN_SPACE 0x00002U
+#define SECUREC_FLAG_LEFT 0x00004U
+#define SECUREC_FLAG_LEADZERO 0x00008U
+#define SECUREC_FLAG_LONG 0x00010U
+#define SECUREC_FLAG_SHORT 0x00020U
+#define SECUREC_FLAG_SIGNED 0x00040U
+#define SECUREC_FLAG_ALTERNATE 0x00080U
+#define SECUREC_FLAG_NEGATIVE 0x00100U
+#define SECUREC_FLAG_FORCE_OCTAL 0x00200U
+#define SECUREC_FLAG_LONG_DOUBLE 0x00400U
+#define SECUREC_FLAG_WIDECHAR 0x00800U
+#define SECUREC_FLAG_LONGLONG 0x01000U
+#define SECUREC_FLAG_CHAR 0x02000U
+#define SECUREC_FLAG_POINTER 0x04000U
+#define SECUREC_FLAG_I64 0x08000U
+#define SECUREC_FLAG_PTRDIFF 0x10000U
+#define SECUREC_FLAG_SIZE 0x20000U
+#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
+#define SECUREC_FLAG_INTMAX 0x40000U
+#endif
+
+/* State definitions. Identify the status of the current format */
+typedef enum {
+ STAT_NORMAL,
+ STAT_PERCENT,
+ STAT_FLAG,
+ STAT_WIDTH,
+ STAT_DOT,
+ STAT_PRECIS,
+ STAT_SIZE,
+ STAT_TYPE,
+ STAT_INVALID
+} SecFmtState;
+
+/* Format output buffer pointer and available size */
+typedef struct {
+ int count;
+ char *cur;
+} SecPrintfStream;
+
+#ifndef SECUREC_BUFFER_SIZE
+#if SECUREC_IN_KERNEL
+#define SECUREC_BUFFER_SIZE 32
+#elif defined(SECUREC_STACK_SIZE_LESS_THAN_1K)
+/*
+ * SECUREC BUFFER SIZE Can not be less than 23
+ * The length of the octal representation of 64-bit integers with zero lead
+ */
+#define SECUREC_BUFFER_SIZE 256
+#else
+#define SECUREC_BUFFER_SIZE 512
+#endif
+#endif
+#if SECUREC_BUFFER_SIZE < 23
+#error SECUREC_BUFFER_SIZE Can not be less than 23
+#endif
+/* Buffer size for wchar, use 4 to make the compiler aligns as 8 bytes as possible */
+#define SECUREC_WCHAR_BUFFER_SIZE 4
+
+#define SECUREC_MAX_PRECISION SECUREC_BUFFER_SIZE
+/* Max. # bytes in multibyte char ,see MB_LEN_MAX */
+#define SECUREC_MB_LEN 16
+/* The return value of the internal function, which is returned when truncated */
+#define SECUREC_PRINTF_TRUNCATE (-2)
+
+#define SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, maxLimit) \
+ ((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit))
+
+#define SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, maxLimit) do { \
+ if ((strDest) != NULL && (destMax) > 0 && (destMax) <= (maxLimit)) { \
+ *(strDest) = '\0'; \
+ } \
+} SECUREC_WHILE_ZERO
+
+#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
+#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, maxLimit) \
+ (((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit)) || \
+ ((count) > (SECUREC_STRING_MAX_LEN - 1) && (count) != (size_t)(-1)))
+
+#else
+#define SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, maxLimit) \
+ (((format) == NULL || (strDest) == NULL || (destMax) == 0 || (destMax) > (maxLimit)) || \
+ ((count) > (SECUREC_STRING_MAX_LEN - 1)))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList);
+#ifdef SECUREC_FOR_WCHAR
+ int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/secureprintoutput_a.c b/3rd/gstor/dependency/Huawei_Secure_C/src/secureprintoutput_a.c
new file mode 100644
index 0000000000000000000000000000000000000000..64762c06775b760e278aee850081cf291f3b3255
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/secureprintoutput_a.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: By defining corresponding macro for ANSI string and including "output.inl",
+ * this file generates real underlying function used by printf family API.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#define SECUREC_FORMAT_OUTPUT_INPUT 1
+
+#ifdef SECUREC_FOR_WCHAR
+#undef SECUREC_FOR_WCHAR
+#endif
+
+#include "secureprintoutput.h"
+#if SECUREC_WARP_OUTPUT
+#define SECUREC_FORMAT_FLAG_TABLE_SIZE 128
+SECUREC_INLINE const char *SecSkipKnownFlags(const char *format)
+{
+ static const unsigned char flagTable[SECUREC_FORMAT_FLAG_TABLE_SIZE] = {
+ /*
+ * Known flag is "0123456789 +-#hlLwZzjqt*I$"
+ */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+ const char *fmt = format;
+ while (*fmt != '\0') {
+ char fmtChar = *fmt;
+ if ((unsigned char)fmtChar > 0x7f) { /* 0x7f is upper limit of format char value */
+ break;
+ }
+ if (flagTable[(unsigned char)fmtChar] == 0) {
+ break;
+ }
+ ++fmt;
+ }
+ return fmt;
+}
+
+SECUREC_INLINE int SecFormatContainN(const char *format)
+{
+ const char *fmt = format;
+ while (*fmt != '\0') {
+ ++fmt;
+ /* Skip normal char */
+ if (*(fmt - 1) != '%') {
+ continue;
+ }
+ /* Meet %% */
+ if (*fmt == '%') {
+ ++fmt; /* Point to the character after the %. Correct handling %%xx */
+ continue;
+ }
+ /* Now parse %..., fmt point to the character after the % */
+ fmt = SecSkipKnownFlags(fmt);
+ if (*fmt == 'n') {
+ return 1;
+ }
+ }
+ return 0;
+}
+/*
+ * Multi character formatted output implementation, the count include \0 character, must be greater than zero
+ */
+int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList)
+{
+ int retVal;
+ if (SecFormatContainN(format) != 0) {
+ string[0] = '\0';
+ return -1;
+ }
+ retVal = vsnprintf(string, count, format, argList);
+ if (retVal >= (int)count) { /* The size_t to int is ok, count max is SECUREC_STRING_MAX_LEN */
+ /* The buffer was too small; we return truncation */
+ string[count - 1] = '\0';
+ return SECUREC_PRINTF_TRUNCATE;
+ }
+ if (retVal < 0) {
+ string[0] = '\0'; /* Empty the dest strDest */
+ return -1;
+ }
+ return retVal;
+}
+#else
+#if SECUREC_IN_KERNEL
+#include
+#endif
+
+#ifndef EOF
+#define EOF (-1)
+#endif
+
+#include "output.inl"
+
+/*
+ * Multi character formatted output implementation
+ */
+int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList)
+{
+ SecPrintfStream str;
+ int retVal;
+
+ str.count = (int)count; /* The count include \0 character, must be greater than zero */
+ str.cur = string;
+
+ retVal = SecOutputS(&str, format, argList);
+ if (retVal >= 0) {
+ if (SecPutZeroChar(&str) == 0) {
+ return retVal;
+ }
+ }
+ if (str.count < 0) {
+ /* The buffer was too small, then truncate */
+ string[count - 1] = '\0';
+ return SECUREC_PRINTF_TRUNCATE;
+ }
+ string[0] = '\0'; /* Empty the dest string */
+ return -1;
+}
+
+/*
+ * Write a wide character
+ */
+SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten)
+{
+ int count;
+ for (count = num; count > 0; --count) {
+ --f->count; /* f -> count may be negative,indicating insufficient space */
+ if (f->count < 0) {
+ *pnumwritten = -1;
+ return;
+ }
+ *(f->cur) = ch;
+ ++f->cur;
+ *pnumwritten = *pnumwritten + 1;
+ }
+}
+
+/*
+ * Write string function, where this function is called, make sure that len is greater than 0
+ */
+SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten)
+{
+ const char *str = string;
+ int count;
+ for (count = len; count > 0; --count) {
+ --f->count; /* f -> count may be negative,indicating insufficient space */
+ if (f->count < 0) {
+ *pnumwritten = -1;
+ return;
+ }
+ *(f->cur) = *str;
+ ++f->cur;
+ ++str;
+ }
+ *pnumwritten = *pnumwritten + (int)(size_t)(str - string);
+}
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/secureprintoutput_w.c b/3rd/gstor/dependency/Huawei_Secure_C/src/secureprintoutput_w.c
new file mode 100644
index 0000000000000000000000000000000000000000..4d06a64a37ee4fcf0f4499a4daa260b18af8931a
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/secureprintoutput_w.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: By defining corresponding macro for UNICODE string and including "output.inl",
+ * this file generates real underlying function used by printf family API.
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+/* If some platforms don't have wchar.h, dont't include it */
+#if !(defined(SECUREC_VXWORKS_PLATFORM))
+/* If there is no macro above, it will cause compiling alarm */
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+#ifndef _CRTIMP_ALTERNATIVE
+#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */
+#endif
+#ifndef __STDC_WANT_SECURE_LIB__
+#define __STDC_WANT_SECURE_LIB__ 0
+#endif
+#endif
+#include
+#endif
+
+/* Disable wchar func to clear vs warning */
+#define SECUREC_ENABLE_WCHAR_FUNC 0
+#define SECUREC_FORMAT_OUTPUT_INPUT 1
+
+#ifndef SECUREC_FOR_WCHAR
+#define SECUREC_FOR_WCHAR
+#endif
+
+#if defined(SECUREC_WARP_OUTPUT) && SECUREC_WARP_OUTPUT
+#undef SECUREC_WARP_OUTPUT
+#define SECUREC_WARP_OUTPUT 0
+#endif
+
+#include "secureprintoutput.h"
+
+SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritten);
+SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount);
+
+#include "output.inl"
+
+/*
+ * Wide character formatted output implementation
+ */
+int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList)
+{
+ SecPrintfStream str;
+ int retVal; /* If initialization causes e838 */
+
+ str.cur = (char *)string;
+ /* This count include \0 character, Must be greater than zero */
+ str.count = (int)(sizeInWchar * sizeof(wchar_t));
+
+ retVal = SecOutputSW(&str, format, argList);
+ if (retVal >= 0) {
+ if (SecPutWcharStrEndingZero(&str, (int)sizeof(wchar_t)) == 0) {
+ return retVal;
+ }
+ }
+ if (str.count < 0) {
+ /* The buffer was too small, then truncate */
+ string[sizeInWchar - 1] = L'\0';
+ return SECUREC_PRINTF_TRUNCATE;
+ }
+ string[0] = L'\0'; /* Empty the dest string */
+ return -1;
+}
+
+/*
+ * Output a wide character zero end into the SecPrintfStream structure
+ */
+SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount)
+{
+ int count;
+ for (count = zeroCount; count > 0; --count) {
+ if (SecPutZeroChar(str) != 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Output a wide character into the SecPrintfStream structure
+ */
+SECUREC_INLINE int SecPutCharW(wchar_t ch, SecPrintfStream *f)
+{
+ f->count -= (int)sizeof(wchar_t); /* f -> count may be negative,indicating insufficient space */
+ if (f->count >= 0) {
+ *(wchar_t *)(void *)(f->cur) = ch;
+ f->cur += sizeof(wchar_t);
+ return 0;
+ }
+ return -1;
+}
+
+/*
+ * Output a wide character into the SecPrintfStream structure, returns the number of characters written
+ */
+SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritten)
+{
+ if (SecPutCharW(ch, f) == 0) {
+ *pnumwritten = *pnumwritten + 1;
+ } else {
+ *pnumwritten = -1;
+ }
+}
+
+/*
+ * Output multiple wide character into the SecPrintfStream structure, returns the number of characters written
+ */
+SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten)
+{
+ int count;
+ for (count = num; count > 0; --count) {
+ SecWriteCharW(ch, f, pnumwritten);
+ if (*pnumwritten == -1) {
+ break;
+ }
+ }
+}
+
+/*
+ * Output a wide string into the SecPrintfStream structure, returns the number of characters written
+ */
+SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten)
+{
+ const wchar_t *str = string;
+ int count;
+ for (count = len; count > 0; --count) {
+ SecWriteCharW(*str, f, pnumwritten);
+ ++str;
+ if (*pnumwritten == -1) {
+ break;
+ }
+ }
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/snprintf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/snprintf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..491c0a8d27ab0eeb201a29603801bcd4bf89c851
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/snprintf_s.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: snprintf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securec.h"
+
+#if SECUREC_ENABLE_SNPRINTF
+/*
+ *
+ * The snprintf_s function is equivalent to the snprintf function
+ * except for the parameter destMax/count and the explicit runtime-constraints violation
+ * The snprintf_s function formats and stores count or fewer characters in
+ * strDest and appends a terminating null. Each argument (if any) is converted
+ * and output according to the corresponding format specification in format.
+ * The formatting is consistent with the printf family of functions; If copying
+ * occurs between strings that overlap, the behavior is undefined.
+ *
+ *
+ * strDest Storage location for the output.
+ * destMax The size of the storage location for output. Size
+ * in bytes for snprintf_s or size in words for snwprintf_s.
+ * count Maximum number of character to store.
+ * format Format-control string.
+ * ... Optional arguments.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * return the number of characters written, not including the terminating null
+ * return -1 if an error occurs.
+ * return -1 if count < destMax and the output string has been truncated
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ *
+ */
+int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vsnprintf_s(strDest, destMax, count, format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(snprintf_s);
+#endif
+#endif
+
+#if SECUREC_SNPRINTF_TRUNCATED
+/*
+ *
+ * The snprintf_truncated_s function is equivalent to the snprintf function
+ * except for the parameter destMax/count and the explicit runtime-constraints violation
+ * The snprintf_truncated_s function formats and stores count or fewer characters in
+ * strDest and appends a terminating null. Each argument (if any) is converted
+ * and output according to the corresponding format specification in format.
+ * The formatting is consistent with the printf family of functions; If copying
+ * occurs between strings that overlap, the behavior is undefined.
+ *
+ *
+ * strDest Storage location for the output.
+ * destMax The size of the storage location for output. Size
+ * in bytes for snprintf_truncated_s or size in words for snwprintf_s.
+ * format Format-control string.
+ * ... Optional arguments.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * return the number of characters written, not including the terminating null
+ * return -1 if an error occurs.
+ * return destMax-1 if output string has been truncated
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ *
+ */
+int snprintf_truncated_s(char *strDest, size_t destMax, const char *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vsnprintf_truncated_s(strDest, destMax, format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(snprintf_truncated_s);
+#endif
+
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/sprintf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/sprintf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..95b448586c5c265d7ce9c55d4f1b6bbba249f521
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/sprintf_s.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: sprintf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securec.h"
+
+/*
+ *
+ * The sprintf_s function is equivalent to the sprintf function
+ * except for the parameter destMax and the explicit runtime-constraints violation
+ * The sprintf_s function formats and stores a series of characters and values
+ * in strDest. Each argument (if any) is converted and output according to
+ * the corresponding format specification in format. The format consists of
+ * ordinary characters and has the same form and function as the format argument
+ * for printf. A null character is appended after the last character written.
+ * If copying occurs between strings that overlap, the behavior is undefined.
+ *
+ *
+ * strDest Storage location for output.
+ * destMax Maximum number of characters to store.
+ * format Format-control string.
+ * ... Optional arguments
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * return the number of bytes stored in strDest, not counting the terminating null character.
+ * return -1 if an error occurred.
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+int sprintf_s(char *strDest, size_t destMax, const char *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vsprintf_s(strDest, destMax, format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(sprintf_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/sscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/sscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..ba5680f03329f9dfd4471e76e99baa38b1655088
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/sscanf_s.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: sscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securec.h"
+
+/*
+ *
+ * The sscanf_s function is equivalent to fscanf_s,
+ * except that input is obtained from a string (specified by the argument buffer) rather than from a stream
+ * The sscanf function reads data from buffer into the location given by each
+ * argument. Every argument must be a pointer to a variable with a type that
+ * corresponds to a type specifier in format. The format argument controls the
+ * interpretation of the input fields and has the same form and function as
+ * the format argument for the scanf function.
+ * If copying takes place between strings that overlap, the behavior is undefined.
+ *
+ *
+ * buffer Stored data.
+ * format Format control string, see Format Specifications.
+ * ... Optional arguments.
+ *
+ *
+ * ... The converted value stored in user assigned address
+ *
+ *
+ * Each of these functions returns the number of fields successfully converted
+ * and assigned; the return value does not include fields that were read but
+ * not assigned.
+ * A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int sscanf_s(const char *buffer, const char *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vsscanf_s(buffer, format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(sscanf_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/strcat_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/strcat_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..05c1c3230f6c8375ddfa4e64ad094bae0e1342c4
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/strcat_s.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: strcat_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+/*
+ * Befor this function, the basic parameter checking has been done
+ */
+SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax, const char *strSrc)
+{
+ size_t destLen;
+ size_t srcLen;
+ size_t maxSrcLen;
+ SECUREC_CALC_STR_LEN(strDest, destMax, &destLen);
+ /* Only optimize strSrc, do not apply this function to strDest */
+ maxSrcLen = destMax - destLen;
+ SECUREC_CALC_STR_LEN_OPT(strSrc, maxSrcLen, &srcLen);
+
+ if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) {
+ strDest[0] = '\0';
+ if (strDest + destLen <= strSrc && destLen == destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("strcat_s");
+ return EINVAL_AND_RESET;
+ }
+ SECUREC_ERROR_BUFFER_OVERLAP("strcat_s");
+ return EOVERLAP_AND_RESET;
+ }
+ if (srcLen + destLen >= destMax || strDest == strSrc) {
+ strDest[0] = '\0';
+ if (destLen == destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("strcat_s");
+ return EINVAL_AND_RESET;
+ }
+ SECUREC_ERROR_INVALID_RANGE("strcat_s");
+ return ERANGE_AND_RESET;
+ }
+ SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen + 1); /* Single character length include \0 */
+ return EOK;
+}
+
+/*
+ *
+ * The strcat_s function appends a copy of the string pointed to by strSrc (including the terminating null character)
+ * to the end of the string pointed to by strDest.
+ * The initial character of strSrc overwrites the terminating null character of strDest.
+ * strcat_s will return EOVERLAP_AND_RESET if the source and destination strings overlap.
+ *
+ * Note that the second parameter is the total size of the buffer, not the
+ * remaining size.
+ *
+ *
+ * strDest Null-terminated destination string buffer.
+ * destMax Size of the destination string buffer.
+ * strSrc Null-terminated source string buffer.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * EOK Success
+ * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
+ * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or
+ * (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN)
+ * ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
+ * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc)
+{
+ if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("strcat_s");
+ return ERANGE;
+ }
+ if (strDest == NULL || strSrc == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("strcat_s");
+ if (strDest != NULL) {
+ strDest[0] = '\0';
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+ return SecDoCat(strDest, destMax, strSrc);
+}
+
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(strcat_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/strcpy_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/strcpy_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..e7921eae1b4ff857a81806b5938de414fcdcc672
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/strcpy_s.c
@@ -0,0 +1,349 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: strcpy_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+#ifndef SECUREC_STRCPY_WITH_PERFORMANCE
+#define SECUREC_STRCPY_WITH_PERFORMANCE 1
+#endif
+
+#define SECUREC_STRCPY_PARAM_OK(strDest, destMax, strSrc) ((destMax) > 0 && \
+ (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && (strDest) != (strSrc))
+
+#if (!SECUREC_IN_KERNEL) && SECUREC_STRCPY_WITH_PERFORMANCE
+#ifndef SECUREC_STRCOPY_THRESHOLD_SIZE
+#define SECUREC_STRCOPY_THRESHOLD_SIZE 32UL
+#endif
+/* The purpose of converting to void is to clean up the alarm */
+#define SECUREC_SMALL_STR_COPY(strDest, strSrc, lenWithTerm) do { \
+ if (SECUREC_ADDR_ALIGNED_8(strDest) && SECUREC_ADDR_ALIGNED_8(strSrc)) { \
+ /* Use struct assignment */ \
+ switch (lenWithTerm) { \
+ case 1: \
+ *(strDest) = *(strSrc); \
+ break; \
+ case 2: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 2); \
+ break; \
+ case 3: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 3); \
+ break; \
+ case 4: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 4); \
+ break; \
+ case 5: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 5); \
+ break; \
+ case 6: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 6); \
+ break; \
+ case 7: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 7); \
+ break; \
+ case 8: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 8); \
+ break; \
+ case 9: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 9); \
+ break; \
+ case 10: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 10); \
+ break; \
+ case 11: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 11); \
+ break; \
+ case 12: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 12); \
+ break; \
+ case 13: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 13); \
+ break; \
+ case 14: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 14); \
+ break; \
+ case 15: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 15); \
+ break; \
+ case 16: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 16); \
+ break; \
+ case 17: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 17); \
+ break; \
+ case 18: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 18); \
+ break; \
+ case 19: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 19); \
+ break; \
+ case 20: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 20); \
+ break; \
+ case 21: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 21); \
+ break; \
+ case 22: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 22); \
+ break; \
+ case 23: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 23); \
+ break; \
+ case 24: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 24); \
+ break; \
+ case 25: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 25); \
+ break; \
+ case 26: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 26); \
+ break; \
+ case 27: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 27); \
+ break; \
+ case 28: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 28); \
+ break; \
+ case 29: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 29); \
+ break; \
+ case 30: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 30); \
+ break; \
+ case 31: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 31); \
+ break; \
+ case 32: \
+ SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 32); \
+ break; \
+ default: \
+ /* Do nothing */ \
+ break; \
+ } /* END switch */ \
+ } else { \
+ char *tmpStrDest_ = (char *)(strDest); \
+ const char *tmpStrSrc_ = (const char *)(strSrc); \
+ switch (lenWithTerm) { \
+ case 32: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 31: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 30: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 29: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 28: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 27: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 26: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 25: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 24: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 23: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 22: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 21: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 20: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 19: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 18: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 17: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 16: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 15: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 14: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 13: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 12: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 11: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 10: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 9: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 8: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 7: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 6: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 5: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 4: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 3: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 2: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ case 1: \
+ *(tmpStrDest_++) = *(tmpStrSrc_++); \
+ /* fall-through */ /* FALLTHRU */ \
+ default: \
+ /* Do nothing */ \
+ break; \
+ } \
+ } \
+} SECUREC_WHILE_ZERO
+#endif
+
+#if SECUREC_IN_KERNEL || (!SECUREC_STRCPY_WITH_PERFORMANCE)
+#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm))
+#else
+/*
+ * Performance optimization. lenWithTerm include '\0'
+ */
+#define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) do { \
+ if ((lenWithTerm) > SECUREC_STRCOPY_THRESHOLD_SIZE) { \
+ SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm)); \
+ } else { \
+ SECUREC_SMALL_STR_COPY((dest), (src), (lenWithTerm)); \
+ } \
+} SECUREC_WHILE_ZERO
+#endif
+
+/*
+ * Check Src Range
+ */
+SECUREC_INLINE errno_t CheckSrcRange(char *strDest, size_t destMax, const char *strSrc)
+{
+ size_t tmpDestMax = destMax;
+ const char *tmpSrc = strSrc;
+ /* Use destMax as boundary checker and destMax must be greater than zero */
+ while (*tmpSrc != '\0' && tmpDestMax > 0) {
+ ++tmpSrc;
+ --tmpDestMax;
+ }
+ if (tmpDestMax == 0) {
+ strDest[0] = '\0';
+ SECUREC_ERROR_INVALID_RANGE("strcpy_s");
+ return ERANGE_AND_RESET;
+ }
+ return EOK;
+}
+
+/*
+ * Handling errors
+ */
+errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc)
+{
+ if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("strcpy_s");
+ return ERANGE;
+ }
+ if (strDest == NULL || strSrc == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("strcpy_s");
+ if (strDest != NULL) {
+ strDest[0] = '\0';
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+ return CheckSrcRange(strDest, destMax, strSrc);
+}
+
+/*
+ *
+ * The strcpy_s function copies the string pointed to strSrc
+ * (including the terminating null character) into the array pointed to by strDest
+ * The destination string must be large enough to hold the source string,
+ * including the terminating null character. strcpy_s will return EOVERLAP_AND_RESET
+ * if the source and destination strings overlap.
+ *
+ *
+ * strDest Location of destination string buffer
+ * destMax Size of the destination string buffer.
+ * strSrc Null-terminated source string buffer.
+ *
+ *
+ * strDest is updated.
+ *
+ *
+ * EOK Success
+ * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
+ * EINVAL_AND_RESET strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
+ * ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
+ * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc)
+{
+ if (SECUREC_STRCPY_PARAM_OK(strDest, destMax, strSrc)) {
+ size_t srcStrLen;
+ SECUREC_CALC_STR_LEN(strSrc, destMax, &srcStrLen);
+ ++srcStrLen; /* The length include '\0' */
+
+ if (srcStrLen <= destMax) {
+ /* Use mem overlap check include '\0' */
+ if (SECUREC_MEMORY_NO_OVERLAP(strDest, strSrc, srcStrLen)) {
+ /* Performance optimization srcStrLen include '\0' */
+ SECUREC_STRCPY_OPT(strDest, strSrc, srcStrLen);
+ return EOK;
+ } else {
+ strDest[0] = '\0';
+ SECUREC_ERROR_BUFFER_OVERLAP("strcpy_s");
+ return EOVERLAP_AND_RESET;
+ }
+ }
+ }
+ return strcpy_error(strDest, destMax, strSrc);
+}
+
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(strcpy_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/strncat_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/strncat_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..3baf9bf242e3fdc279adf34540b82d6b519763e1
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/strncat_s.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: strncat_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+/*
+ * Befor this function, the basic parameter checking has been done
+ */
+SECUREC_INLINE errno_t SecDoCatLimit(char *strDest, size_t destMax, const char *strSrc, size_t count)
+{
+ size_t destLen;
+ size_t srcLen;
+ SECUREC_CALC_STR_LEN(strDest, destMax, &destLen);
+ /*
+ * The strSrc is no longer optimized. The reason is that when count is small,
+ * the efficiency of strnlen is higher than that of self realization.
+ */
+ SECUREC_CALC_STR_LEN(strSrc, count, &srcLen);
+
+ if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) {
+ strDest[0] = '\0';
+ if (strDest + destLen <= strSrc && destLen == destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("strncat_s");
+ return EINVAL_AND_RESET;
+ }
+ SECUREC_ERROR_BUFFER_OVERLAP("strncat_s");
+ return EOVERLAP_AND_RESET;
+ }
+ if (srcLen + destLen >= destMax || strDest == strSrc) {
+ strDest[0] = '\0';
+ if (destLen == destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("strncat_s");
+ return EINVAL_AND_RESET;
+ }
+ SECUREC_ERROR_INVALID_RANGE("strncat_s");
+ return ERANGE_AND_RESET;
+ }
+ SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen); /* No terminator */
+ *(strDest + destLen + srcLen) = '\0';
+ return EOK;
+}
+
+/*
+ *
+ * The strncat_s function appends not more than n successive characters
+ * (not including the terminating null character)
+ * from the array pointed to by strSrc to the end of the string pointed to by strDest
+ * The strncat_s function try to append the first D characters of strSrc to
+ * the end of strDest, where D is the lesser of count and the length of strSrc.
+ * If appending those D characters will fit within strDest (whose size is given
+ * as destMax) and still leave room for a null terminator, then those characters
+ * are appended, starting at the original terminating null of strDest, and a
+ * new terminating null is appended; otherwise, strDest[0] is set to the null
+ * character.
+ *
+ *
+ * strDest Null-terminated destination string.
+ * destMax Size of the destination buffer.
+ * strSrc Null-terminated source string.
+ * count Number of character to append, or truncate.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * EOK Success
+ * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
+ * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid)or
+ * (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN)
+ * ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
+ * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count)
+{
+ if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("strncat_s");
+ return ERANGE;
+ }
+
+ if (strDest == NULL || strSrc == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("strncat_s");
+ if (strDest != NULL) {
+ strDest[0] = '\0';
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+ if (count > SECUREC_STRING_MAX_LEN) {
+#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
+ if (count == (size_t)(-1)) {
+ /* Windows internal functions may pass in -1 when calling this function */
+ return SecDoCatLimit(strDest, destMax, strSrc, destMax);
+ }
+#endif
+ strDest[0] = '\0';
+ SECUREC_ERROR_INVALID_RANGE("strncat_s");
+ return ERANGE_AND_RESET;
+ }
+ return SecDoCatLimit(strDest, destMax, strSrc, count);
+}
+
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(strncat_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/strncpy_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/strncpy_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..5bbf0814563f12d84aa42307b1bb7933f14b1248
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/strncpy_s.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: strncpy_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
+#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \
+ (((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && \
+ ((count) <= SECUREC_STRING_MAX_LEN || (count) == ((size_t)(-1))) && (count) > 0))
+#else
+#define SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count) \
+ (((destMax) > 0 && (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && \
+ (count) <= SECUREC_STRING_MAX_LEN && (count) > 0))
+#endif
+
+/*
+ * Check Src Count Range
+ */
+SECUREC_INLINE errno_t CheckSrcCountRange(char *strDest, size_t destMax, const char *strSrc, size_t count)
+{
+ size_t tmpDestMax = destMax;
+ size_t tmpCount = count;
+ const char *endPos = strSrc;
+
+ /* Use destMax and count as boundary checker and destMax must be greater than zero */
+ while (*(endPos) != '\0' && tmpDestMax > 0 && tmpCount > 0) {
+ ++endPos;
+ --tmpCount;
+ --tmpDestMax;
+ }
+ if (tmpDestMax == 0) {
+ strDest[0] = '\0';
+ SECUREC_ERROR_INVALID_RANGE("strncpy_s");
+ return ERANGE_AND_RESET;
+ }
+ return EOK;
+}
+
+/*
+ * Handling errors, when dest euqal src return EOK
+ */
+errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count)
+{
+ if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("strncpy_s");
+ return ERANGE;
+ }
+ if (strDest == NULL || strSrc == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("strncpy_s");
+ if (strDest != NULL) {
+ strDest[0] = '\0';
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+ if (count > SECUREC_STRING_MAX_LEN) {
+ strDest[0] = '\0'; /* Clear dest string */
+ SECUREC_ERROR_INVALID_RANGE("strncpy_s");
+ return ERANGE_AND_RESET;
+ }
+ if (count == 0) {
+ strDest[0] = '\0';
+ return EOK;
+ }
+ return CheckSrcCountRange(strDest, destMax, strSrc, count);
+}
+
+/*
+ *
+ * The strncpy_s function copies not more than n successive characters (not including the terminating null character)
+ * from the array pointed to by strSrc to the array pointed to by strDest.
+ *
+ *
+ * strDest Destination string.
+ * destMax The size of the destination string, in characters.
+ * strSrc Source string.
+ * count Number of characters to be copied.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * EOK Success
+ * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
+ * EINVAL_AND_RESET strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN
+ * ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN
+ * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count)
+{
+ if (SECUREC_STRNCPY_PARAM_OK(strDest, destMax, strSrc, count)) {
+ size_t minCpLen; /* Use it to store the maxi length limit */
+ if (count < destMax) {
+ SECUREC_CALC_STR_LEN(strSrc, count, &minCpLen); /* No ending terminator */
+ } else {
+ size_t tmpCount = destMax;
+#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
+ if (count == ((size_t)(-1))) {
+ tmpCount = destMax - 1;
+ }
+#endif
+ SECUREC_CALC_STR_LEN(strSrc, tmpCount, &minCpLen); /* No ending terminator */
+ if (minCpLen == destMax) {
+ strDest[0] = '\0';
+ SECUREC_ERROR_INVALID_RANGE("strncpy_s");
+ return ERANGE_AND_RESET;
+ }
+ }
+ if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, minCpLen) || strDest == strSrc) {
+ /* Not overlap */
+ SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, minCpLen); /* Copy string without terminator */
+ strDest[minCpLen] = '\0';
+ return EOK;
+ } else {
+ strDest[0] = '\0';
+ SECUREC_ERROR_BUFFER_OVERLAP("strncpy_s");
+ return EOVERLAP_AND_RESET;
+ }
+ }
+ return strncpy_error(strDest, destMax, strSrc, count);
+}
+
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(strncpy_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/strtok_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/strtok_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..b04793bcf667fc6687ead42a7d744cbd80e222d4
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/strtok_s.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: strtok_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+SECUREC_INLINE int SecIsInDelimit(char ch, const char *strDelimit)
+{
+ const char *ctl = strDelimit;
+ while (*ctl != '\0' && *ctl != ch) {
+ ++ctl;
+ }
+ return (int)(*ctl != '\0');
+}
+
+/*
+ * Find beginning of token (skip over leading delimiters).
+ * Note that there is no token if this loop sets string to point to the terminal null.
+ */
+SECUREC_INLINE char *SecFindBegin(char *strToken, const char *strDelimit)
+{
+ char *token = strToken;
+ while (*token != '\0') {
+ if (SecIsInDelimit(*token, strDelimit) != 0) {
+ ++token;
+ continue;
+ }
+ /* Don't find any delimiter in string header, break the loop */
+ break;
+ }
+ return token;
+}
+
+/*
+ * Find rest of token
+ */
+SECUREC_INLINE char *SecFindRest(char *strToken, const char *strDelimit)
+{
+ /* Find the rest of the token. If it is not the end of the string, put a null there */
+ char *token = strToken;
+ while (*token != '\0') {
+ if (SecIsInDelimit(*token, strDelimit) != 0) {
+ /* Find a delimiter, set string termintor */
+ *token = '\0';
+ ++token;
+ break;
+ }
+ ++token;
+ }
+ return token;
+}
+
+/*
+ * Find the final position pointer
+ */
+SECUREC_INLINE char *SecUpdateToken(char *strToken, const char *strDelimit, char **context)
+{
+ /* Point to updated position. Record string position for next search in the context */
+ *context = SecFindRest(strToken, strDelimit);
+ /* Determine if a token has been found. */
+ if (*context == strToken) {
+ return NULL;
+ }
+ return strToken;
+}
+
+/*
+ *
+ * The strtok_s function parses a string into a sequence of strToken,
+ * replace all characters in strToken string that match to strDelimit set with 0.
+ * On the first call to strtok_s the string to be parsed should be specified in strToken.
+ * In each subsequent call that should parse the same string, strToken should be NULL
+ *
+ * strToken String containing token or tokens.
+ * strDelimit Set of delimiter characters.
+ * context Used to store position information between calls
+ * to strtok_s
+ *
+ * context is updated
+ *
+ * On the first call returns the address of the first non \0 character, otherwise NULL is returned.
+ * In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
+ * return NULL if the *context string length is equal 0, otherwise return *context.
+ */
+char *strtok_s(char *strToken, const char *strDelimit, char **context)
+{
+ char *orgToken = strToken;
+ /* Validate delimiter and string context */
+ if (context == NULL || strDelimit == NULL) {
+ return NULL;
+ }
+ /* Valid input string and string pointer from where to search */
+ if (orgToken == NULL && *context == NULL) {
+ return NULL;
+ }
+ /* If string is null, continue searching from previous string position stored in context */
+ if (orgToken == NULL) {
+ orgToken = *context;
+ }
+ orgToken = SecFindBegin(orgToken, strDelimit);
+ return SecUpdateToken(orgToken, strDelimit, context);
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(strtok_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/swprintf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/swprintf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..2d2ad42b19d3ce766277d4ee1f51561c7bbe861f
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/swprintf_s.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: swprintf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securec.h"
+
+/*
+ *
+ * The swprintf_s function is the wide-character equivalent of the sprintf_s function
+ *
+ *
+ * strDest Storage location for the output.
+ * destMax Maximum number of characters to store.
+ * format Format-control string.
+ * ... Optional arguments
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * return the number of wide characters stored in strDest, not counting the terminating null wide character.
+ * return -1 if an error occurred.
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vswprintf_s(strDest, destMax, format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/swscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/swscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..987b6893d66ebd7db2f84d06902b16f138cb07ce
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/swscanf_s.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: swscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securec.h"
+
+/*
+ *
+ * The swscanf_s function is the wide-character equivalent of the sscanf_s function
+ * The swscanf_s function reads data from buffer into the location given by
+ * each argument. Every argument must be a pointer to a variable with a type
+ * that corresponds to a type specifier in format. The format argument controls
+ * the interpretation of the input fields and has the same form and function
+ * as the format argument for the scanf function. If copying takes place between
+ * strings that overlap, the behavior is undefined.
+ *
+ *
+ * buffer Stored data.
+ * format Format control string, see Format Specifications.
+ * ... Optional arguments.
+ *
+ *
+ * ... the converted value stored in user assigned address
+ *
+ *
+ * Each of these functions returns the number of fields successfully converted
+ * and assigned; The return value does not include fields that were read but not
+ * assigned.
+ * A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vswscanf_s(buffer, format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/vfscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/vfscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..96aee67fa9b0b8ab8de3353bebc48aff6725c462
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/vfscanf_s.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: vfscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "secinput.h"
+
+/*
+ *
+ * The vfscanf_s function is equivalent to fscanf_s, with the variable argument list replaced by argList
+ * The vfscanf_s function reads data from the current position of stream into
+ * the locations given by argument (if any). Each argument must be a pointer
+ * to a variable of a type that corresponds to a type specifier in format.
+ * format controls the interpretation of the input fields and has the same
+ * form and function as the format argument for scanf.
+ *
+ *
+ * stream Pointer to FILE structure.
+ * format Format control string, see Format Specifications.
+ * argList pointer to list of arguments
+ *
+ *
+ * argList the converted value stored in user assigned address
+ *
+ *
+ * Each of these functions returns the number of fields successfully converted
+ * and assigned; the return value does not include fields that were read but
+ * not assigned. A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int vfscanf_s(FILE *stream, const char *format, va_list argList)
+{
+ int retVal; /* If initialization causes e838 */
+ SecFileStream fStr;
+
+ if (stream == NULL || format == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+ if (stream == SECUREC_STREAM_STDIN) {
+ return vscanf_s(format, argList);
+ }
+
+ SECUREC_LOCK_FILE(stream);
+ SECUREC_FILE_STREAM_FROM_FILE(&fStr, stream);
+ retVal = SecInputS(&fStr, format, argList);
+ SECUREC_UNLOCK_FILE(stream);
+ if (retVal < 0) {
+ SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+
+ return retVal;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/vfwscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/vfwscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..0fd0c350cd3ecb825191e2066ce83c51b9c1aae2
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/vfwscanf_s.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: vfwscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef SECUREC_FOR_WCHAR
+#define SECUREC_FOR_WCHAR
+#endif
+
+#include "secinput.h"
+
+/*
+ *
+ * The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
+ * The vfwscanf_s function reads data from the current position of stream into
+ * the locations given by argument (if any). Each argument must be a pointer
+ * to a variable of a type that corresponds to a type specifier in format.
+ * format controls the interpretation of the input fields and has the same form
+ * and function as the format argument for scanf.
+ *
+ *
+ * stream Pointer to FILE structure.
+ * format Format control string, see Format Specifications.
+ * argList pointer to list of arguments
+ *
+ *
+ * argList the converted value stored in user assigned address
+ *
+ *
+ * Each of these functions returns the number of fields successfully converted
+ * and assigned; the return value does not include fields that were read but
+ * not assigned. A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList)
+{
+ int retVal; /* If initialization causes e838 */
+ SecFileStream fStr;
+
+ if (stream == NULL || format == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+ if (stream == SECUREC_STREAM_STDIN) {
+ return vwscanf_s(format, argList);
+ }
+
+ SECUREC_LOCK_FILE(stream);
+ SECUREC_FILE_STREAM_FROM_FILE(&fStr, stream);
+ retVal = SecInputSW(&fStr, format, argList);
+ SECUREC_UNLOCK_FILE(stream);
+ if (retVal < 0) {
+ SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+ return retVal;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/vscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/vscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..23edffe13777deaa59619c468306f208e9b42fd1
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/vscanf_s.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: vscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "secinput.h"
+
+/*
+ *
+ * The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList,
+ * The vscanf_s function reads data from the standard input stream stdin and
+ * writes the data into the location that's given by argument. Each argument
+ * must be a pointer to a variable of a type that corresponds to a type specifier
+ * in format. If copying occurs between strings that overlap, the behavior is
+ * undefined.
+ *
+ *
+ * format Format control string.
+ * argList pointer to list of arguments
+ *
+ *
+ * argList the converted value stored in user assigned address
+ *
+ *
+ * Returns the number of fields successfully converted and assigned;
+ * the return value does not include fields that were read but not assigned.
+ * A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int vscanf_s(const char *format, va_list argList)
+{
+ int retVal; /* If initialization causes e838 */
+ SecFileStream fStr;
+ SECUREC_FILE_STREAM_FROM_STDIN(&fStr);
+ /*
+ * The "va_list" has different definition on different platform, so we can't use argList == NULL
+ * To determine it's invalid. If you has fixed platform, you can check some fields to validate it,
+ * such as "argList == NULL" or argList.xxx != NULL or *(size_t *)&argList != 0.
+ */
+ if (format == NULL || fStr.pf == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("vscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+
+ SECUREC_LOCK_STDIN(0, fStr.pf);
+ retVal = SecInputS(&fStr, format, argList);
+ SECUREC_UNLOCK_STDIN(0, fStr.pf);
+ if (retVal < 0) {
+ SECUREC_ERROR_INVALID_PARAMTER("vscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+ return retVal;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/vsnprintf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/vsnprintf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..36619d87afac42ba914ce2475f68a2cfbcb5c980
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/vsnprintf_s.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: vsnprintf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "secureprintoutput.h"
+
+#if SECUREC_ENABLE_VSNPRINTF
+/*
+ *
+ * The vsnprintf_s function is equivalent to the vsnprintf function
+ * except for the parameter destMax/count and the explicit runtime-constraints violation
+ * The vsnprintf_s function takes a pointer to an argument list, then formats
+ * and writes up to count characters of the given data to the memory pointed
+ * to by strDest and appends a terminating null.
+ *
+ *
+ * strDest Storage location for the output.
+ * destMax The size of the strDest for output.
+ * count Maximum number of character to write(not including
+ * the terminating NULL)
+ * format Format-control string.
+ * argList pointer to list of arguments.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * return the number of characters written, not including the terminating null
+ * return -1 if an error occurs.
+ * return -1 if count < destMax and the output string has been truncated
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, va_list argList)
+{
+ int retVal;
+
+ if (SECUREC_VSNPRINTF_PARAM_ERROR(format, strDest, destMax, count, SECUREC_STRING_MAX_LEN)) {
+ SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN);
+ SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s");
+ return -1;
+ }
+
+ if (destMax > count) {
+ retVal = SecVsnprintfImpl(strDest, count + 1, format, argList);
+ if (retVal == SECUREC_PRINTF_TRUNCATE) { /* To keep dest buffer not destroyed 2014.2.18 */
+ /* The string has been truncated, return -1 */
+ return -1; /* To skip error handler, return strlen(strDest) or -1 */
+ }
+ } else {
+ retVal = SecVsnprintfImpl(strDest, destMax, format, argList);
+#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
+ if (retVal == SECUREC_PRINTF_TRUNCATE && count == (size_t)(-1)) {
+ return -1;
+ }
+#endif
+ }
+
+ if (retVal < 0) {
+ strDest[0] = '\0'; /* Empty the dest strDest */
+ if (retVal == SECUREC_PRINTF_TRUNCATE) {
+ /* Buffer too small */
+ SECUREC_ERROR_INVALID_RANGE("vsnprintf_s");
+ }
+ SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s");
+ return -1;
+ }
+
+ return retVal;
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(vsnprintf_s);
+#endif
+#endif
+
+#if SECUREC_SNPRINTF_TRUNCATED
+/*
+ *
+ * The vsnprintf_truncated_s function is equivalent to the vsnprintf function
+ * except for the parameter destMax/count and the explicit runtime-constraints violation
+ * The vsnprintf_truncated_s function takes a pointer to an argument list, then formats
+ * and writes up to count characters of the given data to the memory pointed
+ * to by strDest and appends a terminating null.
+ *
+ *
+ * strDest Storage location for the output.
+ * destMax The size of the strDest for output.
+ * the terminating NULL)
+ * format Format-control string.
+ * argList pointer to list of arguments.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * return the number of characters written, not including the terminating null
+ * return -1 if an error occurs.
+ * return destMax-1 if output string has been truncated
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, va_list argList)
+{
+ int retVal;
+
+ if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_STRING_MAX_LEN)) {
+ SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN);
+ SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s");
+ return -1;
+ }
+
+ retVal = SecVsnprintfImpl(strDest, destMax, format, argList);
+ if (retVal < 0) {
+ if (retVal == SECUREC_PRINTF_TRUNCATE) {
+ return (int)(destMax - 1); /* To skip error handler, return strlen(strDest) */
+ }
+ strDest[0] = '\0'; /* Empty the dest strDest */
+ SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_truncated_s");
+ return -1;
+ }
+
+ return retVal;
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(vsnprintf_truncated_s);
+#endif
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/vsprintf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/vsprintf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..012f522c4987d99a448a5f4b6a157a5d3a271e9f
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/vsprintf_s.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: vsprintf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "secureprintoutput.h"
+
+/*
+ *
+ * The vsprintf_s function is equivalent to the vsprintf function
+ * except for the parameter destMax and the explicit runtime-constraints violation
+ * The vsprintf_s function takes a pointer to an argument list, and then formats
+ * and writes the given data to the memory pointed to by strDest.
+ * The function differ from the non-secure versions only in that the secure
+ * versions support positional parameters.
+ *
+ *
+ * strDest Storage location for the output.
+ * destMax Size of strDest
+ * format Format specification.
+ * argList pointer to list of arguments
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * return the number of characters written, not including the terminating null character,
+ * return -1 if an error occurs.
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+int vsprintf_s(char *strDest, size_t destMax, const char *format, va_list argList)
+{
+ int retVal; /* If initialization causes e838 */
+
+ if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_STRING_MAX_LEN)) {
+ SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_STRING_MAX_LEN);
+ SECUREC_ERROR_INVALID_PARAMTER("vsprintf_s");
+ return -1;
+ }
+
+ retVal = SecVsnprintfImpl(strDest, destMax, format, argList);
+ if (retVal < 0) {
+ strDest[0] = '\0';
+ if (retVal == SECUREC_PRINTF_TRUNCATE) {
+ /* Buffer is too small */
+ SECUREC_ERROR_INVALID_RANGE("vsprintf_s");
+ }
+ SECUREC_ERROR_INVALID_PARAMTER("vsprintf_s");
+ return -1;
+ }
+
+ return retVal;
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(vsprintf_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/vsscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/vsscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..6612d2fa0098cdb7db2162b48f85674d4ab0c5d1
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/vsscanf_s.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: vsscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "secinput.h"
+#if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL && \
+ (!defined(SECUREC_SYSAPI4VXWORKS) && !defined(SECUREC_CTYPE_MACRO_ADAPT))
+#include
+#endif
+
+/*
+ *
+ * vsscanf_s
+ *
+ *
+ *
+ * The vsscanf_s function is equivalent to sscanf_s, with the variable argument list replaced by argList
+ * The vsscanf_s function reads data from buffer into the location given by
+ * each argument. Every argument must be a pointer to a variable with a type
+ * that corresponds to a type specifier in format. The format argument controls
+ * the interpretation of the input fields and has the same form and function
+ * as the format argument for the scanf function.
+ * If copying takes place between strings that overlap, the behavior is undefined.
+ *
+ *
+ * buffer Stored data
+ * format Format control string, see Format Specifications.
+ * argList pointer to list of arguments
+ *
+ *
+ * argList the converted value stored in user assigned address
+ *
+ *
+ * Each of these functions returns the number of fields successfully converted
+ * and assigned; the return value does not include fields that were read but
+ * not assigned. A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int vsscanf_s(const char *buffer, const char *format, va_list argList)
+{
+ size_t count; /* If initialization causes e838 */
+ int retVal;
+ SecFileStream fStr;
+
+ /* Validation section */
+ if (buffer == NULL || format == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+ count = strlen(buffer);
+ if (count == 0 || count > SECUREC_STRING_MAX_LEN) {
+ SecClearDestBuf(buffer, format, argList);
+ SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+#if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL
+ /*
+ * On vxworks platform when buffer is white string, will set first %s argument tu zero.like following useage:
+ * " \v\f\t\r\n", "%s", str, strSize
+ * Do not check all character, just first and last character then consider it is white string
+ */
+ if (isspace((int)(unsigned char)buffer[0]) != 0 && isspace((int)(unsigned char)buffer[count - 1]) != 0) {
+ SecClearDestBuf(buffer, format, argList);
+ }
+#endif
+ SECUREC_FILE_STREAM_FROM_STRING(&fStr, buffer, count);
+ retVal = SecInputS(&fStr, format, argList);
+ if (retVal < 0) {
+ SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+ return retVal;
+}
+#if SECUREC_IN_KERNEL
+EXPORT_SYMBOL(vsscanf_s);
+#endif
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/vswprintf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/vswprintf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..38b0b4045fd49e2788607ad984e399a74586eb8d
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/vswprintf_s.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: vswprintf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef SECUREC_FOR_WCHAR
+#define SECUREC_FOR_WCHAR
+#endif
+
+#include "secureprintoutput.h"
+
+/*
+ *
+ * The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
+ *
+ *
+ * strDest Storage location for the output.
+ * destMax Maximum number of characters to store
+ * format Format specification.
+ * argList pointer to list of arguments
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * return the number of wide characters stored in strDest, not counting the terminating null wide character.
+ * return -1 if an error occurred.
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList)
+{
+ int retVal; /* If initialization causes e838 */
+ if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN)) {
+ SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN);
+ SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
+ return -1;
+ }
+
+ retVal = SecVswprintfImpl(strDest, destMax, format, argList);
+ if (retVal < 0) {
+ strDest[0] = L'\0';
+ if (retVal == SECUREC_PRINTF_TRUNCATE) {
+ /* Buffer too small */
+ SECUREC_ERROR_INVALID_RANGE("vswprintf_s");
+ }
+ SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
+ return -1;
+ }
+
+ return retVal;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/vswscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/vswscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..d416b96c7f4f440524aa6eb8517803775aba75cc
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/vswscanf_s.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: vswscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef SECUREC_FOR_WCHAR
+#define SECUREC_FOR_WCHAR
+#endif
+
+#include "secinput.h"
+
+SECUREC_INLINE size_t SecWcslen(const wchar_t *s)
+{
+ const wchar_t *end = s;
+ while (*end != L'\0') {
+ ++end;
+ }
+ return ((size_t)((end - s)));
+}
+
+/*
+ *
+ * The vswscanf_s function is the wide-character equivalent of the vsscanf_s function
+ * The vsscanf_s function reads data from buffer into the location given by
+ * each argument. Every argument must be a pointer to a variable with a type
+ * that corresponds to a type specifier in format.
+ * The format argument controls the interpretation of the input fields and
+ * has the same form and function as the format argument for the scanf function.
+ * If copying takes place between strings that overlap, the behavior is undefined.
+ *
+ *
+ * buffer Stored data
+ * format Format control string, see Format Specifications.
+ * argList pointer to list of arguments
+ *
+ *
+ * argList the converted value stored in user assigned address
+ *
+ *
+ * Each of these functions returns the number of fields successfully converted
+ * and assigned; the return value does not include fields that were read but
+ * not assigned. A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList)
+{
+ size_t count; /* If initialization causes e838 */
+ SecFileStream fStr;
+ int retVal;
+
+ /* Validation section */
+ if (buffer == NULL || format == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+ count = SecWcslen(buffer);
+ if (count == 0 || count > SECUREC_WCHAR_STRING_MAX_LEN) {
+ SecClearDestBufW(buffer, format, argList);
+ SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+ SECUREC_FILE_STREAM_FROM_STRING(&fStr, (const char *)buffer, count * sizeof(wchar_t));
+ retVal = SecInputSW(&fStr, format, argList);
+ if (retVal < 0) {
+ SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+ return retVal;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/vwscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/vwscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..90f49a1c332562434bb43cf1fe68c551ca046807
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/vwscanf_s.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: vwscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#ifndef SECUREC_FOR_WCHAR
+#define SECUREC_FOR_WCHAR
+#endif
+
+#include "secinput.h"
+
+/*
+ *
+ * The vwscanf_s function is the wide-character equivalent of the vscanf_s function
+ * The vwscanf_s function is the wide-character version of vscanf_s. The
+ * function reads data from the standard input stream stdin and writes the
+ * data into the location that's given by argument. Each argument must be a
+ * pointer to a variable of a type that corresponds to a type specifier in
+ * format. If copying occurs between strings that overlap, the behavior is
+ * undefined.
+ *
+ *
+ * format Format control string.
+ * argList pointer to list of arguments
+ *
+ *
+ * argList the converted value stored in user assigned address
+ *
+ *
+ * Returns the number of fields successfully converted and assigned;
+ * the return value does not include fields that were read but not assigned.
+ * A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int vwscanf_s(const wchar_t *format, va_list argList)
+{
+ int retVal; /* If initialization causes e838 */
+ SecFileStream fStr;
+ SECUREC_FILE_STREAM_FROM_STDIN(&fStr);
+ if (format == NULL || fStr.pf == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+
+ SECUREC_LOCK_STDIN(0, fStr.pf);
+ retVal = SecInputSW(&fStr, format, argList);
+ SECUREC_UNLOCK_STDIN(0, fStr.pf);
+ if (retVal < 0) {
+ SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
+ return SECUREC_SCANF_EINVAL;
+ }
+
+ return retVal;
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/wcscat_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/wcscat_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..780907bf3d85a0e1fbf74b535e0bc761ba2dce4c
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/wcscat_s.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: wcscat_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+/*
+ * Befor this function, the basic parameter checking has been done
+ */
+SECUREC_INLINE errno_t SecDoCatW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
+{
+ size_t destLen;
+ size_t srcLen;
+ size_t maxCount; /* Store the maximum available count */
+
+ /* To calculate the length of a wide character, the parameter must be a wide character */
+ SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen);
+ maxCount = destMax - destLen;
+ SECUREC_CALC_WSTR_LEN(strSrc, maxCount, &srcLen);
+
+ if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) {
+ strDest[0] = L'\0';
+ if (strDest + destLen <= strSrc && destLen == destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("wcscat_s");
+ return EINVAL_AND_RESET;
+ }
+ SECUREC_ERROR_BUFFER_OVERLAP("wcscat_s");
+ return EOVERLAP_AND_RESET;
+ }
+ if (srcLen + destLen >= destMax || strDest == strSrc) {
+ strDest[0] = L'\0';
+ if (destLen == destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("wcscat_s");
+ return EINVAL_AND_RESET;
+ }
+ SECUREC_ERROR_INVALID_RANGE("wcscat_s");
+ return ERANGE_AND_RESET;
+ }
+ /* Copy single character length include \0 */
+ SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, (srcLen + 1) * sizeof(wchar_t));
+ return EOK;
+}
+
+/*
+ *
+ * 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.
+ * The arguments and return value of wcscat_s are wide-character strings.
+ *
+ * The wcscat_s function appends strSrc to strDest and terminates the resulting
+ * string with a null character. The initial character of strSrc overwrites the
+ * terminating null character of strDest. wcscat_s will return EOVERLAP_AND_RESET if the
+ * source and destination strings overlap.
+ *
+ * Note that the second parameter is the total size of the buffer, not the
+ * remaining size.
+ *
+ *
+ * strDest Null-terminated destination string buffer.
+ * destMax Size of the destination string buffer.
+ * strSrc Null-terminated source string buffer.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * EOK Success
+ * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
+ * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or
+ * (strDest != NULL and strSrc is NULLL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN)
+ * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
+ * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
+{
+ if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("wcscat_s");
+ return ERANGE;
+ }
+
+ if (strDest == NULL || strSrc == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("wcscat_s");
+ if (strDest != NULL) {
+ strDest[0] = L'\0';
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+
+ return SecDoCatW(strDest, destMax, strSrc);
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/wcscpy_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/wcscpy_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..89c281df6bf5f58a4596725787462e8559ce76c0
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/wcscpy_s.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: wcscpy_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
+{
+ size_t srcStrLen;
+ SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen);
+
+ if (srcStrLen == destMax) {
+ strDest[0] = L'\0';
+ SECUREC_ERROR_INVALID_RANGE("wcscpy_s");
+ return ERANGE_AND_RESET;
+ }
+ if (strDest == strSrc) {
+ return EOK;
+ }
+
+ if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, srcStrLen)) {
+ /* Performance optimization, srcStrLen is single character length include '\0' */
+ SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, (srcStrLen + 1) * sizeof(wchar_t));
+ return EOK;
+ } else {
+ strDest[0] = L'\0';
+ SECUREC_ERROR_BUFFER_OVERLAP("wcscpy_s");
+ return EOVERLAP_AND_RESET;
+ }
+}
+
+/*
+ *
+ * The wcscpy_s function copies the wide string pointed to by strSrc
+ * (including theterminating null wide character) into the array pointed to by strDest
+
+ *
+ * strDest Destination string buffer
+ * destMax Size of the destination string buffer.
+ * strSrc Null-terminated source string buffer.
+ *
+ *
+ * strDest is updated.
+ *
+ *
+ * EOK Success
+ * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
+ * EINVAL_AND_RESET strDest != NULL and strSrc is NULLL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
+ * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
+ * ERANGE_AND_RESET destMax <= length of strSrc and strDest != strSrc
+ * and strDest != NULL and strSrc != NULL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and destMax != 0
+ * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
+ * and strDest != NULL and strSrc !=NULL and strDest != strSrc
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc)
+{
+ if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("wcscpy_s");
+ return ERANGE;
+ }
+ if (strDest == NULL || strSrc == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("wcscpy_s");
+ if (strDest != NULL) {
+ strDest[0] = L'\0';
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+ return SecDoCpyW(strDest, destMax, strSrc);
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/wcsncat_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/wcsncat_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..6151da4425553a73bc016a09dcf33fc8cea91675
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/wcsncat_s.c
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: wcsncat_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+/*
+ * Befor this function, the basic parameter checking has been done
+ */
+SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
+{
+ /* To calculate the length of a wide character, the parameter must be a wide character */
+ size_t destLen;
+ size_t srcLen;
+ SECUREC_CALC_WSTR_LEN(strDest, destMax, &destLen);
+ SECUREC_CALC_WSTR_LEN(strSrc, count, &srcLen);
+
+ if (SECUREC_CAT_STRING_IS_OVERLAP(strDest, destLen, strSrc, srcLen)) {
+ strDest[0] = L'\0';
+ if (strDest + destLen <= strSrc && destLen == destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s");
+ return EINVAL_AND_RESET;
+ }
+ SECUREC_ERROR_BUFFER_OVERLAP("wcsncat_s");
+ return EOVERLAP_AND_RESET;
+ }
+ if (srcLen + destLen >= destMax || strDest == strSrc) {
+ strDest[0] = L'\0';
+ if (destLen == destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s");
+ return EINVAL_AND_RESET;
+ }
+ SECUREC_ERROR_INVALID_RANGE("wcsncat_s");
+ return ERANGE_AND_RESET;
+ }
+ SECUREC_MEMCPY_WARP_OPT(strDest + destLen, strSrc, srcLen * sizeof(wchar_t)); /* no terminator */
+ *(strDest + destLen + srcLen) = L'\0';
+ return EOK;
+}
+
+/*
+ *
+ * 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 by strDest.
+ *
+ * The wcsncat_s function try to append the first D characters of strSrc to
+ * the end of strDest, where D is the lesser of count and the length of strSrc.
+ * If appending those D characters will fit within strDest (whose size is
+ * given as destMax) and still leave room for a null terminator, then those
+ * characters are appended, starting at the original terminating null of
+ * strDest, and a new terminating null is appended; otherwise, strDest[0] is
+ * set to the null character.
+ *
+ *
+ * strDest Null-terminated destination string.
+ * destMax Size of the destination buffer.
+ * strSrc Null-terminated source string.
+ * count Number of character to append, or truncate.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * EOK Success
+ * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
+ * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or
+ * (strDest != NULL and strSrc is NULLL and destMax != 0 and
+ * destMax <= SECUREC_WCHAR_STRING_MAX_LEN)
+ * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
+ * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
+{
+ if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("wcsncat_s");
+ return ERANGE;
+ }
+ if (strDest == NULL || strSrc == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("wcsncat_s");
+ if (strDest != NULL) {
+ strDest[0] = L'\0';
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+ if (count > SECUREC_WCHAR_STRING_MAX_LEN) {
+#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
+ if (count == ((size_t)(-1))) {
+ /* Windows internal functions may pass in -1 when calling this function */
+ return SecDoCatLimitW(strDest, destMax, strSrc, destMax);
+ }
+#endif
+ strDest[0] = L'\0';
+ SECUREC_ERROR_INVALID_RANGE("wcsncat_s");
+ return ERANGE_AND_RESET;
+ }
+ return SecDoCatLimitW(strDest, destMax, strSrc, count);
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/wcsncpy_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/wcsncpy_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..8bd5737bbc46cbfe4a59d6307293f7803069e373
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/wcsncpy_s.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: wcsncpy_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
+{
+ size_t srcStrLen;
+ if (count < destMax) {
+ SECUREC_CALC_WSTR_LEN(strSrc, count, &srcStrLen);
+ } else {
+ SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen);
+ }
+ if (srcStrLen == destMax) {
+ strDest[0] = L'\0';
+ SECUREC_ERROR_INVALID_RANGE("wcsncpy_s");
+ return ERANGE_AND_RESET;
+ }
+ if (strDest == strSrc) {
+ return EOK;
+ }
+ if (SECUREC_STRING_NO_OVERLAP(strDest, strSrc, srcStrLen)) {
+ /* Performance optimization srcStrLen not include '\0' */
+ SECUREC_MEMCPY_WARP_OPT(strDest, strSrc, srcStrLen * sizeof(wchar_t));
+ *(strDest + srcStrLen) = L'\0';
+ return EOK;
+ } else {
+ strDest[0] = L'\0';
+ SECUREC_ERROR_BUFFER_OVERLAP("wcsncpy_s");
+ return EOVERLAP_AND_RESET;
+ }
+}
+
+/*
+ *
+ * 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
+ *
+ *
+ * strDest Destination string.
+ * destMax The size of the destination string, in characters.
+ * strSrc Source string.
+ * count Number of characters to be copied.
+ *
+ *
+ * strDest is updated
+ *
+ *
+ * EOK Success
+ * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
+ * EINVAL_AND_RESET strDest != NULL and strSrc is NULLL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_STRING_MAX_LEN
+ * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0
+ * ERANGE_AND_RESET count > SECUREC_WCHAR_STRING_MAX_LEN or
+ * (destMax <= length of strSrc and destMax <= count and strDest != strSrc
+ * and strDest != NULL and strSrc != NULL and destMax != 0 and
+ * destMax <= SECUREC_WCHAR_STRING_MAX_LEN and not overlap)
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid
+ *
+ *
+ * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
+ */
+errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count)
+{
+ if (destMax == 0 || destMax > SECUREC_WCHAR_STRING_MAX_LEN) {
+ SECUREC_ERROR_INVALID_RANGE("wcsncpy_s");
+ return ERANGE;
+ }
+ if (strDest == NULL || strSrc == NULL) {
+ SECUREC_ERROR_INVALID_PARAMTER("wcsncpy_s");
+ if (strDest != NULL) {
+ strDest[0] = L'\0';
+ return EINVAL_AND_RESET;
+ }
+ return EINVAL;
+ }
+ if (count > SECUREC_WCHAR_STRING_MAX_LEN) {
+#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
+ if (count == (size_t)(-1)) {
+ return SecDoCpyLimitW(strDest, destMax, strSrc, destMax - 1);
+ }
+#endif
+ strDest[0] = L'\0'; /* Clear dest string */
+ SECUREC_ERROR_INVALID_RANGE("wcsncpy_s");
+ return ERANGE_AND_RESET;
+ }
+
+ if (count == 0) {
+ strDest[0] = L'\0';
+ return EOK;
+ }
+
+ return SecDoCpyLimitW(strDest, destMax, strSrc, count);
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/wcstok_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/wcstok_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..19284f334ed87aedf78a73860ddf2d7d92ff61f7
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/wcstok_s.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: wcstok_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+SECUREC_INLINE int SecIsInDelimitW(wchar_t ch, const wchar_t *strDelimit)
+{
+ const wchar_t *ctl = strDelimit;
+ while (*ctl != L'\0' && *ctl != ch) {
+ ++ctl;
+ }
+ return (int)(*ctl != L'\0');
+}
+
+/*
+ * Find beginning of token (skip over leading delimiters).
+ * Note that there is no token if this loop sets string to point to the terminal null.
+ */
+SECUREC_INLINE wchar_t *SecFindBeginW(wchar_t *strToken, const wchar_t *strDelimit)
+{
+ wchar_t *token = strToken;
+ while (*token != L'\0') {
+ if (SecIsInDelimitW(*token, strDelimit) != 0) {
+ ++token;
+ continue;
+ }
+ /* Don't find any delimiter in string header, break the loop */
+ break;
+ }
+ return token;
+}
+
+/*
+ * Find the end of the token. If it is not the end of the string, put a null there.
+ */
+SECUREC_INLINE wchar_t *SecFindRestW(wchar_t *strToken, const wchar_t *strDelimit)
+{
+ wchar_t *token = strToken;
+ while (*token != L'\0') {
+ if (SecIsInDelimitW(*token, strDelimit) != 0) {
+ /* Find a delimiter, set string termintor */
+ *token = L'\0';
+ ++token;
+ break;
+ }
+ ++token;
+ }
+ return token;
+}
+
+/*
+ * Update Token wide character function
+ */
+SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context)
+{
+ /* Point to updated position. Record string position for next search in the context */
+ *context = SecFindRestW(strToken, strDelimit);
+ /* Determine if a token has been found */
+ if (*context == strToken) {
+ return NULL;
+ }
+ return strToken;
+}
+
+/*
+ *
+ * wcstok_s
+ *
+ *
+ *
+ * The wcstok_s function is the wide-character equivalent of the strtok_s function
+ *
+ *
+ * strToken String containing token or tokens.
+ * strDelimit Set of delimiter characters.
+ * context Used to store position information between calls to
+ * wcstok_s.
+ *
+ *
+ * context is updated
+ *
+ * The wcstok_s function is the wide-character equivalent of the strtok_s function
+ */
+wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context)
+{
+ wchar_t *orgToken = strToken;
+ /* Validation section */
+ if (context == NULL || strDelimit == NULL) {
+ return NULL;
+ }
+ if (orgToken == NULL && *context == NULL) {
+ return NULL;
+ }
+ /* If string==NULL, continue with previous string */
+ if (orgToken == NULL) {
+ orgToken = *context;
+ }
+ orgToken = SecFindBeginW(orgToken, strDelimit);
+ return SecUpdateTokenW(orgToken, strDelimit, context);
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/wmemcpy_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/wmemcpy_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..99611809ff97c16567b016f244830db915633134
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/wmemcpy_s.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: wmemcpy_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+/*
+ *
+ * The wmemcpy_s function copies n successive wide characters
+ * from the object pointed to by src into the object pointed to by dest.t.
+ *
+ *
+ * dest Destination buffer.
+ * destMax Size of the destination buffer.
+ * src Buffer to copy from.
+ * count Number of characters to copy.
+ *
+ *
+ * dest buffer is uptdated.
+ *
+ *
+ * EOK Success
+ * EINVAL dest is NULL and destMax != 0 and count <= destMax
+ * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
+ * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax
+ * ERANGE destMax > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or
+ * (count > destMax and dest is NULL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN)
+ * ERANGE_AND_RESET count > destMax and dest != NULL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
+ * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and
+ * count <= destMax destMax != 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
+ * and dest != NULL and src != NULL and dest != src
+ *
+ * if an error occured, dest will be filled with 0 when dest and destMax valid .
+ * If the source and destination overlap, the behavior of wmemcpy_s is undefined.
+ * Use wmemmove_s to handle overlapping regions.
+ */
+errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count)
+{
+ if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) {
+ SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s");
+ return ERANGE;
+ }
+ if (count > destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s");
+ if (dest != NULL) {
+ (void)memset(dest, 0, destMax * sizeof(wchar_t));
+ return ERANGE_AND_RESET;
+ }
+ return ERANGE;
+ }
+ return memcpy_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t));
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/wmemmove_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/wmemmove_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..e66e29b7398ed9c75219a20a4b6338dc71badae8
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/wmemmove_s.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: wmemmove_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securecutil.h"
+
+/*
+ *
+ * The wmemmove_s function copies n successive wide characters from the object pointed
+ * to by src into the object pointed to by dest.
+ *
+ *
+ * dest Destination buffer.
+ * destMax Size of the destination buffer.
+ * src Source object.
+ * count Number of bytes or character to copy.
+ *
+ *
+ * dest is updated.
+ *
+ *
+ * EOK Success
+ * EINVAL dest is NULL and destMax != 0 and count <= destMax
+ * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
+ * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax
+ * ERANGE destMax > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or
+ * (count > destMax and dest is NULL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN)
+ * ERANGE_AND_RESET count > destMax and dest != NULL and destMax != 0
+ * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN
+ *
+ *
+ * If an error occured, dest will be filled with 0 when dest and destMax valid.
+ * If some regions of the source area and the destination overlap, wmemmove_s
+ * ensures that the original source bytes in the overlapping region are copied
+ * before being overwritten
+ */
+errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count)
+{
+ if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) {
+ SECUREC_ERROR_INVALID_PARAMTER("wmemmove_s");
+ return ERANGE;
+ }
+ if (count > destMax) {
+ SECUREC_ERROR_INVALID_PARAMTER("wmemmove_s");
+ if (dest != NULL) {
+ (void)memset(dest, 0, destMax * sizeof(wchar_t));
+ return ERANGE_AND_RESET;
+ }
+ return ERANGE;
+ }
+ return memmove_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t));
+}
+
diff --git a/3rd/gstor/dependency/Huawei_Secure_C/src/wscanf_s.c b/3rd/gstor/dependency/Huawei_Secure_C/src/wscanf_s.c
new file mode 100644
index 0000000000000000000000000000000000000000..0a3df7768b1ea6cc035b94a0378d6625b9a300c4
--- /dev/null
+++ b/3rd/gstor/dependency/Huawei_Secure_C/src/wscanf_s.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
+ * 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.
+ * Description: wscanf_s function
+ * Author: lishunda
+ * Create: 2014-02-25
+ */
+
+#include "securec.h"
+
+/*
+ *
+ *
+ * The wscanf_s function is the wide-character equivalent of the scanf_s function
+ * The wscanf_s function reads data from the standard input stream stdin and
+ * writes the data into the location that's given by argument. Each argument
+ * must be a pointer to a variable of a type that corresponds to a type specifier
+ * in format. If copying occurs between strings that overlap, the behavior is
+ * undefined.
+ *
+ *
+ * format Format control string.
+ * ... Optional arguments.
+ *
+ *
+ * ... the converted value stored in user assigned address
+ *
+ *
+ * Returns the number of fields successfully converted and assigned;
+ * the return value does not include fields that were read but not assigned.
+ * A return value of 0 indicates that no fields were assigned.
+ * return -1 if an error occurs.
+ */
+int wscanf_s(const wchar_t *format, ...)
+{
+ int ret; /* If initialization causes e838 */
+ va_list argList;
+
+ va_start(argList, format);
+ ret = vwscanf_s(format, argList);
+ va_end(argList);
+ (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */
+
+ return ret;
+}
+
diff --git a/3rd/gstor/dependency/build/build_all.sh b/3rd/gstor/dependency/build/build_all.sh
new file mode 100644
index 0000000000000000000000000000000000000000..8fb95b3e0b44a8c4f2572c8e75fdf8b86ebe89ef
--- /dev/null
+++ b/3rd/gstor/dependency/build/build_all.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# *************************************************************************
+# Copyright: (c) Huawei Technologies Co., Ltd. 2020. All rights reserved
+#
+# description: the script that make install dependency
+# date: 2023-1-6
+# version: 1.0.0
+# history:
+# 2023-1-6 fisrt version
+# *************************************************************************
+set -e
+
+ROOT_DIR=$(cd `dirname $0`/..; pwd)
+CURR_DIR=$(cd `dirname $0`; pwd)
+
+# check gcc min version
+let gcc_min_version=7
+gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
+ver_num=(${gcc_version//\./ })
+if [[ ${ver_num[0]} -lt $gcc_min_version ]]; then
+ echo "[ERROR] Current gcc version is: ${gcc_version}, to low. (No less then gcc $gcc_min_version)"
+ exit 1
+fi
+
+sh ${CURR_DIR}/build_tools.sh
+sh ${CURR_DIR}/build_platform.sh
+sh ${CURR_DIR}/build_dependency.sh
+
+[ -f "${ROOT_DIR}/demo.log" ] && rm -f "${ROOT_DIR}/demo.log"
diff --git a/3rd/gstor/dependency/build/build_dependency.sh b/3rd/gstor/dependency/build/build_dependency.sh
new file mode 100644
index 0000000000000000000000000000000000000000..4ceba5062552a49a0d0d7e76dd98cdfefea8008d
--- /dev/null
+++ b/3rd/gstor/dependency/build/build_dependency.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+# *************************************************************************
+# Copyright: (c) Huawei Technologies Co., Ltd. 2020. All rights reserved
+#
+# description: the script that make install dependency
+# date: 2020-10-21
+# version: 1.0
+# history:
+#
+# *************************************************************************
+set -e
+
+ARCH=$(uname -m)
+ROOT_DIR=$(cd `dirname $0`/..; pwd)
+
+[ -f build_all.log ] && rm -rf build_all.log
+
+function build_module() {
+ local module_name
+ local build_cmd='sh build.sh -m all'
+ local log_file="$ROOT_DIR/build/build_result.log"
+ case "$#" in
+ 3)
+ log_file=$3
+ build_cmd=$2
+ module_name=$1
+ ;;
+ 2)
+ build_cmd=$2
+ module_name=$1
+ ;;
+ 1)
+ module_name=$1
+ ;;
+ 0)
+ return
+ ;;
+ esac
+
+ echo "------------------------------ $module_name ------------------------------------------------------"
+ start_tm=$(date +%s%N)
+ cd ${ROOT_DIR}/${module_name}
+ ${build_cmd} 2>&1 >> "${log_file}"
+ end_tm=$(date +%s%N)
+ use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
+ echo "[${module_name}] use ${use_tm} second."
+}
+
+
+[ -f "${ROOT_DIR}/openssl/openssl/test/certs/embeddedSCTs1_issuer-key.pem" ] && rm -f "${ROOT_DIR}/openssl/openssl/test/certs/embeddedSCTs1_issuer-key.pem"
+#build_module openssl 'python3 build.py -m all -f openssl-OpenSSL_1_1_1n.tar.gz -t comm,llt' "${ROOT_DIR}/build/demo.log"
+#build_module cJSON
+#build_module lz4
+build_module zlib
+#build_module zstd
diff --git a/3rd/gstor/dependency/build/build_platform.sh b/3rd/gstor/dependency/build/build_platform.sh
new file mode 100644
index 0000000000000000000000000000000000000000..7ce9f0f9150ebe912e8fae9c7596ada99c8270df
--- /dev/null
+++ b/3rd/gstor/dependency/build/build_platform.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+# *************************************************************************
+# Copyright: (c) Huawei Technologies Co., Ltd. 2020. All rights reserved
+#
+# description: the script that make install platform
+# date: 2020-10-21
+# version: 1.0
+# history:
+#
+# *************************************************************************
+set -e
+
+ROOT_DIR=$(cd `dirname $0`/..; pwd)
+PLATFORM_PATH=${ROOT_DIR}
+
+# build huawei secure c lib
+cd ${PLATFORM_PATH}/Huawei_Secure_C
+sh build.sh -m all
+
+# build huawei jdk
+# cd ${PLATFORM_PATH}/openjdk8
+# sh ./build.sh
diff --git a/3rd/gstor/dependency/build/build_tools.sh b/3rd/gstor/dependency/build/build_tools.sh
new file mode 100644
index 0000000000000000000000000000000000000000..10d40d03a7d45756deab5173e61b7d4da338cac2
--- /dev/null
+++ b/3rd/gstor/dependency/build/build_tools.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+# *************************************************************************
+# Copyright: (c) Huawei Technologies Co., Ltd. 2020. All rights reserved
+#
+# description: the script that make install dependency
+# date: 2020-10-21
+# version: 1.0
+# history:
+#
+# *************************************************************************
+set -e
+
+ARCH=`uname -m`
+ROOT_DIR=$(cd `dirname $0`/..; pwd)
+PLATFORM="$(bash ${ROOT_DIR}/build/get_platform.sh)"
+
+[ -f build_tools.log ] && rm -rf build_tools.lo
+
+echo --------------------------------python2-------------------------------------------------
+if [ -z `command -v python2` ]; then
+ if [ -d "${ROOT_DIR}/python2" ]; then
+ start_tm=$(date +%s%N)
+ cd ${ROOT_DIR}/python2
+ sh ./build.sh >> build_tools.log
+ end_tm=$(date +%s%N)
+ use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
+ echo "[python] $use_tm"
+ fi
+else
+ echo 'python2 had already installed. Skip the build process of python2.'
+fi
+
+echo ---------------------------license_control---------------------------------------------
+if [ -d "${ROOT_DIR}/license_control" ]; then
+ start_tm=$(date +%s%N)
+ cd ${ROOT_DIR}/license_control
+ sh ./build.sh >> build_tools.log
+ end_tm=$(date +%s%N)
+ use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
+ echo "[license_control] $use_tm"
+fi
+
+# Use by dependency/pljava, dependency/postgresql-hll on
+# cp -a $(pwd)/../server_key $(pwd)/../../output/buildtools/
diff --git a/3rd/gstor/dependency/build/get_platform.sh b/3rd/gstor/dependency/build/get_platform.sh
new file mode 100644
index 0000000000000000000000000000000000000000..fbe26f9df5aec69b1c07d8368a7680a4c49ad24e
--- /dev/null
+++ b/3rd/gstor/dependency/build/get_platform.sh
@@ -0,0 +1,169 @@
+#!/bin/bash
+# *************************************************************************
+# Copyright: (c) Huawei Technologies Co., Ltd. 2019. All rights reserved
+#
+# description: Acording plat form, get the string info, like "redhat6.4_x86_64".
+# return: $plat_form_str : we support the platform and put out $plat_form_str
+# "Failed" : the plat form, not supported
+# date: 2015-8-22
+# version: 1.0.1
+# history:
+# 2023-1-6 Since Remove the dependency on `lsb_release` because it is not installed by default with CentOS minimal installations
+# *************************************************************************
+set -e
+
+##############################################################################################
+# common paremeters:
+# lsb_release and uname both suit almost all linux platform, including Redhat,CentOS,SuSE,Debian and so on.
+##############################################################################################
+# get os name
+kernel=""
+if [ -f "/etc/euleros-release" ]
+then
+ kernel=$(cat /etc/euleros-release | awk -F ' ' '{print $1}' | tr A-Z a-z)
+else
+ kernel=$(uname -n | awk -F '-' '{print $1}' | tr A-Z a-z)
+fi
+
+## to solve kernel="name=openeuler"
+if echo $kernel | grep -q 'openeuler'
+then
+ kernel="openeuler"
+fi
+
+# get cpu bit
+cpu_bit=$(uname -p)
+
+# the result info
+plat_form_str=""
+
+##################################################################################
+# redhat platform
+# the result form like this: redhat6.4_x86_64
+##################################################################################
+if [ "$kernel"x = "red"x ]
+then
+ plat_form_str=redhat6.4_"$cpu_bit"
+fi
+
+##################################################################################
+# fedora platform
+# the result form like this: redhat6.4_x86_64
+##################################################################################
+if [ "$kernel"x = "fedora"x ]
+then
+ plat_form_str=redhat6.4_"$cpu_bit"
+fi
+
+##################################################################################
+# suse platform
+# the result form like this: suse11_sp1_x86_64
+##################################################################################
+if [ "$kernel"x = "suse"x ]
+then
+ version=$(lsb_release -r | awk -F ' ' '{print $2}')
+ if [ "$version"x = "12"x ]
+ then
+ plat_form_str=suse12_"$cpu_bit"
+ else
+ plat_form_str=suse11_sp1_"$cpu_bit"
+ fi
+fi
+
+##################################################################################
+# euler platform
+# the result form like this: euleros2.0_sp8_aarch64
+##################################################################################
+if [ "$kernel"x = "euleros"x ]
+then
+ version=$(cat /etc/euleros-release | awk -F '(' '{print $2}'| awk -F ')' '{print $1}' | tr A-Z a-z)
+ plat_form_str=euleros2.0_"$version"_"$cpu_bit"
+fi
+
+##################################################################################
+# deepin platform
+# the result form like this: deepin_aarch64
+##################################################################################
+if [ "$kernel"x = "deepin"x ]
+then
+ if [ X"$cpu_bit" = X"unknown" ]
+ then
+ cpu_bit=$(uname -m)
+ fi
+ plat_form_str=deepin15.2_"$cpu_bit"
+fi
+##################################################################################
+# centos7.6_x86_64 platform
+# centos7.5+aarch64 platform
+# the result form like this: centos7.6_x86_64 or centos_7.5_aarch64
+##################################################################################
+if [ "$kernel"x = "centos"x ]
+then
+ if [ X"$cpu_bit" = X"aarch64" ]
+ then
+ plat_form_str=centos_7.5_aarch64
+ else
+ plat_form_str=centos7.6_"$cpu_bit"
+ fi
+fi
+
+
+##################################################################################
+# openeuler platform
+# the result form like this: openeuler_aarch64
+##################################################################################
+if [ "$kernel"x = "openeuler"x ]
+then
+ plat_form_str=openeuler_"$cpu_bit"
+fi
+
+
+##################################################################################
+# kylin platform
+# the result form like this: kylin_aarch64
+##################################################################################
+if [ "$kernel"x = "kylin"x ]
+then
+ plat_form_str=kylin_"$cpu_bit"
+fi
+
+
+##################################################################################
+# ubuntu platform
+# the result form like this: ubuntu_x86_64
+##################################################################################
+if [ "$kernel"x = "ubuntu"x ]
+then
+ plat_form_str=ubuntu18.04_"$cpu_bit"
+fi
+
+##################################################################################
+# redflag platform
+# the result form like this: asianux_x86_64
+##################################################################################
+if [ "$kernel"x = "redflag"x ]
+then
+ plat_form_str=asianux7.6_"$cpu_bit"
+fi
+
+##################################################################################
+# asianux platform
+# the result form like this: asianux_aarch64
+##################################################################################
+if [ "$kernel"x = "asianux"x ]
+then
+ plat_form_str=asianux7.5_"$cpu_bit"
+fi
+
+##################################################################################
+#
+# other platform
+#
+##################################################################################
+if [ -z "$plat_form_str" ]
+then
+ echo "Failed"
+else
+ echo $plat_form_str
+fi
+
diff --git a/3rd/gstor/dependency/build/test.sh b/3rd/gstor/dependency/build/test.sh
new file mode 100644
index 0000000000000000000000000000000000000000..1b895209dd35a04d02c620146e75e1624d8d649a
--- /dev/null
+++ b/3rd/gstor/dependency/build/test.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+CURRENT_DIR=$(cd $(dirname $0); pwd)
+echo CURRENT_DIR: $CURRENT_DIR
diff --git a/3rd/gstor/dependency/cJSON/build.sh b/3rd/gstor/dependency/cJSON/build.sh
new file mode 100644
index 0000000000000000000000000000000000000000..b72dc423fd35191b0ed55d5cf506ddc4c53fdb40
--- /dev/null
+++ b/3rd/gstor/dependency/cJSON/build.sh
@@ -0,0 +1,99 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2022. All rights reserved.
+# description: the script that make install cjson
+# date: 2020-08-10
+# version: 2.0
+# history:
+# 2019-5-5 update to cjson 1.7.11 from 1.7.7
+# 2019-12-28 fix buildcheck warning
+# 2020-06-22 fix buildcheck warning
+# 2020-08-10 update to cjson 1.7.13 from 1.7.11
+
+set -e
+
+WORK_PATH="$(dirname $0)"
+
+source "${WORK_PATH}/build_common.sh"
+
+source "${WORK_PATH}/build_component.sh"
+
+source "${WORK_PATH}/shrink_component.sh"
+
+source "${WORK_PATH}/dist_component.sh"
+
+source "${WORK_PATH}/clean_component.sh"
+
+#######################################################################
+#######################################################################
+#######################################################################
+# main
+#######################################################################
+#######################################################################
+#######################################################################
+function main()
+{
+
+ if [ -d ${SOURCE_CODE_PATH} ]; then
+ rm -rf ${SOURCE_CODE_PATH}
+ fi
+ mkdir $SOURCE_CODE_PATH
+ tar -zxf $TAR_FILE_NAME -C $SOURCE_CODE_PATH --strip-components 1
+ case "${BUILD_OPTION}" in
+ build)
+ build_component
+ ;;
+ shrink)
+ shrink_component
+ ;;
+ dist)
+ dist_component
+ ;;
+ clean)
+ clean_component
+ ;;
+ all)
+ build_component
+ shrink_component
+ dist_component
+ clean_component
+ ;;
+ *)
+ log "Internal Error: option processing error: $2"
+ log "please input right paramenter values build, shrink, dist or clean "
+ esac
+}
+
+
+########################################################################
+if [ $# = 0 ] ; then
+ log "missing option"
+ print_help
+ exit 1
+fi
+
+##########################################################################
+#read command line paramenters
+##########################################################################
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h|--help)
+ print_help
+ exit 1
+ ;;
+ -m|--build_option)
+ if [ "$2"X = X ];then
+ die "no given version number values"
+ fi
+ BUILD_OPTION=$2
+ shift 2
+ ;;
+ *)
+ log "Internal Error: option processing error: $1" 1>&2
+ log "please input right paramtenter, the following command may help you"
+ log "./build.sh --help or ./build.sh -h"
+ exit 1
+ esac
+done
+
+###########################################################################
+main
diff --git a/3rd/gstor/dependency/cJSON/build_common.sh b/3rd/gstor/dependency/cJSON/build_common.sh
new file mode 100644
index 0000000000000000000000000000000000000000..789bec7f946bbf6d9455be23b86060824461030c
--- /dev/null
+++ b/3rd/gstor/dependency/cJSON/build_common.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2022. All rights reserved.
+# description: the script that make install cjson
+# date: 2020-08-10
+# version: 2.0
+# history:
+# 2019-5-5 update to cjson 1.7.11 from 1.7.7
+# 2019-12-28 fix buildcheck warning
+# 2020-06-22 fix buildcheck warning
+# 2020-08-10 update to cjson 1.7.13 from 1.7.11
+
+set -e
+
+######################################################################
+# Parameter setting
+######################################################################
+LOCAL_PATH=${0}
+FIRST_CHAR=$(expr substr "$LOCAL_PATH" 1 1)
+if [ "$FIRST_CHAR" = "/" ]; then
+ LOCAL_PATH=${0}
+else
+ LOCAL_PATH="$(pwd)/${LOCAL_PATH}"
+fi
+
+LOCAL_DIR=$(dirname "${LOCAL_PATH}")
+CONFIG_FILE_NAME=config.ini
+BUILD_OPTION=release
+
+TAR_FILE_NAME=cJSON-1.7.15.tar.gz
+SOURCE_CODE_PATH=cJSON
+
+LOG_FILE=${LOCAL_DIR}/build_cjson.log
+BUILD_FAILED=1
+
+ls ${LOCAL_DIR}/${CONFIG_FILE_NAME} >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+ die "[Error] the file ${CONFIG_FILE_NAME} not exist."
+fi
+
+COMPLIE_TYPE_LIST=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' | awk -F '=' '{print $2}' | sed 's/|/ /g')
+COMPONENT_NAME=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' |awk -F '=' '{print $1}'| awk -F '@' '{print $2}')
+
+if [ "${COMPONENT_NAME}"X = ""X ]
+then
+ die "[Error] get component name failed!"
+fi
+
+ROOT_DIR="${LOCAL_DIR}/../../"
+INSTALL_COMPOENT_PATH_NAME="${ROOT_DIR}/output/kernel/dependency/${COMPONENT_NAME}"
+
+#######################################################################
+## print help information
+#######################################################################
+function print_help()
+{
+ echo "Usage: $0 [OPTION]
+ -h|--help show help information
+ -m|--build_option provode type of operation, values of paramenter is build, shrink, dist or clean
+ "
+}
+
+#######################################################################
+# Print log.
+#######################################################################
+log()
+{
+ echo "[Build cjson] $(date +%y-%m-%d' '%T): $@"
+ echo "[Build cjson] $(date +%y-%m-%d' '%T): $@" >> "$LOG_FILE" 2>&1
+}
+
+#######################################################################
+# print log and exit.
+#######################################################################
+die()
+{
+ log "$@"
+ echo "$@"
+ exit $BUILD_FAILED
+}
+
diff --git a/3rd/gstor/dependency/cJSON/build_component.sh b/3rd/gstor/dependency/cJSON/build_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..8adc6f6ef17738a3234dbbba8b6b9869747436d2
--- /dev/null
+++ b/3rd/gstor/dependency/cJSON/build_component.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2022. All rights reserved.
+# description: the script that make install cjson
+# date: 2020-08-10
+# version: 2.0
+# history:
+# 2019-5-5 update to cjson 1.7.11 from 1.7.7
+# 2019-12-28 fix buildcheck warning
+# 2020-06-22 fix buildcheck warning
+# 2020-08-10 update to cjson 1.7.13 from 1.7.11
+
+set -e
+
+#######################################################################
+# build and install component
+#######################################################################
+function build_component()
+{
+ cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
+
+ if [ $? -ne 0 ]; then
+ die "[Error] change dir to $SRC_DIR failed."
+ fi
+
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}
+ do
+ case "${COMPILE_TYPE}" in
+ release)
+ die "[Error] cjson not supported build type."
+ ;;
+ debug)
+ die "[Error] cjson not supported build type."
+ ;;
+ release_llt)
+ die "[Error] cjson not supported build type."
+ ;;
+ debug_llt)
+ die "[Error] cjson not supported build type."
+ ;;
+ comm|llt)
+ mkdir -p ${LOCAL_DIR}/install_${COMPILE_TYPE}
+ log "[Notice] cjson using \"${COMPILE_TYPE}\" Begin make"
+
+ mkdir tmp_build
+ cd tmp_build
+ cmake .. -DENABLE_CJSON_UTILS=ON -DENABLE_SAFE_STACK=ON -DCMAKE_PROJECT_INCLUDE=${LOCAL_DIR}/${SOURCE_CODE_PATH}/../project_include.cmake -DCMAKE_INSTALL_PREFIX=${LOCAL_DIR}/install_${COMPILE_TYPE}
+ make
+ ;;
+ *)
+ log "Internal Error: option processing error: $1"
+ log "please write right paramenter in ${CONFIG_FILE_NAME}"
+ exit 1
+ esac
+
+ if [ $? -ne 0 ]; then
+ die "cjson make failed."
+ fi
+ log "[Notice] cjson End make"
+
+ log "[Notice] cjson using \"${COMPILE_TYPE}\" Begin make install"
+ make install
+ cd ${LOCAL_DIR}/install_${COMPILE_TYPE}
+ mv lib64 lib
+ if [ $? -ne 0 ]; then
+ die "[Error] cjson make install failed."
+ fi
+ log "[Notice] cjson using \"${COMPILE_TYPE}\" End make install"
+
+ cd ${LOCAL_DIR}
+ if [ -d ${SOURCE_CODE_PATH} ]; then
+ rm -rf ${SOURCE_CODE_PATH}
+ fi
+ mkdir $SOURCE_CODE_PATH
+ tar -zxf $TAR_FILE_NAME -C $SOURCE_CODE_PATH --strip-components 1
+ cd ${LOCAL_DIR}/$SOURCE_CODE_PATH
+
+ log "[Notice] cjson build using \"${COMPILE_TYPE}\" has been finished"
+ done
+}
diff --git a/3rd/gstor/dependency/cJSON/cJSON-1.7.15.tar.gz b/3rd/gstor/dependency/cJSON/cJSON-1.7.15.tar.gz
new file mode 100644
index 0000000000000000000000000000000000000000..bc92023d9fcc421fd2c8fefd0cba740c6b25f8ab
Binary files /dev/null and b/3rd/gstor/dependency/cJSON/cJSON-1.7.15.tar.gz differ
diff --git a/3rd/gstor/dependency/cJSON/clean_component.sh b/3rd/gstor/dependency/cJSON/clean_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..8c7152e1a200b3b0f0eff92c7ae8fbd3c9b68172
--- /dev/null
+++ b/3rd/gstor/dependency/cJSON/clean_component.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2022. All rights reserved.
+# description: the script that make install cjson
+# date: 2020-08-10
+# version: 2.0
+# history:
+# 2019-5-5 update to cjson 1.7.11 from 1.7.7
+# 2019-12-28 fix buildcheck warning
+# 2020-06-22 fix buildcheck warning
+# 2020-08-10 update to cjson 1.7.13 from 1.7.11
+
+set -e
+
+#######################################################################
+# clean component
+#######################################################################
+function clean_component()
+{
+ cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
+ if [ $? -ne 0 ]; then
+ die "[Error] cd ${LOCAL_DIR}/${SOURCE_CODE_PATH} failed."
+ fi
+
+ make clean
+
+ cd ${LOCAL_DIR}
+ if [ $? -ne 0 ]; then
+ die "[Error] cd ${LOCAL_DIR} failed."
+ fi
+ [ -n "${SOURCE_CODE_PATH}" ] && rm -rf ${SOURCE_CODE_PATH}
+ rm -rf install_*
+ rm -rf *.log
+
+ log "[Notice] cjson clean has been finished!"
+}
diff --git a/3rd/gstor/dependency/cJSON/config.ini b/3rd/gstor/dependency/cJSON/config.ini
new file mode 100644
index 0000000000000000000000000000000000000000..fc73150fefa23f5ba4eb76191f09447524c3ffc0
--- /dev/null
+++ b/3rd/gstor/dependency/cJSON/config.ini
@@ -0,0 +1,4 @@
+###############################
+# cjson support
+###############################
+binarylibs@cjson=comm|llt
diff --git a/3rd/gstor/dependency/cJSON/dist_component.sh b/3rd/gstor/dependency/cJSON/dist_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..03fdaeb321cd33b911055e29a26c2840735180e5
--- /dev/null
+++ b/3rd/gstor/dependency/cJSON/dist_component.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2022. All rights reserved.
+# description: the script that make install cjson
+# date: 2020-08-10
+# version: 2.0
+# history:
+# 2019-5-5 update to cjson 1.7.11 from 1.7.7
+# 2019-12-28 fix buildcheck warning
+# 2020-06-22 fix buildcheck warning
+# 2020-08-10 update to cjson 1.7.13 from 1.7.11
+
+set -e
+
+##############################################################################################################
+# dist the real files to the matched path
+# we could makesure that $INSTALL_COMPOENT_PATH_NAME is not null, '.' or '/'
+##############################################################################################################
+function dist_component()
+{
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}
+ do
+ case "${COMPILE_TYPE}" in
+ comm)
+ mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/comm
+ rm -rf ${INSTALL_COMPOENT_PATH_NAME}/comm/*
+ cp -dr ${LOCAL_DIR}/install_comm_dist/* ${INSTALL_COMPOENT_PATH_NAME}/comm
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_comm_dist/* ${INSTALL_COMPOENT_PATH_NAME}/comm\" failed."
+ fi
+ ;;
+ llt)
+ mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/llt
+ rm -rf ${INSTALL_COMPOENT_PATH_NAME}/llt/*
+ cp -dr ${LOCAL_DIR}/install_llt_dist/* ${INSTALL_COMPOENT_PATH_NAME}/llt
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_llt_dist/* ${INSTALL_COMPOENT_PATH_NAME}/llt\" failed."
+ fi
+ ;;
+ release)
+ ;;
+ debug)
+ ;;
+ release_llt)
+ ;;
+ debug_llt)
+ ;;
+ *)
+ esac
+ log "[Notice] cjson dist using \"${COMPILE_TYPE}\" has been finished!"
+ done
+}
+
diff --git a/3rd/gstor/dependency/cJSON/project_include.cmake b/3rd/gstor/dependency/cJSON/project_include.cmake
new file mode 100644
index 0000000000000000000000000000000000000000..72b7d9b20c087a13438c414cb543d02f55ee4621
--- /dev/null
+++ b/3rd/gstor/dependency/cJSON/project_include.cmake
@@ -0,0 +1,11 @@
+add_compile_options(
+ -fstack-protector-all
+ $<$,STATIC_LIBRARY>:-fPIC>
+ $<$,EXECUTABLE>:-fPIE>
+)
+add_link_options(
+ -Wl,-z,now
+ -Wl,-z,relro
+ -Wl,-z,noexecstack
+ $<$,EXECUTABLE>:-pie>
+)
diff --git a/3rd/gstor/dependency/cJSON/readme.txt b/3rd/gstor/dependency/cJSON/readme.txt
new file mode 100644
index 0000000000000000000000000000000000000000..8409033c67f95423dcd143beec5bf452559c0b87
--- /dev/null
+++ b/3rd/gstor/dependency/cJSON/readme.txt
@@ -0,0 +1,10 @@
+open source target name :cJSON
+source code repository : product warehouse
+compile dependency: NULL
+upgrade open source package method:
+----|pull command : python $(pwd)../../build/pull_open_source.py "path" "name" "id"
+ |----path : the parent directory name
+ |----name:the package name in product warehouse
+ |----id:pdm version id
+the compile command : sh -x build.sh -m all
+Patch Info:
diff --git a/3rd/gstor/dependency/cJSON/shrink_component.sh b/3rd/gstor/dependency/cJSON/shrink_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..ff6c4a84ebedd56d5ecc743ed9e841339e0d3cad
--- /dev/null
+++ b/3rd/gstor/dependency/cJSON/shrink_component.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2022. All rights reserved.
+# description: the script that make install cjson
+# date: 2020-08-10
+# version: 2.0
+# history:
+# 2019-5-5 update to cjson 1.7.11 from 1.7.7
+# 2019-12-28 fix buildcheck warning
+# 2020-06-22 fix buildcheck warning
+# 2020-08-10 update to cjson 1.7.13 from 1.7.11
+
+set -e
+
+#######################################################################
+# choose the real files
+#######################################################################
+function shrink_component()
+{
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}
+ do
+ case "${COMPILE_TYPE}" in
+ release)
+ ;;
+ comm)
+ mkdir -p ${LOCAL_DIR}/install_comm_dist/lib
+ cp -dr ${LOCAL_DIR}/install_comm/include ${LOCAL_DIR}/install_comm_dist
+ cp -a ${LOCAL_DIR}/install_comm/lib/*\.so* ${LOCAL_DIR}/install_comm_dist/lib
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_comm/* ${LOCAL_DIR}/install_comm_dist\" failed."
+ fi
+ ;;
+ llt)
+ mkdir -p ${LOCAL_DIR}/install_llt_dist/lib
+ cp -dr ${LOCAL_DIR}/install_llt/include ${LOCAL_DIR}/install_llt_dist
+ cp -a ${LOCAL_DIR}/install_llt/lib/*\.so* ${LOCAL_DIR}/install_llt_dist/lib
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_llt/* ${LOCAL_DIR}/install_llt_dist\" failed."
+ fi
+ ;;
+ debug)
+ ;;
+ release_llt)
+ ;;
+ debug_llt)
+ ;;
+ *)
+ esac
+ log "[Notice] lz4 shrink using \"${COMPILE_TYPE}\" has been finished!"
+ done
+}
diff --git a/3rd/gstor/dependency/lz4/README.txt b/3rd/gstor/dependency/lz4/README.txt
new file mode 100644
index 0000000000000000000000000000000000000000..a530d637252f1a99bd492fbb4329b12ce31b5f86
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/README.txt
@@ -0,0 +1,10 @@
+open source target name lz4
+source code repository : product warehouse
+compile dependency: NULL
+upgrade open source package method
+----|pull command : python $(pwd)../../build/pull_open_source.py "path" "name" "id"
+ |----path : the parent directory name
+ |----namethe package name in product warehouse
+ |----idpdm version id
+the compile command :
+Patch Info:
\ No newline at end of file
diff --git a/3rd/gstor/dependency/lz4/build.sh b/3rd/gstor/dependency/lz4/build.sh
new file mode 100644
index 0000000000000000000000000000000000000000..1f8b4e8afdd497bf7d146b0b29d86afeb2ab06a4
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/build.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2018. All rights reserved.
+# description: the script that make install lz4
+# date: 2019-12-28
+# version: 1.11
+# history:
+# 2019-5-5 update to lz4 1.8.3 from 1.7.5
+# 2019-12-12 update to lz4 1.9.2 from 1.8.3
+# 2019-12-28 change formatting and add copyright notice
+
+set -e
+
+WORK_PATH="$(dirname $0)"
+
+source "${WORK_PATH}/build_common.sh"
+
+source "${WORK_PATH}/build_component.sh"
+
+source "${WORK_PATH}/shrink_component.sh"
+
+source "${WORK_PATH}/dist_component.sh"
+
+source "${WORK_PATH}/clean_component.sh"
+
+#######################################################################
+#######################################################################
+#######################################################################
+# main
+#######################################################################
+#######################################################################
+#######################################################################
+function main()
+{
+ case "${BUILD_OPTION}" in
+ build)
+ build_component
+ ;;
+ shrink)
+ shrink_component
+ ;;
+ dist)
+ dist_component
+ ;;
+ clean)
+ clean_component
+ ;;
+ all)
+ build_component
+ shrink_component
+ dist_component
+ clean_component
+ ;;
+ *)
+ log "Internal Error: option processing error: $2"
+ log "please input right paramenter values build, shrink, dist or clean "
+ esac
+}
+
+
+########################################################################
+if [ $# = 0 ] ; then
+ log "missing option"
+ print_help
+ exit 1
+fi
+
+##########################################################################
+#read command line paramenters
+##########################################################################
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h|--help)
+ print_help
+ exit 1
+ ;;
+ -m|--build_option)
+ if [ "$2"X = X ];then
+ die "no given version number values"
+ fi
+ BUILD_OPTION=$2
+ shift 2
+ ;;
+ *)
+ log "Internal Error: option processing error: $1" 1>&2
+ log "please input right paramtenter, the following command may help you"
+ log "./build.sh --help or ./build.sh -h"
+ exit 1
+ esac
+done
+
+###########################################################################
+main
diff --git a/3rd/gstor/dependency/lz4/build_common.sh b/3rd/gstor/dependency/lz4/build_common.sh
new file mode 100644
index 0000000000000000000000000000000000000000..bb4f18d304b3a5b3b522ea5bfc6d15c16a822289
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/build_common.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2018. All rights reserved.
+# description: the script that make install lz4
+# date: 2019-12-28
+# version: 1.11
+# history:
+# 2019-5-5 update to lz4 1.8.3 from 1.7.5
+# 2019-12-12 update to lz4 1.9.2 from 1.8.3
+# 2019-12-28 change formatting and add copyright notice
+
+set -e
+
+######################################################################
+# Parameter setting
+######################################################################
+LOCAL_PATH=${0}
+FIRST_CHAR=$(expr substr "$LOCAL_PATH" 1 1)
+if [ "$FIRST_CHAR" = "/" ]; then
+ LOCAL_PATH=${0}
+else
+ LOCAL_PATH="$(pwd)/${LOCAL_PATH}"
+fi
+
+LOCAL_DIR=$(dirname "${LOCAL_PATH}")
+CONFIG_FILE_NAME=config.ini
+BUILD_OPTION=release
+
+TAR_FILE_NAME=lz4-1.9.3.tar.gz
+SOURCE_CODE_PATH=lz4
+
+LOG_FILE=${LOCAL_DIR}/build_lz4.log
+BUILD_FAILED=1
+
+ls ${LOCAL_DIR}/${CONFIG_FILE_NAME} >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+ die "[Error] the file ${CONFIG_FILE_NAME} not exist."
+fi
+
+COMPLIE_TYPE_LIST=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' | awk -F '=' '{print $2}' | sed 's/|/ /g')
+COMPONENT_NAME=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' |awk -F '=' '{print $1}'| awk -F '@' '{print $2}')
+COMPONENT_TYPE=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' | awk -F '@' '{print $1}')
+
+if [ "${COMPONENT_NAME}"X = ""X ]
+then
+ die "[Error] get component name failed!"
+fi
+
+if [ "${COMPONENT_TYPE}"X = ""X ]
+then
+ die "[Error] get component type failed!"
+fi
+
+
+ROOT_DIR="${LOCAL_DIR}/../../"
+INSTALL_COMPOENT_PATH_NAME="${ROOT_DIR}/output/kernel/dependency/${COMPONENT_NAME}"
+
+#######################################################################
+## print help information
+#######################################################################
+function print_help()
+{
+ echo "Usage: $0 [OPTION]
+ -h|--help show help information
+ -m|--build_option provode type of operation, values of paramenter is build, shrink, dist or clean
+ "
+}
+
+#######################################################################
+# Print log.
+#######################################################################
+log()
+{
+ echo "[Build lz4] "$(date +%y-%m-%d" "%T)": $@"
+ echo "[Build lz4] "$(date +%y-%m-%d" "%T)": $@" >> "$LOG_FILE" 2>&1
+}
+
+#######################################################################
+# print log and exit.
+#######################################################################
+die()
+{
+ log "$@"
+ echo "$@"
+ exit $BUILD_FAILED
+}
diff --git a/3rd/gstor/dependency/lz4/build_component.sh b/3rd/gstor/dependency/lz4/build_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..51776967c3254c18ddffb09e6f4784840555c927
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/build_component.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2018. All rights reserved.
+# description: the script that make install lz4
+# date: 2019-12-28
+# version: 1.11
+# history:
+# 2019-5-5 update to lz4 1.8.3 from 1.7.5
+# 2019-12-12 update to lz4 1.9.2 from 1.8.3
+# 2019-12-28 change formatting and add copyright notice
+
+set -e
+
+#######################################################################
+# build and install component
+#######################################################################
+function build_component()
+{
+ cd ${LOCAL_DIR}
+
+ if [ -d ${SOURCE_CODE_PATH} ]; then
+ rm -rf ${SOURCE_CODE_PATH}
+ fi
+ rm -rf install_*
+ mkdir ${SOURCE_CODE_PATH}
+ tar -zxf $TAR_FILE_NAME -C $SOURCE_CODE_PATH --strip-components 1
+
+ cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
+ if [ $? -ne 0 ]; then
+ die "[Error] change dir to $SRC_DIR failed."
+ fi
+
+ # copy and apply patch
+ log "[Notice] begin apply patch to lz4 "
+ patch -p1 < ../lz4.patch
+ # cd lib/
+ # cp ../../huawei_lz4.patch ./
+ # patch -p0 < huawei_lz4.patch
+ # if [ $? -ne 0 ]; then
+ # die "[Error] apply patch failed."
+ # fi
+ # log "[Notice] finish apply patch to lz4 "
+
+ # chmod +x configure
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}
+ do
+ case "${COMPILE_TYPE}" in
+ release)
+ die "[Error] lz4 not supported build type."
+ ;;
+ debug)
+ die "[Error] lz4 not supported build type."
+ ;;
+ release_llt)
+ die "[Error] lz4 not supported build type."
+ ;;
+ debug_llt)
+ die "[Error] lz4 not supported build type."
+ ;;
+ comm|llt)
+ mkdir -p ${LOCAL_DIR}/install_${COMPILE_TYPE}
+
+ log "[Notice] lz4 using \"${COMPILE_TYPE}\" Begin make"
+ if [ "${COMPILE_TYPE}"X = "comm"X ]; then
+ sed -i '53a CFLAGS += -fPIC -fstack-protector-strong' lib/Makefile
+ sed -i '54a LDFLAGS += -Wl,-z,relro,-z,now,-z,noexecstack -pie' lib/Makefile
+
+ sed -i '52a CFLAGS += -fstack-protector-strong -fPIE' programs/Makefile
+ sed -i '53a LDFLAGS += -Wl,-z,relro,-z,now,-z,noexecstack -pie' programs/Makefile
+ make -j4
+ else
+ make -j4
+ fi
+ ;;
+ *)
+ log "Internal Error: option processing error: $1"
+ log "please write right paramenter in ${CONFIG_FILE_NAME}"
+ exit 1
+ esac
+
+ if [ $? -ne 0 ]; then
+ die "lz4 make failed."
+ fi
+ log "[Notice] lz4 End make"
+
+ log "[Notice] lz4 using \"${COMPILE_TYPE}\" Begin make install"
+ make install prefix=${LOCAL_DIR}/install_${COMPILE_TYPE}
+ if [ $? -ne 0 ]; then
+ die "[Error] lz4 make install failed."
+ fi
+ log "[Notice] lz4 using \"${COMPILE_TYPE}\" End make install"
+ make clean -s
+ log "[Notice] lz4 build using \"${COMPILE_TYPE}\" has been finished"
+ done
+}
diff --git a/3rd/gstor/dependency/lz4/clean_component.sh b/3rd/gstor/dependency/lz4/clean_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..59cdd06b44604d97f0b20e61190170d88e914796
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/clean_component.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2018. All rights reserved.
+# description: the script that make install lz4
+# date: 2019-12-28
+# version: 1.11
+# history:
+# 2019-5-5 update to lz4 1.8.3 from 1.7.5
+# 2019-12-12 update to lz4 1.9.2 from 1.8.3
+# 2019-12-28 change formatting and add copyright notice
+
+set -e
+
+#######################################################################
+# clean component
+#######################################################################
+function clean_component()
+{
+ cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
+ if [ $? -ne 0 ]; then
+ die "[Error] cd ${LOCAL_DIR}/${SOURCE_CODE_PATH} failed."
+ fi
+
+ make clean
+
+ cd ${LOCAL_DIR}
+ if [ $? -ne 0 ]; then
+ die "[Error] cd ${LOCAL_DIR} failed."
+ fi
+ [ -n "${SOURCE_CODE_PATH}" ] && rm -rf "${SOURCE_CODE_PATH}"
+ #rm -rf install_*
+ rm -rf *.log
+
+ log "[Notice] lz4 clean has been finished!"
+}
diff --git a/3rd/gstor/dependency/lz4/config.ini b/3rd/gstor/dependency/lz4/config.ini
new file mode 100644
index 0000000000000000000000000000000000000000..c039f8442ca0cfab197a4712ad2eebd3cdcfd5f5
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/config.ini
@@ -0,0 +1,4 @@
+###############################
+# libtinfo support
+###############################
+binarylibs@lz4=comm|llt
diff --git a/3rd/gstor/dependency/lz4/dist_component.sh b/3rd/gstor/dependency/lz4/dist_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..ec24ab6ebb086e7fb4caefa0fdbe6c174e98a364
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/dist_component.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2018. All rights reserved.
+# description: the script that make install lz4
+# date: 2019-12-28
+# version: 1.11
+# history:
+# 2019-5-5 update to lz4 1.8.3 from 1.7.5
+# 2019-12-12 update to lz4 1.9.2 from 1.8.3
+# 2019-12-28 change formatting and add copyright notice
+
+set -e
+
+##############################################################################################################
+# dist the real files to the matched path
+# we could makesure that $INSTALL_COMPOENT_PATH_NAME is not null, '.' or '/'
+##############################################################################################################
+function dist_component()
+{
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}
+ do
+ case "${COMPILE_TYPE}" in
+ comm)
+ mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/comm
+ rm -rf "${INSTALL_COMPOENT_PATH_NAME}"/comm/*
+ cp -dr ${LOCAL_DIR}/install_comm_dist/* ${INSTALL_COMPOENT_PATH_NAME}/comm
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_comm_dist/* ${INSTALL_COMPOENT_PATH_NAME}/comm\" failed."
+ fi
+ ;;
+ llt)
+ mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/llt
+ rm -rf "${INSTALL_COMPOENT_PATH_NAME}"/llt/*
+ cp -dr ${LOCAL_DIR}/install_llt_dist/* ${INSTALL_COMPOENT_PATH_NAME}/llt
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_llt_dist/* ${INSTALL_COMPOENT_PATH_NAME}/llt\" failed."
+ fi
+ ;;
+ release)
+ ;;
+ debug)
+ ;;
+ release_llt)
+ ;;
+ debug_llt)
+ ;;
+ *)
+ esac
+ log "[Notice] lz4 dist using \"${COMPILE_TYPE}\" has been finished!"
+ done
+}
+
diff --git a/3rd/gstor/dependency/lz4/huawei_lz4.patch b/3rd/gstor/dependency/lz4/huawei_lz4.patch
new file mode 100644
index 0000000000000000000000000000000000000000..7ba8ee42dfb2b3fc618fd8adde422e66e55cedc1
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/huawei_lz4.patch
@@ -0,0 +1,10 @@
+--- lz4hc.c 2019-12-12 15:28:42.669000000 +0800
++++ lz4hc.c.new 2019-12-12 15:27:38.604000000 +0800
+@@ -921,6 +921,7 @@
+ {
+ #if defined(LZ4HC_HEAPMODE) && LZ4HC_HEAPMODE==1
+ LZ4_streamHC_t* const statePtr = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t));
++ if (statePtr == NULL) return 0;
+ #else
+ LZ4_streamHC_t state;
+ LZ4_streamHC_t* const statePtr = &state;
diff --git a/3rd/gstor/dependency/lz4/lz4-1.9.3.tar.gz b/3rd/gstor/dependency/lz4/lz4-1.9.3.tar.gz
new file mode 100644
index 0000000000000000000000000000000000000000..c26129a58b87b9a00b2889701abb76de2af5199d
Binary files /dev/null and b/3rd/gstor/dependency/lz4/lz4-1.9.3.tar.gz differ
diff --git a/3rd/gstor/dependency/lz4/lz4-CVE-2021-3520.patch b/3rd/gstor/dependency/lz4/lz4-CVE-2021-3520.patch
new file mode 100644
index 0000000000000000000000000000000000000000..b5c16b75b04bd77875c921faacbe581752a21418
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/lz4-CVE-2021-3520.patch
@@ -0,0 +1,24 @@
+commit 9b97c3a72a0ef1b66e0326d180fa0b29fc9c2094
+Author: l30004689
+Date: Fri Jun 11 03:01:43 2021 -0400
+
+ [Backport]Fix potential memory corruption with negative memmove() size
+
+ Offering: GaussDB Kernel
+ CVE: CVE-2021-3520
+ Reference: https://github.com/lz4/lz4/commit/8301a21773ef61656225e264f4f06ae14462bca7
+ Signed-off-by: liuqirun liuqirun@huawei.com
+
+diff --git a/lib/lz4.c b/lib/lz4.c
+index 9808d70..805388d 100644
+--- a/lib/lz4.c
++++ b/lib/lz4.c
+@@ -1665,7 +1665,7 @@ LZ4_decompress_generic(
+ const size_t dictSize /* note : = 0 if noDict */
+ )
+ {
+- if (src == NULL) { return -1; }
++ if ((src == NULL) || (outputSize < 0)) { return -1; }
+
+ { const BYTE* ip = (const BYTE*) src;
+ const BYTE* const iend = ip + srcSize;
diff --git a/3rd/gstor/dependency/lz4/lz4.patch b/3rd/gstor/dependency/lz4/lz4.patch
new file mode 100644
index 0000000000000000000000000000000000000000..f559956d5e7415d71c8de390dd322b36f9fefbe9
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/lz4.patch
@@ -0,0 +1,33 @@
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' lz4/lib/lz4.c lz4_h1/lib/lz4.c
+*** lz4/lib/lz4.c 2022-08-26 15:00:24.524000000 +0800
+--- lz4_h1/lib/lz4.c 2022-08-26 15:00:10.636000000 +0800
+***************
+*** 1749,1755 ****
+ const size_t dictSize /* note : = 0 if noDict */
+ )
+ {
+! if (src == NULL) { return -1; }
+
+ { const BYTE* ip = (const BYTE*) src;
+ const BYTE* const iend = ip + srcSize;
+--- 1749,1755 ----
+ const size_t dictSize /* note : = 0 if noDict */
+ )
+ {
+! if ((src == NULL) || (outputSize < 0)) { return -1; }
+
+ { const BYTE* ip = (const BYTE*) src;
+ const BYTE* const iend = ip + srcSize;
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' lz4/lib/lz4hc.c lz4_h1/lib/lz4hc.c
+*** lz4/lib/lz4hc.c 2022-08-26 15:00:24.524000000 +0800
+--- lz4_h1/lib/lz4hc.c 2022-08-26 15:00:10.640000000 +0800
+***************
+*** 955,960 ****
+--- 955,961 ----
+ {
+ #if defined(LZ4HC_HEAPMODE) && LZ4HC_HEAPMODE==1
+ LZ4_streamHC_t* const statePtr = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t));
++ if (statePtr == NULL) return 0;
+ #else
+ LZ4_streamHC_t state;
+ LZ4_streamHC_t* const statePtr = &state;
diff --git a/3rd/gstor/dependency/lz4/shrink_component.sh b/3rd/gstor/dependency/lz4/shrink_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..89d40efa7018dfb05073e7769d8adcd955fca5ba
--- /dev/null
+++ b/3rd/gstor/dependency/lz4/shrink_component.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+# Copyright (c) Huawei Technologies Co., Ltd. 2010-2018. All rights reserved.
+# description: the script that make install lz4
+# date: 2019-12-28
+# version: 1.11
+# history:
+# 2019-5-5 update to lz4 1.8.3 from 1.7.5
+# 2019-12-12 update to lz4 1.9.2 from 1.8.3
+# 2019-12-28 change formatting and add copyright notice
+
+set -e
+
+#######################################################################
+# choose the real files
+#######################################################################
+function shrink_component()
+{
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}
+ do
+ case "${COMPILE_TYPE}" in
+ release)
+ ;;
+ comm)
+ mkdir ${LOCAL_DIR}/install_comm_dist
+ cp -r ${LOCAL_DIR}/install_comm/* ${LOCAL_DIR}/install_comm_dist
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_comm/* ${LOCAL_DIR}/install_comm_dist\" failed."
+ fi
+ rm -rf ${LOCAL_DIR}/install_comm_dist/share
+ rm ${LOCAL_DIR}/install_comm_dist/lib/liblz4.a
+ rm ${LOCAL_DIR}/install_comm_dist/bin/lz4c
+ rm ${LOCAL_DIR}/install_comm_dist/bin/lz4cat
+ rm ${LOCAL_DIR}/install_comm_dist/bin/unlz4
+ rm -rf ${LOCAL_DIR}/install_comm_dist/lib/pkgconfig
+ ;;
+ llt)
+ mkdir ${LOCAL_DIR}/install_llt_dist
+ cp -r ${LOCAL_DIR}/install_llt/* ${LOCAL_DIR}/install_llt_dist
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_llt/* ${LOCAL_DIR}/install_llt_dist\" failed."
+ fi
+ rm -rf ${LOCAL_DIR}/install_llt_dist/share
+ rm ${LOCAL_DIR}/install_llt_dist/lib/liblz4.a
+ rm ${LOCAL_DIR}/install_llt_dist/bin/lz4c
+ rm ${LOCAL_DIR}/install_llt_dist/bin/lz4cat
+ rm ${LOCAL_DIR}/install_llt_dist/bin/unlz4
+ rm -rf ${LOCAL_DIR}/install_llt_dist/lib/pkgconfig
+ ;;
+ debug)
+ ;;
+ release_llt)
+ ;;
+ debug_llt)
+ ;;
+ *)
+ esac
+ log "[Notice] lz4 shrink using \"${COMPILE_TYPE}\" has been finished!"
+ done
+}
diff --git a/3rd/gstor/dependency/openssl/.gitignore b/3rd/gstor/dependency/openssl/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..3e8eb55161690677784f8c9e54a5f31e25e74732
--- /dev/null
+++ b/3rd/gstor/dependency/openssl/.gitignore
@@ -0,0 +1,4 @@
+install/
+openssl/
+openssl_src/
+
diff --git a/3rd/gstor/dependency/openssl/README.txt b/3rd/gstor/dependency/openssl/README.txt
new file mode 100644
index 0000000000000000000000000000000000000000..740913e2e079f548a554546ba5f79ffbe6661783
--- /dev/null
+++ b/3rd/gstor/dependency/openssl/README.txt
@@ -0,0 +1,12 @@
+open source target name openssl
+source code repository : product warehouse
+compile dependency: NULL
+upgrade open source package method
+----|pull command : python $(pwd)../../build/pull_open_source.py "path" "name" "id"
+ |----path : the parent directory name
+ |----namethe package name in product warehouse
+ |----idpdm version id
+the compile command : python build.py -m all -f openssl-1.1.1g.tar.gz -t "comm|llt"
+To meet the requirements of compiler security options, both comm and llt are required.
+comm is used to build lib and include files, and llt is used to build bin/openssl.
+Patch Info: None
\ No newline at end of file
diff --git a/3rd/gstor/dependency/openssl/build.py b/3rd/gstor/dependency/openssl/build.py
new file mode 100644
index 0000000000000000000000000000000000000000..da9194f35374c8d2ba6177e5be0f21a1d2f082c8
--- /dev/null
+++ b/3rd/gstor/dependency/openssl/build.py
@@ -0,0 +1,275 @@
+#!/usr/bin/env python
+# coding=utf-8
+# description: Python script for open source software build.
+# Copyright (c) 2020 Huawei Technologies Co.,Ltd.
+# date: 2020-06-08
+
+#-------------------------------------------------------------------------#
+#usage: #
+# python3/python build.py -m all -f openssl-1.1.1g.tar.gz -t "comm,llt" #
+# -m: build mode include all|build|shrink|dist|clean #
+# -t: build type include comm,llt,release,debug #
+# -f: tar file name #
+#-------------------------------------------------------------------------#
+
+import os
+import subprocess
+import sys
+import argparse
+
+#--------------------------------------------------------#
+# open source software build operator #
+#--------------------------------------------------------#
+
+openssl_source_dir = "openssl"
+
+class OPOperator():
+ def __init__(self, mode, filename, compile_types):
+ self.mode = mode
+ self.filename = filename
+ self.local_dir = os.getcwd()
+ self.compile_types = compile_types.split(',')
+ self.tmp_dir = os.getcwd()
+
+#--------------------------------------------------------#
+# parser build source code folder parameter #
+#--------------------------------------------------------#
+
+ def folder_parser(self):
+ ls_cmd = 'cd %s; ls ' % (self.local_dir)
+ file_str = os.popen(ls_cmd).read()
+ file_list = file_str.split('\n')
+ for pre_str in file_list:
+ if pre_str.find('.tar.gz') != -1:
+ source_code = pre_str.split(".tar", 1)
+ break
+ return source_code[0]
+
+#--------------------------------------------------------#
+# parser build patch parameter #
+#--------------------------------------------------------#
+
+ def patch_parser(self):
+ patch_list = []
+ ls_cmd = 'cd %s; ls ' % (self.local_dir)
+ file_str = os.popen(ls_cmd).read()
+ file_list = file_str.split('\n')
+ for pre_str in file_list:
+ if pre_str.find('patch') != -1:
+ patch_list.append(pre_str)
+ return patch_list
+
+#--------------------------------------------------------#
+# parser build mode parameter #
+#--------------------------------------------------------#
+
+ def build_mode(self):
+ # build mode
+ if self.mode == 'build':
+ self.build_component()
+ elif self.mode == 'all':
+ self.build_all()
+ elif self.mode == 'shrink':
+ self.shrink_component()
+ elif self.mode == 'clean':
+ self.clean_component()
+ elif self.mode == 'dist':
+ self.dist_component()
+ else:
+ print("[ERROR] Unrecognized build parameters, assert!")
+ assert False
+
+#--------------------------------------------------------#
+# error log handler #
+#--------------------------------------------------------#
+
+ def error_handler(self, ret):
+ if ret:
+ print("[ERROR] Invalid return code, exited")
+ assert False
+
+#--------------------------------------------------------#
+# build all mode #
+#--------------------------------------------------------#
+
+ def build_all(self):
+ self.build_component()
+ self.shrink_component()
+ self.dist_component()
+ # self.clean_component()
+
+#--------------------------------------------------------#
+# build component mode #
+#--------------------------------------------------------#
+
+ def build_component(self):
+ source_code_path = '%s/%s' % (self.local_dir, openssl_source_dir)
+ patch_list = self.patch_parser()
+
+ if not os.path.exists(source_code_path):
+ # tar open source package
+ tar_cmd = 'cd %s; mkdir -p "%s"; tar -zxvf %s -C "%s" --strip-components 1' % (self.local_dir, openssl_source_dir, self.filename, openssl_source_dir)
+ self.exe_cmd(tar_cmd, True)
+
+ # apply open source patch
+ if len(patch_list):
+ for pre_patch in patch_list:
+ self.exe_cmd('cd "%s"; patch -p1 < ../%s' % (source_code_path, pre_patch), True)
+
+ cpu_num = self.exe_cmd_get_output('grep -w processor /proc/cpuinfo|wc -l')
+
+ # compile source code type
+ for c_type in self.compile_types:
+ config_parameters = ''
+
+ if c_type == 'comm':
+ config_parameters = 'enable-ssl3-method -fPIC -shared -fstack-protector-strong -g -O2 -Wl,--build-id=none,-z,relro,-z,now,-z,noexecstack'
+
+ elif c_type == 'llt':
+ config_parameters = 'no-shared -fPIE -pie -fstack-protector-strong -g -O2 -Wl,--build-id=none,-z,relro,-z,now,-z,noexecstack'
+
+ elif c_type == 'release':
+ print ("[WARNING] Not supported build type. line=%d, c_type=%s" % (sys._getframe().f_lineno,c_type) )
+ break
+ elif c_type == 'debug':
+ print ("[WARNING] Not supported build type. line=%d, c_type=%s" % (sys._getframe().f_lineno,c_type) )
+ break
+ else:
+ print ("[WARNING] Not supported build type. line=%d, c_type=%s" % (sys._getframe().f_lineno,c_type) )
+ break
+
+ # deferent configuration parameter in compile types, copy srouce to deferent folder
+ src_rel_path = "%s_src/%s" % (openssl_source_dir, c_type)
+ src_abs_path = "%s/%s" % (self.local_dir, src_rel_path)
+
+ if not os.path.exists(src_abs_path):
+ self.exe_cmd('cd %s; mkdir -p %s; cp -r %s/* %s' % (self.local_dir, src_rel_path, openssl_source_dir, src_rel_path))
+
+ install_dir = self.local_dir + '/install/' + c_type
+ prepare_cmd = '[ -d "%s" ] || mkdir -p "%s"' % (install_dir, install_dir)
+ self.exe_cmd(prepare_cmd, True)
+
+ config_cmd = 'cd %s; ./config %s --prefix=%s --openssldir=%s' % (src_abs_path, config_parameters, install_dir, install_dir)
+ self.exe_cmd(config_cmd, True)
+
+ make_cmd = 'cd %s; make -j%s && make install' % (src_abs_path, cpu_num)
+ self.exe_cmd(make_cmd, True)
+ # finish compile
+ print ("[INFO] Build component finished")
+
+#--------------------------------------------------------#
+# copy open source component for using mode #
+#--------------------------------------------------------#
+
+ def shrink_component(self):
+ # shrink source code type
+ self.exe_cmd('mkdir -p %s/install_comm_dist' % (self.local_dir), True)
+
+ for c_type in self.compile_types:
+ if c_type == 'comm':
+ self.exe_cmd('cp -r %s/install/comm/include %s/install_comm_dist' % (self.local_dir, self.local_dir))
+ self.exe_cmd('cp -r %s/install/comm/lib %s/install_comm_dist' % (self.local_dir, self.local_dir))
+ elif c_type == 'llt':
+ self.exe_cmd('cp -r %s/install/llt/bin %s/install_comm_dist' % (self.local_dir, self.local_dir))
+ elif c_type == 'release':
+ print ("[WARNING] Not supported build type. line=%d, c_type=%s" % (sys._getframe().f_lineno,c_type) )
+ elif c_type == 'debug':
+ print ("[WARNING] Not supported build type. line=%d, c_type=%s" % (sys._getframe().f_lineno,c_type) )
+ else:
+ print ("[WARNING] Not supported build type. line=%d, c_type=%s" % (sys._getframe().f_lineno,c_type) )
+
+ self.exe_cmd('mv %s/install_comm_dist/lib/libssl.a %s/install_comm_dist/lib/libssl_static.a' % (self.local_dir, self.local_dir))
+ self.exe_cmd('mv %s/install_comm_dist/lib/libcrypto.a %s/install_comm_dist/lib/libcrypto_static.a' % (self.local_dir, self.local_dir))
+ self.exe_cmd('rm -rf %s/install_comm_dist/lib/engines-1.1 %s/install_comm_dist/lib/pkgconfig %s/install_comm_dist/bin/c_rehash' % (self.local_dir, self.local_dir, self.local_dir))
+ self.exe_cmd('chmod -x %s/install_comm_dist/lib/lib*.so.1.1' % (self.local_dir))
+ # finish shrink
+ print ("[INFO] Shrink component finished")
+
+#--------------------------------------------------------#
+# move need component into matched platform binary path #
+#--------------------------------------------------------#
+
+ def dist_component(self):
+ install_path = '%s/../../output/kernel/dependency/openssl' % (self.local_dir)
+ comm_path = "%s/comm" % install_path
+ llt_path = "%s/llt" % install_path
+ if not os.path.exists(install_path):
+ os.makedirs(comm_path)
+ os.makedirs(llt_path)
+ # move source code type
+ for c_type in self.compile_types:
+ if c_type == 'comm':
+ self.exe_cmd('rm -rf %s/comm/bin/* %s/comm/include/* %s/comm/lib/*' % (install_path, install_path, install_path))
+ self.exe_cmd('cp -r %s/install_comm_dist/* %s/comm/' % (self.local_dir, install_path))
+ elif c_type == 'llt':
+ self.exe_cmd('rm -rf %s/llt/bin/* %s/llt/include/* %s/llt/lib/*' % (install_path, install_path, install_path))
+ self.exe_cmd('cp -r %s/install_comm_dist/* %s/llt/' % (self.local_dir, install_path))
+ elif c_type == 'release':
+ print ("[WARNING] Not supported build type. line=%d, c_type=%s" % (sys._getframe().f_lineno,c_type) )
+ elif c_type == 'debug':
+ print ("[WARNING] Not supported build type. line=%d, c_type=%s" % (sys._getframe().f_lineno,c_type) )
+ else:
+ print ("[WARNING] Not supported build type. line=%d, c_type=%s" % (sys._getframe().f_lineno,c_type) )
+ # finish dist
+ print ("[INFO] Dist component finished")
+
+#--------------------------------------------------------#
+# clean component mode #
+#--------------------------------------------------------#
+
+ def clean_component(self):
+ source_code_path = openssl_source_dir
+ # clean source code
+ self.exe_cmd('cd %s/%s; make clean' % (self.local_dir, source_code_path), True)
+
+ self.exe_cmd('cd %s; rm -rf %s; rm -rf install; rm -rf install_comm_dist; rm -rf openssl_src' \
+ % (self.local_dir, source_code_path)
+ , True)
+
+ # finish clean
+ print ("[INFO] Clean component finished")
+
+#--------------------------------------------------------#
+# base interface for executing command #
+#--------------------------------------------------------#
+
+ def exe_cmd(self, cmd, is_handle_error=False):
+ if sys.version_info < (3, 5):
+ ret = subprocess.call(cmd, shell = True)
+ else:
+ run_tsk = subprocess.run(cmd, shell = True, check = True)
+ ret = run_tsk.returncode
+ if is_handle_error:
+ self.error_handler(ret)
+ return ret
+
+ def exe_cmd_get_output(self, cmd):
+ status, output = subprocess.getstatusoutput(cmd)
+ self.error_handler(status)
+ return output.strip()
+
+
+#--------------------------------------------------------#
+# build script operator parameter parser #
+#--------------------------------------------------------#
+
+def parse_args():
+ parser = argparse.ArgumentParser(description='GaussDB Kernel open source software build script')
+
+ parser.add_argument('-m', '--mode', type=str, required=True,
+ help='build mode set, all|build|shrink|dist|clean')
+ parser.add_argument('-f', '--filename', type=str, required=True,
+ help='file name set')
+ parser.add_argument('-t', '--compile_types', type=str, required=True,
+ help='compile type set "comm,llt,release,debug"')
+ return parser.parse_args()
+
+#--------------------------------------------------------#
+# main function #
+#--------------------------------------------------------#
+
+if __name__ == '__main__':
+ args = parse_args()
+ Operator = OPOperator(mode = args.mode, filename = args.filename, compile_types = args.compile_types)
+ Operator.build_mode()
+
diff --git a/3rd/gstor/dependency/openssl/openssl-OpenSSL_1_1_1n.tar.gz b/3rd/gstor/dependency/openssl/openssl-OpenSSL_1_1_1n.tar.gz
new file mode 100644
index 0000000000000000000000000000000000000000..8f0613137770c5d10ce4786e3d4b6bcc4b27cae8
Binary files /dev/null and b/3rd/gstor/dependency/openssl/openssl-OpenSSL_1_1_1n.tar.gz differ
diff --git a/3rd/gstor/dependency/openssl/openssl.patch b/3rd/gstor/dependency/openssl/openssl.patch
new file mode 100644
index 0000000000000000000000000000000000000000..29dbe6e31b27cdeae4015a5448100e1ba06c2135
--- /dev/null
+++ b/3rd/gstor/dependency/openssl/openssl.patch
@@ -0,0 +1,488 @@
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' openssl/test/certs/embeddedSCTs1_issuer-key.pem openssl_h3/test/certs/embeddedSCTs1_issuer-key.pem
+*** openssl/test/certs/embeddedSCTs1_issuer-key.pem 1970-01-01 08:00:00.000000000 +0800
+--- openssl_h3/test/certs/embeddedSCTs1_issuer-key.pem 2022-08-26 11:49:22.296000000 +0800
+***************
+*** 0 ****
+--- 1,15 ----
++ -----BEGIN RSA PRIVATE KEY-----
++ MIICXAIBAAKBgQDVimhTYhCicRmTbneDIRgcKkATxtB7jHbrkVfT0PtLO1FuzsvR
++ yY2RxS90P6tjXVUJnNE6uvMa5UFEJFGnTHgW8iQ8+EjPKDHM5nugSlojgZ88ujfm
++ JNnDvbKZuDnd/iYx0ss6hPx7srXFL8/BT/9Ab1zURmnLsvfP34b7arnRsQIDAQAB
++ AoGAJLR6xEJp+5IXRFlLn7WTkFvO0ddtxJ7bXhiIkTctyruyfqp7LF9Jv1G2m3PK
++ QPUtBc73w/GYkfnwIwdfJbOmPHL7XyEGHZYmEXgIgEtw6LXvAv0G5JpUnNwsSBfL
++ GfSQqI5Z5ytyzlJXkMcTGA2kTgNAYc73h4EnU+pwUnDPdAECQQD2aj+4LtYk1XPq
++ r3gjgI6MoGvgYJfPmAtZhxxVbhXQKciFUCAcBiwlQdHIdLWE9j65ctmZRWidKifr
++ 4O4nz+TBAkEA3djNW/rTQq5fKZy+mCF1WYnIU/3yhJaptzRqLm7AHqe7+hdrGXJw
++ +mCtU8T3L/Ms8bH1yFBZhmkp1PbR8gl48QJAQo70YyWThiN5yfxXcQ96cZWrTdIJ
++ b3NcLXSHPLQdhDqlBQ1dfvRT3ERpC8IqfZ2d162kBPhwh3MpkVcSPQK0gQJAC/dY
++ xGBYKt2a9nSk9zG+0bCT5Kvq++ngh6hFHfINXNnxUsEWns3EeEzkrIMQTj7QqszN
++ lBt5aL2dawZRNrv6EQJBAOo4STF9KEwQG0HLC/ryh1FeB0OBA5yIepXze+eJVKei
++ T0cCECOQJKfWHEzYJYDJhyEFF/sYp9TXwKSDjOifrsU=
++ -----END RSA PRIVATE KEY-----
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' openssl/test/certs/embeddedSCTs1_issuer.pem openssl_h3/test/certs/embeddedSCTs1_issuer.pem
+*** openssl/test/certs/embeddedSCTs1_issuer.pem 2022-08-26 11:49:44.720000000 +0800
+--- openssl_h3/test/certs/embeddedSCTs1_issuer.pem 2022-08-26 11:49:22.296000000 +0800
+***************
+*** 1,18 ****
+ -----BEGIN CERTIFICATE-----
+! MIIC0DCCAjmgAwIBAgIBADANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJHQjEk
+ MCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENBMQ4wDAYDVQQIEwVX
+! YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAeFw0xMjA2MDEwMDAwMDBaFw0yMjA2MDEw
+! MDAwMDBaMFUxCzAJBgNVBAYTAkdCMSQwIgYDVQQKExtDZXJ0aWZpY2F0ZSBUcmFu
+! c3BhcmVuY3kgQ0ExDjAMBgNVBAgTBVdhbGVzMRAwDgYDVQQHEwdFcncgV2VuMIGf
+! MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVimhTYhCicRmTbneDIRgcKkATxtB7
+! jHbrkVfT0PtLO1FuzsvRyY2RxS90P6tjXVUJnNE6uvMa5UFEJFGnTHgW8iQ8+EjP
+! KDHM5nugSlojgZ88ujfmJNnDvbKZuDnd/iYx0ss6hPx7srXFL8/BT/9Ab1zURmnL
+! svfP34b7arnRsQIDAQABo4GvMIGsMB0GA1UdDgQWBBRfnYgNyHPmVNT4DdjmsMEk
+! tEfDVTB9BgNVHSMEdjB0gBRfnYgNyHPmVNT4DdjmsMEktEfDVaFZpFcwVTELMAkG
+! A1UEBhMCR0IxJDAiBgNVBAoTG0NlcnRpZmljYXRlIFRyYW5zcGFyZW5jeSBDQTEO
+! MAwGA1UECBMFV2FsZXMxEDAOBgNVBAcTB0VydyBXZW6CAQAwDAYDVR0TBAUwAwEB
+! /zANBgkqhkiG9w0BAQUFAAOBgQAGCMxKbWTyIF4UbASydvkrDvqUpdryOvw4BmBt
+! OZDQoeojPUApV2lGOwRmYef6HReZFSCa6i4Kd1F2QRIn18ADB8dHDmFYT9czQiRy
+! f1HWkLxHqd81TbD26yWVXeGJPE3VICskovPkQNJ0tU4b03YmnKliibduyqQQkOFP
+! OwqULg==
+ -----END CERTIFICATE-----
+--- 1,18 ----
+ -----BEGIN CERTIFICATE-----
+! MIIC0jCCAjugAwIBAgIBADANBgkqhkiG9w0BAQsFADBVMQswCQYDVQQGEwJHQjEk
+ MCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENBMQ4wDAYDVQQIEwVX
+! YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAgFw0yMjA2MDExMDM4MDJaGA8yMTIyMDUw
+! ODEwMzgwMlowVTELMAkGA1UEBhMCR0IxJDAiBgNVBAoTG0NlcnRpZmljYXRlIFRy
+! YW5zcGFyZW5jeSBDQTEOMAwGA1UECBMFV2FsZXMxEDAOBgNVBAcTB0VydyBXZW4w
+! gZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANWKaFNiEKJxGZNud4MhGBwqQBPG
+! 0HuMduuRV9PQ+0s7UW7Oy9HJjZHFL3Q/q2NdVQmc0Tq68xrlQUQkUadMeBbyJDz4
+! SM8oMczme6BKWiOBnzy6N+Yk2cO9spm4Od3+JjHSyzqE/HuytcUvz8FP/0BvXNRG
+! acuy98/fhvtqudGxAgMBAAGjga8wgawwHQYDVR0OBBYEFF+diA3Ic+ZU1PgN2Oaw
+! wSS0R8NVMH0GA1UdIwR2MHSAFF+diA3Ic+ZU1PgN2OawwSS0R8NVoVmkVzBVMQsw
+! CQYDVQQGEwJHQjEkMCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENB
+! MQ4wDAYDVQQIEwVXYWxlczEQMA4GA1UEBxMHRXJ3IFdlboIBADAMBgNVHRMEBTAD
+! AQH/MA0GCSqGSIb3DQEBCwUAA4GBAD0aYh9OkFYfXV7kBfhrtD0PJG2U47OV/1qq
+! +uFpqB0S1WO06eJT0pzYf1ebUcxjBkajbJZm/FHT85VthZ1lFHsky87aFD8XlJCo
+! 2IOhKOkvvWKPUdFLoO/ZVXqEVKkcsS1eXK1glFvb07eJZya3JVG0KdMhV2YoDg6c
+! Doud4XrO
+ -----END CERTIFICATE-----
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' openssl/test/certs/embeddedSCTs1-key.pem openssl_h3/test/certs/embeddedSCTs1-key.pem
+*** openssl/test/certs/embeddedSCTs1-key.pem 2022-08-26 11:49:44.720000000 +0800
+--- openssl_h3/test/certs/embeddedSCTs1-key.pem 2022-08-26 11:49:22.296000000 +0800
+***************
+*** 1,15 ****
+ -----BEGIN RSA PRIVATE KEY-----
+! MIICWwIBAAKBgQC+75jnwmh3rjhfdTJaDB0ym+3xj6r015a/BH634c4VyVui+A7k
+! WL19uG+KSyUhkaeb1wDDjpwDibRc1NyaEgqyHgy0HNDnKAWkEM2cW9tdSSdyba8X
+! EPYBhzd+olsaHjnu0LiBGdwVTcaPfajjDK8VijPmyVCfSgWwFAn/Xdh+tQIDAQAB
+! AoGAK/daG0vt6Fkqy/hdrtSJSKUVRoGRmS2nnba4Qzlwzh1+x2kdbMFuaOu2a37g
+! PvmeQclheKZ3EG1+Jb4yShwLcBCV6pkRJhOKuhvqGnjngr6uBH4gMCjpZVj7GDMf
+! flYHhdJCs3Cz/TY0wKN3o1Fldil2DHR/AEOc1nImeSp5/EUCQQDjKS3W957kYtTU
+! X5BeRjvg03Ug8tJq6IFuhTFvUJ+XQ5bAc0DmxAbQVKqRS7Wje59zTknVvS+MFdeQ
+! pz4dGuV7AkEA1y0X2yarIls+0A/S1uwkvwRTIkfS+QwFJ1zVya8sApRdKAcidIzA
+! b70hkKLilU9+LrXg5iZdFp8l752qJiw9jwJAXjItN/7mfH4fExGto+or2kbVQxxt
+! 9LcFNPc2UJp2ExuL37HrL8YJrUnukOF8KJaSwBWuuFsC5GwKP4maUCdfEQJAUwBR
+! 83c3DEmmMRvpeH4erpA8gTyzZN3+HvDwhpvLnjMcvBQEdnDUykVqbSBnxrCjO+Fs
+! n1qtDczWFVf8Cj2GgQJAQ14Awx32Cn9sF+3M+sEVtlAf6CqiEbkYeYdSCbsplMmZ
+! 1UoaxiwXY3z+B7epsRnnPR3KaceAlAxw2/zQJMFNOQ==
+ -----END RSA PRIVATE KEY-----
+--- 1,27 ----
+ -----BEGIN RSA PRIVATE KEY-----
+! MIIEpQIBAAKCAQEAuIjpA4/iCpDA2mjywI5zG6IBX6bNcRQYDsB7Cv0VonNXtJBw
+! XxMENP4jVpvEmWpJ5iMBknGHV+XWBkngYapczIsY4LGn6aMU6ySABBVQpNOQSRfT
+! 48xGGPR9mzOBG/yplmpFOVq1j+b65lskvAXKYaLFpFn3oY/pBSdcCNBP8LypVXAJ
+! b3IqEXsBL/ErgHG9bgIRP8VxBAaryCz77kLzAXkfHL2LfSGIfNONyEKB3xI94S4L
+! eouOSoWL1VkEfJs87vG4G5xoXw3KOHyiueQUUlMnu8p+Bx0xPVKPEsLje3R9k0rG
+! a5ca7dXAn9UypKKp25x4NXpnjGX5txVEYfNvqQIDAQABAoIBAE0zqhh9Z5n3+Vbm
+! tTht4CZdXqm/xQ9b0rzJNjDgtN5j1vuJuhlsgUQSVoJzZIqydvw7BPtZV8AkPagf
+! 3Cm/9lb0kpHegVsziRrfCFes+zIZ+LE7sMAKxADIuIvnvkoRKHnvN8rI8lCj16/r
+! zbCD06mJSZp6sSj8ZgZr8wsU63zRGt1TeGM67uVW4agphfzuKGlXstPLsSMwknpF
+! nxFS2TYbitxa9oH76oCpEk5fywYsYgUP4TdzOzfVAgMzNSu0FobvWl0CECB+G3RQ
+! XQ5VWbYkFoj5XbE5kYz6sYHMQWL1NQpglUp+tAQ1T8Nca0CvbSpD77doRGm7UqYw
+! ziVQKokCgYEA6BtHwzyD1PHdAYtOcy7djrpnIMaiisSxEtMhctoxg8Vr2ePEvMpZ
+! S1ka8A1Pa9GzjaUk+VWKWsTf+VkmMHGtpB1sv8S7HjujlEmeQe7p8EltjstvLDmi
+! BhAA7ixvZpXXjQV4GCVdUVu0na6gFGGueZb2FHEXB8j1amVwleJj2lcCgYEAy4f3
+! 2wXqJfz15+YdJPpG9BbH9d/plKJm5ID3p2ojAGo5qvVuIJMNJA4elcfHDwzCWVmn
+! MtR/WwtxYVVmy1BAnmk6HPSYc3CStvv1800vqN3fyJWtZ1P+8WBVZWZzIQdjdiaU
+! JSRevPnjQGc+SAZQQIk1yVclbz5790yuXsdIxf8CgYEApqlABC5lsvfga4Vt1UMn
+! j57FAkHe4KmPRCcZ83A88ZNGd/QWhkD9kR7wOsIz7wVqWiDkxavoZnjLIi4jP9HA
+! jwEZ3zER8wl70bRy0IEOtZzj8A6fSzAu6Q+Au4RokU6yse3lZ+EcepjQvhBvnXLu
+! ZxxAojj6AnsHzVf9WYJvlI0CgYEAoATIw/TEgRV/KNHs/BOiEWqP0Co5dVix2Nnk
+! 3EVAO6VIrbbE3OuAm2ZWeaBWSujXLHSmVfpoHubCP6prZVI1W9aTkAxmh+xsDV3P
+! o3h+DiBTP1seuGx7tr7spQqFXeR3OH9gXktYCO/W0d3aQ7pjAjpehWv0zJ+ty2MI
+! fQ/lkXUCgYEAgbP+P5UmY7Fqm/mi6TprEJ/eYktji4Ne11GDKGFQCfjF5RdKhdw1
+! 5+elGhZes+cpzu5Ak6zBDu4bviT+tRTWJu5lVLEzlHHv4nAU7Ks5Aj67ApH21AnP
+! RtlATdhWOt5Dkdq1WSpDfz5bvWgvyBx9D66dSmQdbKKe2dH327eQll4=
+ -----END RSA PRIVATE KEY-----
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' openssl/test/certs/embeddedSCTs1.pem openssl_h3/test/certs/embeddedSCTs1.pem
+*** openssl/test/certs/embeddedSCTs1.pem 2022-08-26 11:49:44.720000000 +0800
+--- openssl_h3/test/certs/embeddedSCTs1.pem 2022-08-26 11:49:22.296000000 +0800
+***************
+*** 1,20 ****
+ -----BEGIN CERTIFICATE-----
+! MIIDWTCCAsKgAwIBAgIBBzANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJHQjEk
+ MCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENBMQ4wDAYDVQQIEwVX
+! YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAeFw0xMjA2MDEwMDAwMDBaFw0yMjA2MDEw
+! MDAwMDBaMFIxCzAJBgNVBAYTAkdCMSEwHwYDVQQKExhDZXJ0aWZpY2F0ZSBUcmFu
+! c3BhcmVuY3kxDjAMBgNVBAgTBVdhbGVzMRAwDgYDVQQHEwdFcncgV2VuMIGfMA0G
+! CSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+75jnwmh3rjhfdTJaDB0ym+3xj6r015a/
+! BH634c4VyVui+A7kWL19uG+KSyUhkaeb1wDDjpwDibRc1NyaEgqyHgy0HNDnKAWk
+! EM2cW9tdSSdyba8XEPYBhzd+olsaHjnu0LiBGdwVTcaPfajjDK8VijPmyVCfSgWw
+! FAn/Xdh+tQIDAQABo4IBOjCCATYwHQYDVR0OBBYEFCAxVBryXAX/2GWLaEN5T16Q
+! Nve0MH0GA1UdIwR2MHSAFF+diA3Ic+ZU1PgN2OawwSS0R8NVoVmkVzBVMQswCQYD
+! VQQGEwJHQjEkMCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENBMQ4w
+! DAYDVQQIEwVXYWxlczEQMA4GA1UEBxMHRXJ3IFdlboIBADAJBgNVHRMEAjAAMIGK
+! BgorBgEEAdZ5AgQCBHwEegB4AHYA3xwuwRUAlFJHqWFoMl3cXHlZ6PfG04j8AC4L
+! vT9012QAAAE92yffkwAABAMARzBFAiBIL2dRrzXbplQ2vh/WZA89v5pBQpSVkkUw
+! KI+j5eI+BgIhAOTtwNs6xXKx4vXoq2poBlOYfc9BAn3+/6EFUZ2J7b8IMA0GCSqG
+! SIb3DQEBBQUAA4GBAIoMS+8JnUeSea+goo5on5HhxEIb4tJpoupspOghXd7dyhUE
+! oR58h8S3foDw6XkDUmjyfKIOFmgErlVvMWmB+Wo5Srer/T4lWsAERRP+dlcMZ5Wr
+! 5HAxM9MD+J86+mu8/FFzGd/ZW5NCQSEfY0A1w9B4MHpoxgdaLiDInza4kQyg
+ -----END CERTIFICATE-----
+--- 1,21 ----
+ -----BEGIN CERTIFICATE-----
+! MIIDeDCCAuGgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBVMQswCQYDVQQGEwJHQjEk
+ MCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENBMQ4wDAYDVQQIEwVX
+! YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAgFw0yMDAxMjUxMTUwMTNaGA8yMTIwMDEy
+! NjExNTAxM1owGTEXMBUGA1UEAwwOc2VydmVyLmV4YW1wbGUwggEiMA0GCSqGSIb3
+! DQEBAQUAA4IBDwAwggEKAoIBAQC4iOkDj+IKkMDaaPLAjnMbogFfps1xFBgOwHsK
+! /RWic1e0kHBfEwQ0/iNWm8SZaknmIwGScYdX5dYGSeBhqlzMixjgsafpoxTrJIAE
+! FVCk05BJF9PjzEYY9H2bM4Eb/KmWakU5WrWP5vrmWyS8BcphosWkWfehj+kFJ1wI
+! 0E/wvKlVcAlvcioRewEv8SuAcb1uAhE/xXEEBqvILPvuQvMBeR8cvYt9IYh8043I
+! QoHfEj3hLgt6i45KhYvVWQR8mzzu8bgbnGhfDco4fKK55BRSUye7yn4HHTE9Uo8S
+! wuN7dH2TSsZrlxrt1cCf1TKkoqnbnHg1emeMZfm3FURh82+pAgMBAAGjggEMMIIB
+! CDAdBgNVHQ4EFgQUtMa8XD5ylrF9AqCdnPEhXa63H2owHwYDVR0jBBgwFoAUX52I
+! Dchz5lTU+A3Y5rDBJLRHw1UwCQYDVR0TBAIwADATBgNVHSUEDDAKBggrBgEFBQcD
+! ATCBigYKKwYBBAHWeQIEAgR8BHoAeAB2AN8cLsEVAJRSR6lhaDJd3Fx5Wej3xtOI
+! /AAuC70/dNdkAAABb15m6AAAAAQDAEcwRQIgfDPo8RArm/vcSEZ608Q1u+XQ55QB
+! u67SZEuZxLpbUM0CIQDRsgcTud4PDy8Cgg+lHeAS7UxgSKBbWAznYOuorwNewzAZ
+! BgNVHREEEjAQgg5zZXJ2ZXIuZXhhbXBsZTANBgkqhkiG9w0BAQsFAAOBgQCWFKKR
+! RNkDRzB25NK07OLkbzebhnpKtbP4i3blRx1HAvTSamf/3uuHI7kfiPJorJymJpT1
+! IuJvSVKyMu1qONWBimiBfiyGL7+le1izHEJIP5lVTbddfzSIBIvrlHHcWIOL3H+W
+! YT6yTEIzJuO07Xp61qnB1CE2TrinUWlyC46Zkw==
+ -----END CERTIFICATE-----
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' openssl/test/certs/embeddedSCTs1.sct openssl_h3/test/certs/embeddedSCTs1.sct
+*** openssl/test/certs/embeddedSCTs1.sct 2022-08-26 11:49:44.720000000 +0800
+--- openssl_h3/test/certs/embeddedSCTs1.sct 2022-08-26 11:49:22.296000000 +0800
+***************
+*** 2,12 ****
+ Version : v1 (0x0)
+ Log ID : DF:1C:2E:C1:15:00:94:52:47:A9:61:68:32:5D:DC:5C:
+ 79:59:E8:F7:C6:D3:88:FC:00:2E:0B:BD:3F:74:D7:64
+! Timestamp : Apr 5 17:04:16.275 2013 GMT
+ Extensions: none
+ Signature : ecdsa-with-SHA256
+! 30:45:02:20:48:2F:67:51:AF:35:DB:A6:54:36:BE:1F:
+! D6:64:0F:3D:BF:9A:41:42:94:95:92:45:30:28:8F:A3:
+! E5:E2:3E:06:02:21:00:E4:ED:C0:DB:3A:C5:72:B1:E2:
+! F5:E8:AB:6A:68:06:53:98:7D:CF:41:02:7D:FE:FF:A1:
+! 05:51:9D:89:ED:BF:08
+\ No newline at end of file
+--- 2,12 ----
+ Version : v1 (0x0)
+ Log ID : DF:1C:2E:C1:15:00:94:52:47:A9:61:68:32:5D:DC:5C:
+ 79:59:E8:F7:C6:D3:88:FC:00:2E:0B:BD:3F:74:D7:64
+! Timestamp : Jan 1 00:00:00.000 2020 GMT
+ Extensions: none
+ Signature : ecdsa-with-SHA256
+! 30:45:02:20:7C:33:E8:F1:10:2B:9B:FB:DC:48:46:7A:
+! D3:C4:35:BB:E5:D0:E7:94:01:BB:AE:D2:64:4B:99:C4:
+! BA:5B:50:CD:02:21:00:D1:B2:07:13:B9:DE:0F:0F:2F:
+! 02:82:0F:A5:1D:E0:12:ED:4C:60:48:A0:5B:58:0C:E7:
+! 60:EB:A8:AF:03:5E:C3
+\ No newline at end of file
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' openssl/test/ct_test.c openssl_h3/test/ct_test.c
+*** openssl/test/ct_test.c 2022-08-26 11:49:44.728000000 +0800
+--- openssl_h3/test/ct_test.c 2022-08-26 11:49:22.304000000 +0800
+***************
+*** 63,69 ****
+ if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
+ goto end;
+ fixture->test_case_name = test_case_name;
+! fixture->epoch_time_in_ms = 1473269626000ULL; /* Sep 7 17:33:46 2016 GMT */
+ if (!TEST_ptr(fixture->ctlog_store = CTLOG_STORE_new())
+ || !TEST_int_eq(
+ CTLOG_STORE_load_default_file(fixture->ctlog_store), 1))
+--- 63,69 ----
+ if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
+ goto end;
+ fixture->test_case_name = test_case_name;
+! fixture->epoch_time_in_ms = 1580335307000ULL; /* Wed 29 Jan 2020 10:01:47 PM UTC */
+ if (!TEST_ptr(fixture->ctlog_store = CTLOG_STORE_new())
+ || !TEST_int_eq(
+ CTLOG_STORE_load_default_file(fixture->ctlog_store), 1))
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' openssl/tools/c_rehash.in openssl_h3/tools/c_rehash.in
+*** openssl/tools/c_rehash.in 2022-08-26 11:49:44.860000000 +0800
+--- openssl_h3/tools/c_rehash.in 2022-08-26 11:49:22.452000000 +0800
+***************
+*** 104,157 ****
+ }
+ exit($errorcount);
+
+ sub hash_dir {
+! my %hashlist;
+! print "Doing $_[0]\n";
+! chdir $_[0];
+! opendir(DIR, ".");
+! my @flist = sort readdir(DIR);
+! closedir DIR;
+! if ( $removelinks ) {
+! # Delete any existing symbolic links
+! foreach (grep {/^[\da-f]+\.r{0,1}\d+$/} @flist) {
+! if (-l $_) {
+! print "unlink $_" if $verbose;
+! unlink $_ || warn "Can't unlink $_, $!\n";
+! }
+! }
+! }
+! FILE: foreach $fname (grep {/\.(pem)|(crt)|(cer)|(crl)$/} @flist) {
+! # Check to see if certificates and/or CRLs present.
+! my ($cert, $crl) = check_file($fname);
+! if (!$cert && !$crl) {
+! print STDERR "WARNING: $fname does not contain a certificate or CRL: skipping\n";
+! next;
+! }
+! link_hash_cert($fname) if ($cert);
+! link_hash_crl($fname) if ($crl);
+! }
+ }
+
+ sub check_file {
+! my ($is_cert, $is_crl) = (0,0);
+! my $fname = $_[0];
+! open IN, $fname;
+! while() {
+! if (/^-----BEGIN (.*)-----/) {
+! my $hdr = $1;
+! if ($hdr =~ /^(X509 |TRUSTED |)CERTIFICATE$/) {
+! $is_cert = 1;
+! last if ($is_crl);
+! } elsif ($hdr eq "X509 CRL") {
+! $is_crl = 1;
+! last if ($is_cert);
+! }
+! }
+! }
+! close IN;
+! return ($is_cert, $is_crl);
+ }
+
+
+ # Link a certificate to its subject name hash value, each hash is of
+ # the form . where n is an integer. If the hash value already exists
+--- 104,200 ----
+ }
+ exit($errorcount);
+
++ sub copy_file {
++ my ($src_fname, $dst_fname) = @_;
++
++ if (open(my $in, "<", $src_fname)) {
++ if (open(my $out, ">", $dst_fname)) {
++ print $out $_ while (<$in>);
++ close $out;
++ } else {
++ warn "Cannot open $dst_fname for write, $!";
++ }
++ close $in;
++ } else {
++ warn "Cannot open $src_fname for read, $!";
++ }
++ }
++
+ sub hash_dir {
+! my $dir = shift;
+! my %hashlist;
+!
+! print "Doing $dir\n";
+!
+! if (!chdir $dir) {
+! print STDERR "WARNING: Cannot chdir to '$dir', $!\n";
+! return;
+! }
+!
+! opendir(DIR, ".") || print STDERR "WARNING: Cannot opendir '.', $!\n";
+! my @flist = sort readdir(DIR);
+! closedir DIR;
+! if ( $removelinks ) {
+! # Delete any existing symbolic links
+! foreach (grep {/^[\da-f]+\.r{0,1}\d+$/} @flist) {
+! if (-l $_) {
+! print "unlink $_\n" if $verbose;
+! unlink $_ || warn "Can't unlink $_, $!\n";
+! }
+! }
+! }
+! FILE: foreach $fname (grep {/\.(pem)|(crt)|(cer)|(crl)$/} @flist) {
+! # Check to see if certificates and/or CRLs present.
+! my ($cert, $crl) = check_file($fname);
+! if (!$cert && !$crl) {
+! print STDERR "WARNING: $fname does not contain a certificate or CRL: skipping\n";
+! next;
+! }
+! link_hash_cert($fname) if ($cert);
+! link_hash_crl($fname) if ($crl);
+! }
+!
+! chdir $pwd;
+ }
+
+ sub check_file {
+! my ($is_cert, $is_crl) = (0,0);
+! my $fname = $_[0];
+!
+! open(my $in, "<", $fname);
+! while(<$in>) {
+! if (/^-----BEGIN (.*)-----/) {
+! my $hdr = $1;
+! if ($hdr =~ /^(X509 |TRUSTED |)CERTIFICATE$/) {
+! $is_cert = 1;
+! last if ($is_crl);
+! } elsif ($hdr eq "X509 CRL") {
+! $is_crl = 1;
+! last if ($is_cert);
+! }
+! }
+! }
+! close $in;
+! return ($is_cert, $is_crl);
+ }
+
++ sub compute_hash {
++ my $fh;
++ if ( $^O eq "VMS" ) {
++ # VMS uses the open through shell
++ # The file names are safe there and list form is unsupported
++ if (!open($fh, "-|", join(' ', @_))) {
++ print STDERR "Cannot compute hash on '$fname'\n";
++ return;
++ }
++ } else {
++ if (!open($fh, "-|", @_)) {
++ print STDERR "Cannot compute hash on '$fname'\n";
++ return;
++ }
++ }
++ return (<$fh>, <$fh>);
++ }
+
+ # Link a certificate to its subject name hash value, each hash is of
+ # the form . where n is an integer. If the hash value already exists
+***************
+*** 160,231 ****
+ # certificate fingerprints
+
+ sub link_hash_cert {
+! my $fname = $_[0];
+! $fname =~ s/\"/\\\"/g;
+! my ($hash, $fprint) = `"$openssl" x509 $x509hash -fingerprint -noout -in "$fname"`;
+! chomp $hash;
+! chomp $fprint;
+! $fprint =~ s/^.*=//;
+! $fprint =~ tr/://d;
+! my $suffix = 0;
+! # Search for an unused hash filename
+! while(exists $hashlist{"$hash.$suffix"}) {
+! # Hash matches: if fingerprint matches its a duplicate cert
+! if ($hashlist{"$hash.$suffix"} eq $fprint) {
+! print STDERR "WARNING: Skipping duplicate certificate $fname\n";
+! return;
+! }
+! $suffix++;
+! }
+! $hash .= ".$suffix";
+! if ($symlink_exists) {
+! print "link $fname -> $hash\n" if $verbose;
+! symlink $fname, $hash || warn "Can't symlink, $!";
+! } else {
+! print "copy $fname -> $hash\n" if $verbose;
+! if (open($in, "<", $fname)) {
+! if (open($out,">", $hash)) {
+! print $out $_ while (<$in>);
+! close $out;
+! } else {
+! warn "can't open $hash for write, $!";
+! }
+! close $in;
+! } else {
+! warn "can't open $fname for read, $!";
+! }
+! }
+! $hashlist{$hash} = $fprint;
+ }
+
+ # Same as above except for a CRL. CRL links are of the form .r
+
+ sub link_hash_crl {
+! my $fname = $_[0];
+! $fname =~ s/'/'\\''/g;
+! my ($hash, $fprint) = `"$openssl" crl $crlhash -fingerprint -noout -in '$fname'`;
+! chomp $hash;
+! chomp $fprint;
+! $fprint =~ s/^.*=//;
+! $fprint =~ tr/://d;
+! my $suffix = 0;
+! # Search for an unused hash filename
+! while(exists $hashlist{"$hash.r$suffix"}) {
+! # Hash matches: if fingerprint matches its a duplicate cert
+! if ($hashlist{"$hash.r$suffix"} eq $fprint) {
+! print STDERR "WARNING: Skipping duplicate CRL $fname\n";
+! return;
+! }
+! $suffix++;
+! }
+! $hash .= ".r$suffix";
+! if ($symlink_exists) {
+! print "link $fname -> $hash\n" if $verbose;
+! symlink $fname, $hash || warn "Can't symlink, $!";
+! } else {
+! print "cp $fname -> $hash\n" if $verbose;
+! system ("cp", $fname, $hash);
+! warn "Can't copy, $!" if ($? >> 8) != 0;
+! }
+! $hashlist{$hash} = $fprint;
+ }
+--- 203,250 ----
+ # certificate fingerprints
+
+ sub link_hash_cert {
+! link_hash($_[0], 'cert');
+ }
+
+ # Same as above except for a CRL. CRL links are of the form .r
+
+ sub link_hash_crl {
+! link_hash($_[0], 'crl');
+! }
+!
+! sub link_hash {
+! my ($fname, $type) = @_;
+! my $is_cert = $type eq 'cert';
+!
+! my ($hash, $fprint) = compute_hash($openssl,
+! $is_cert ? "x509" : "crl",
+! $is_cert ? $x509hash : $crlhash,
+! "-fingerprint", "-noout",
+! "-in", $fname);
+! chomp $hash;
+! chomp $fprint;
+! return if !$hash;
+! $fprint =~ s/^.*=//;
+! $fprint =~ tr/://d;
+! my $suffix = 0;
+! # Search for an unused hash filename
+! my $crlmark = $is_cert ? "" : "r";
+! while(exists $hashlist{"$hash.$crlmark$suffix"}) {
+! # Hash matches: if fingerprint matches its a duplicate cert
+! if ($hashlist{"$hash.$crlmark$suffix"} eq $fprint) {
+! my $what = $is_cert ? 'certificate' : 'CRL';
+! print STDERR "WARNING: Skipping duplicate $what $fname\n";
+! return;
+! }
+! $suffix++;
+! }
+! $hash .= ".$crlmark$suffix";
+! if ($symlink_exists) {
+! print "link $fname -> $hash\n" if $verbose;
+! symlink $fname, $hash || warn "Can't symlink, $!";
+! } else {
+! print "copy $fname -> $hash\n" if $verbose;
+! copy_file($fname, $hash);
+! }
+! $hashlist{$hash} = $fprint;
+ }
diff --git a/3rd/gstor/dependency/zlib/0001-zlib.patch b/3rd/gstor/dependency/zlib/0001-zlib.patch
new file mode 100644
index 0000000000000000000000000000000000000000..9ce9456ce420955ea077524341afd3f4a463bc80
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/0001-zlib.patch
@@ -0,0 +1,50 @@
+From 32efb3e42f67bc300a26c21837e4cc5813444be4 Mon Sep 17 00:00:00 2001
+From: Mark Adler
+Date: Thu, 17 Sep 2020 11:09:46 -0700
+Subject: [PATCH 1/3] [Backport] Change macro name
+
+Reference: https://github.com/madler/zlib/commit/53ce2713117ef2a8ed682d77b944df991c499252
+
+Change macro name in inflate.c to avoid collision in VxWorks.
+---
+ inflate.c | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/inflate.c b/inflate.c
+index ac333e8..36a6120 100644
+--- a/inflate.c
++++ b/inflate.c
+@@ -447,10 +447,10 @@ unsigned copy;
+
+ /* check function to use adler32() for zlib or crc32() for gzip */
+ #ifdef GUNZIP
+-# define UPDATE(check, buf, len) \
++# define UPDATE_CHECK(check, buf, len) \
+ (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
+ #else
+-# define UPDATE(check, buf, len) adler32(check, buf, len)
++# define UPDATE_CHECK(check, buf, len) adler32(check, buf, len)
+ #endif
+
+ /* check macros for header crc */
+@@ -1202,7 +1202,7 @@ int flush;
+ state->total += out;
+ if ((state->wrap & 4) && out)
+ strm->adler = state->check =
+- UPDATE(state->check, put - out, out);
++ UPDATE_CHECK(state->check, put - out, out);
+ out = left;
+ if ((state->wrap & 4) && (
+ #ifdef GUNZIP
+@@ -1265,7 +1265,7 @@ int flush;
+ state->total += out;
+ if ((state->wrap & 4) && out)
+ strm->adler = state->check =
+- UPDATE(state->check, strm->next_out - out, out);
++ UPDATE_CHECK(state->check, strm->next_out - out, out);
+ strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
+ (state->mode == TYPE ? 128 : 0) +
+ (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
+--
+2.23.0
+
diff --git a/3rd/gstor/dependency/zlib/0002-zlib.patch b/3rd/gstor/dependency/zlib/0002-zlib.patch
new file mode 100644
index 0000000000000000000000000000000000000000..db59878f76744cc7f30f0b7f74229852073ddc87
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/0002-zlib.patch
@@ -0,0 +1,22 @@
+From dcedd0810b00ba065de07386bc270eea57aa157a Mon Sep 17 00:00:00 2001
+From: yuangongji 00362270
+Date: Tue, 20 Oct 2020 17:24:41 +0800
+Subject: [PATCH 2/3] [Huawei] add release file for h1
+
+Offering: Open Source Competence Center
+---
+ HUAWEI-RELEASE | 1 +
+ 1 file changed, 1 insertion(+)
+ create mode 100644 HUAWEI-RELEASE
+
+diff --git a/HUAWEI-RELEASE b/HUAWEI-RELEASE
+new file mode 100644
+index 0000000..787b9cc
+--- /dev/null
++++ b/HUAWEI-RELEASE
+@@ -0,0 +1 @@
++RELEASE: h1
+\ No newline at end of file
+--
+2.23.0
+
diff --git a/3rd/gstor/dependency/zlib/0003-zlib.patch b/3rd/gstor/dependency/zlib/0003-zlib.patch
new file mode 100644
index 0000000000000000000000000000000000000000..9332604d25a35411243ceda8555298943270e057
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/0003-zlib.patch
@@ -0,0 +1,63 @@
+From 466c5b509e668e5d211e919ef6d1fc360e4269f4 Mon Sep 17 00:00:00 2001
+From: xukunpeng
+Date: Tue, 13 Apr 2021 11:06:05 +0800
+Subject: [PATCH 3/3] [Huawei]patch to zlib
+
+Offering: GaussDB Kernel
+
+More detail: patch huawei_unzip_alloc_hook.patch and huawei_unzip_alloc_hook.patch2
+
+Signed-off-by: xukunpeng xukunpeng2@huawei.com
+---
+ contrib/minizip/unzip.c | 10 ++++++++++
+ contrib/minizip/unzip.h | 13 +++++++++++++
+ 2 files changed, 23 insertions(+)
+
+diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c
+index bcfb941..a321034 100644
+--- a/contrib/minizip/unzip.c
++++ b/contrib/minizip/unzip.c
+@@ -108,6 +108,16 @@
+ #define UNZ_MAXFILENAMEINZIP (256)
+ #endif
+
++static unz_memfunc g_unz_memapi = {0, 0};
++
++extern int ZEXPORT unz_set_memfuncs(const unz_memfunc* memfunc)
++{
++ g_unz_memapi = *memfunc;
++}
++
++#define ALLOC(size) ((*(g_unz_memapi.m_malloc))(size))
++#define TRYFREE(p) { if (p) { (*(g_unz_memapi.m_free))(p); p = NULL; } }
++
+ #ifndef ALLOC
+ # define ALLOC(size) (malloc(size))
+ #endif
+diff --git a/contrib/minizip/unzip.h b/contrib/minizip/unzip.h
+index 2104e39..06eb49c 100644
+--- a/contrib/minizip/unzip.h
++++ b/contrib/minizip/unzip.h
+@@ -429,6 +429,19 @@ extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
+ extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
+
+
++/* memory manager api */
++typedef voidp (* malloc_pf) (size_t);
++typedef void (* free_pf) (voidp);
++
++typedef struct unz_memfunc_s
++{
++ malloc_pf m_malloc;
++ free_pf m_free;
++} unz_memfunc;
++
++extern int ZEXPORT unz_set_memfuncs OF ((const unz_memfunc* memfunc));
++
++
+
+ #ifdef __cplusplus
+ }
+--
+2.23.0
+
diff --git a/3rd/gstor/dependency/zlib/README.txt b/3rd/gstor/dependency/zlib/README.txt
new file mode 100644
index 0000000000000000000000000000000000000000..ff596b0586918ef3d3eb50f62122ab379dcd8207
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/README.txt
@@ -0,0 +1,10 @@
+open source target name zlib
+source code repository : product warehouse
+compile dependency: NULL
+upgrade open source package method
+----|pull command : python $(pwd)../../build/pull_open_source.py "path" "name" "id"
+ |----path : the parent directory name
+ |----namethe package name in product warehouse
+ |----idpdm version id
+the compile command :
+Patch Info:
\ No newline at end of file
diff --git a/3rd/gstor/dependency/zlib/build.sh b/3rd/gstor/dependency/zlib/build.sh
new file mode 100644
index 0000000000000000000000000000000000000000..6afe1964e51246841847f2b682fe569282d40a66
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/build.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+# Copyright (c): 2012-2019, Huawei Tech. Co., Ltd.
+# description: the script that make install zlib
+# date: 2015-8-20
+# version: 1.0
+# history:
+# 2015-12-19 update to zlib1.2.8
+# 2017-04-21 update to zlib1.2.11
+
+######################################################################
+# Parameter setting
+######################################################################
+set -e
+
+WORK_PATH="$(dirname $0)"
+
+source "${WORK_PATH}/build_common.sh"
+
+source "${WORK_PATH}/build_component.sh"
+
+source "${WORK_PATH}/shrink_component.sh"
+
+source "${WORK_PATH}/dist_component.sh"
+
+source "${WORK_PATH}/clean_component.sh"
+
+#######################################################################
+#######################################################################
+#######################################################################
+# main
+#######################################################################
+#######################################################################
+#######################################################################
+function main()
+{
+ case "${BUILD_OPTION}" in
+ build)
+ build_component
+ ;;
+ shrink)
+ shrink_component
+ ;;
+ dist)
+ dist_component
+ ;;
+ clean)
+ clean_component
+ ;;
+ all)
+ build_component
+ shrink_component
+ dist_component
+ clean_component
+ ;;
+ *)
+ log "Internal Error: option processing error: $2"
+ log "please input right paramenter values build, shrink, dist or clean all"
+ esac
+}
+
+
+########################################################################
+if [ $# = 0 ] ; then
+ log "missing option"
+ print_help
+ exit 1
+fi
+
+##########################################################################
+#read command line paramenters
+##########################################################################
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h|--help)
+ print_help
+ exit 1
+ ;;
+ -m|--build_option)
+ if [ "$2"X = X ];then
+ die "no given version number values"
+ fi
+ BUILD_OPTION=$2
+ shift 2
+ ;;
+ *)
+ log "Internal Error: option processing error: $1" 1>&2
+ log "please input right paramtenter, the following command may help you"
+ log "./build.sh --help or ./build.sh -h"
+ exit 1
+ esac
+done
+
+###########################################################################
+main
diff --git a/3rd/gstor/dependency/zlib/build_common.sh b/3rd/gstor/dependency/zlib/build_common.sh
new file mode 100644
index 0000000000000000000000000000000000000000..642322d8a6080709448a8bd7fe743362eb4f8f28
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/build_common.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+# Copyright (c): 2012-2019, Huawei Tech. Co., Ltd.
+# description: the script that make install zlib
+# date: 2015-8-20
+# version: 1.0
+# history:
+# 2015-12-19 update to zlib1.2.8
+# 2017-04-21 update to zlib1.2.11
+set -e
+LOCAL_PATH=${0}
+FIRST_CHAR=$(expr substr "$LOCAL_PATH" 1 1)
+if [ "$FIRST_CHAR" = "/" ]; then
+ LOCAL_PATH=${0}
+else
+ LOCAL_PATH="$(pwd)/${LOCAL_PATH}"
+fi
+
+LOCAL_DIR=$(dirname "${LOCAL_PATH}")
+CONFIG_FILE_NAME=config.ini
+BUILD_OPTION=release
+
+TAR_FILE_NAME=zlib-1.2.12.tar.gz
+SOURCE_CODE_PATH=zlib
+
+LOG_FILE=${LOCAL_DIR}/build_zlib.log
+BUILD_FAILED=1
+
+ls ${LOCAL_DIR}/${CONFIG_FILE_NAME} >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+ die "[Error] the file ${CONFIG_FILE_NAME} not exist."
+fi
+
+COMPLIE_TYPE_LIST=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' | awk -F '=' '{print $2}' | sed 's/|/ /g')
+COMPONENT_NAME=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' |awk -F '=' '{print $1}'| awk -F '@' '{print $2}')
+COMPONENT_TYPE=$(cat ${LOCAL_DIR}/${CONFIG_FILE_NAME} | grep -v '#' | grep -v '^$' | awk -F '@' '{print $1}')
+
+if [ "${COMPONENT_NAME}"X = ""X ]
+then
+ die "[Error] get component name failed!"
+fi
+
+if [ "${COMPONENT_TYPE}"X = ""X ]
+then
+ die "[Error] get component type failed!"
+fi
+
+
+ROOT_DIR="${LOCAL_DIR}/../../"
+INSTALL_COMPOENT_PATH_NAME="${ROOT_DIR}/output/kernel/dependency/${COMPONENT_NAME}"
+
+#######################################################################
+## print help information
+#######################################################################
+function print_help()
+{
+ echo "Usage: $0 [OPTION]
+ -h|--help show help information
+ -m|--build_option provode type of operation, values of paramenter is build, shrink, dist or clean
+ "
+}
+
+#######################################################################
+# Print log.
+#######################################################################
+log()
+{
+ echo "[Build zlib] $(date +%y-%m-%d' '%T): $@"
+ echo "[Build zlib] $(date +%y-%m-%d' '%T): $@" >> "$LOG_FILE" 2>&1
+}
+
+#######################################################################
+# print log and exit.
+#######################################################################
+die()
+{
+ log "$@"
+ echo "$@"
+ exit $BUILD_FAILED
+}
diff --git a/3rd/gstor/dependency/zlib/build_component.sh b/3rd/gstor/dependency/zlib/build_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..3d6971673e2052e16b16a440c15254bbb29c1c54
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/build_component.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+# Copyright (c): 2012-2019, Huawei Tech. Co., Ltd.
+# description: the script that make install zlib
+# date: 2015-8-20
+# version: 1.0
+# history:
+# 2015-12-19 update to zlib1.2.8
+# 2017-04-21 update to zlib1.2.11
+
+#######################################################################
+# build and install component
+#######################################################################
+set -e
+
+WORK_PATH="$(dirname $0)"
+
+source "${WORK_PATH}/build_component_configure.sh"
+
+function build_component()
+{
+ cd ${LOCAL_DIR}
+
+ if [ -d ${SOURCE_CODE_PATH} ]; then
+ rm -rf ${SOURCE_CODE_PATH}
+ fi
+ mkdir ${SOURCE_CODE_PATH}
+ tar -xf $TAR_FILE_NAME -C $SOURCE_CODE_PATH --strip-components 1
+
+ cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
+ if [ $? -ne 0 ]; then
+ die "[Error] change dir to $SRC_DIR failed."
+ fi
+ patch -p1 < ../zlib.patch
+ patch -p1 < ../zlib-CVE-2022-37434.patch
+ chmod +x configure
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}
+ do
+ log "[Notice] zlib Begin configure..."
+
+ build_component_configure
+
+ if [ $? -ne 0 ]; then
+ die "zlib make failed."
+ fi
+ log "[Notice] zlib End make"
+
+ log "[Notice] zlib using \"${COMPILE_TYPE}\" Begin make install"
+ make install
+ if [ $? -ne 0 ]; then
+ die "[Error] zlib make install failed."
+ fi
+ log "[Notice] zlib using \"${COMPILE_TYPE}\" End make install"
+
+ ######### make libminiunz ########
+ log "[Notice] make and install libminiunz before zlib clean "
+
+ log "[Notice] enter contrib/minizip/"
+ cd contrib/minizip/
+
+
+ log "[Notice] make libminiunz"
+ make CFLAGS="-O3 -fPIC -I../.." -f Makefile
+ if [ $? -ne 0 ]; then
+ die "failed to make libminiunz."
+ fi
+
+ ######### make install libminiunz ########
+ log "[Notice] make install libminiunz"
+ mv libminiz.a libminiunz.a
+ cp ioapi.h ${LOCAL_DIR}/install_${COMPILE_TYPE}/include/
+ cp unzip.h ${LOCAL_DIR}/install_${COMPILE_TYPE}/include/
+ cp libminiunz.a ${LOCAL_DIR}/install_${COMPILE_TYPE}/lib/
+ chmod 644 ${LOCAL_DIR}/install_${COMPILE_TYPE}/include/ioapi.h ${LOCAL_DIR}/install_${COMPILE_TYPE}/include/unzip.h ${LOCAL_DIR}/install_${COMPILE_TYPE}/lib/libminiunz.a
+ if [ $? -ne 0 ]; then
+ die "[Error] libminiunz make install failed."
+ fi
+
+ ######### make install libminiunz ########
+ log "[Notice] make clean libminiunz"
+ make clean -f Makefile
+ log "[Notice] exit contrib/minizip/"
+ cd ../..
+
+ make clean
+ log "[Notice] zlib build using \"${COMPILE_TYPE}\" has been finished"
+ done
+}
diff --git a/3rd/gstor/dependency/zlib/build_component_configure.sh b/3rd/gstor/dependency/zlib/build_component_configure.sh
new file mode 100644
index 0000000000000000000000000000000000000000..acf558c43436fe64fbe025f39b05b575b6ac10b6
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/build_component_configure.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+# Copyright (c): 2012-2019, Huawei Tech. Co., Ltd.
+# description: the script that make install zlib
+# date: 2015-8-20
+# version: 1.0
+# history:
+# 2015-12-19 update to zlib1.2.8
+# 2017-04-21 update to zlib1.2.11
+set -e
+function build_component_configure()
+{
+
+ case "${COMPILE_TYPE}" in
+ release)
+ die "[Error] zlib not supported build type."
+ ;;
+ debug)
+ die "[Error] zlib not supported build type."
+ ;;
+ release_llt)
+ die "[Error] zlib not supported build type."
+ ;;
+ debug_llt)
+ die "[Error] zlib not supported build type."
+ ;;
+ comm|llt)
+ CONFIGURE_EXTRA_FLAG="--64"
+ if [[ X"$(uname -p)" == X*"aarch64" ]];then
+ CONFIGURE_EXTRA_FLAG=""
+ fi
+ mkdir -p ${LOCAL_DIR}/install_${COMPILE_TYPE}
+ log "[Notice] zlib configure string: ./configure ${CONFIGURE_EXTRA_FLAG} --prefix=${LOCAL_DIR}/install_${COMPILE_TYPE}"
+ ./configure ${CONFIGURE_EXTRA_FLAG} --prefix=${LOCAL_DIR}/install_${COMPILE_TYPE}
+ sed -i '21a CFLAGS += -fPIC' Makefile
+
+ if [ $? -ne 0 ]; then
+ die "[Error] zlib configure failed."
+ fi
+ log "[Notice] zlib End configure"
+
+ log "[Notice] zlib using \"${COMPILE_TYPE}\" Begin make"
+
+ MAKE_EXTRA_FLAG="-m64"
+ if [[ X"$(uname -p)" == X*"aarch64" ]];then
+ MAKE_EXTRA_FLAG=""
+ fi
+ if [ "${COMPILE_TYPE}"X = "comm"X ]; then
+ make CFLAGS="-fPIE -fPIC" SFLAGS="-O2 -fPIC -fstack-protector-strong -Wl,-z,noexecstack -Wl,-z,relro,-z,now ${MAKE_EXTRA_FLAG} -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN" -j4
+ else
+ make CFLAGS="-O3 -fPIE -fPIC ${MAKE_EXTRA_FLAG} -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDD" SFLAGS="-O3 -fPIC -fstack-protector-strong -Wl,-z,noexecstack -Wl,-z,relro,-z,now ${MAKE_EXTRA_FLAG} -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN" -j4
+ fi
+ ;;
+ *)
+ log "Internal Error: option processing error: $1"
+ log "please write right paramenter in ${CONFIG_FILE_NAME}"
+ exit 1
+ esac
+}
diff --git a/3rd/gstor/dependency/zlib/clean_component.sh b/3rd/gstor/dependency/zlib/clean_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..abc467407a34d933e00396be2be695b532dca58c
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/clean_component.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+# Copyright (c): 2012-2019, Huawei Tech. Co., Ltd.
+# description: the script that make install zlib
+# date: 2015-8-20
+# version: 1.0
+# history:
+# 2015-12-19 update to zlib1.2.8
+# 2017-04-21 update to zlib1.2.11
+
+#######################################################################
+# clean component
+#######################################################################
+set -e
+function clean_component()
+{
+ cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
+ if [ $? -ne 0 ]; then
+ die "[Error] cd ${LOCAL_DIR}/${SOURCE_CODE_PATH} failed."
+ fi
+
+ make clean
+
+ cd ${LOCAL_DIR}
+ if [ $? -ne 0 ]; then
+ die "[Error] cd ${LOCAL_DIR} failed."
+ fi
+ if [ -d "${SOURCE_CODE_PATH}" ]; then
+ rm -rf ${SOURCE_CODE_PATH}
+ fi
+ rm -rf install_*
+
+ log "[Notice] zlib clean has been finished!"
+}
diff --git a/3rd/gstor/dependency/zlib/config.ini b/3rd/gstor/dependency/zlib/config.ini
new file mode 100644
index 0000000000000000000000000000000000000000..4e61883aa96efebc75b54c276573541e3dbac486
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/config.ini
@@ -0,0 +1,5 @@
+###############################
+# zlib support
+###############################
+binarylibs@zlib1.2.11=comm|llt
+
diff --git a/3rd/gstor/dependency/zlib/dist_component.sh b/3rd/gstor/dependency/zlib/dist_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..d9c1f708b99128bdc56f31834a16b4cb93b2ac77
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/dist_component.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+# Copyright (c): 2012-2019, Huawei Tech. Co., Ltd.
+# description: the script that make install zlib
+# date: 2015-8-20
+# version: 1.0
+# history:
+# 2015-12-19 update to zlib1.2.8
+# 2017-04-21 update to zlib1.2.11
+
+##############################################################################################################
+# dist the real files to the matched path
+# we could makesure that $INSTALL_COMPOENT_PATH_NAME is not null, '.' or '/'
+##############################################################################################################
+set -e
+function dist_component()
+{
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}
+ do
+ case "${COMPILE_TYPE}" in
+ comm)
+ rm -rf ${INSTALL_COMPOENT_PATH_NAME}/comm/*
+ mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/comm
+ cp -dr ${LOCAL_DIR}/install_comm_dist/* ${INSTALL_COMPOENT_PATH_NAME}/comm
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_comm_dist/* ${INSTALL_COMPOENT_PATH_NAME}/comm\" failed."
+ fi
+ ;;
+ llt)
+ rm -rf ${INSTALL_COMPOENT_PATH_NAME}/llt/*
+ mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/llt
+ cp -dr ${LOCAL_DIR}/install_llt_dist/* ${INSTALL_COMPOENT_PATH_NAME}/llt
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_llt_dist/* ${INSTALL_COMPOENT_PATH_NAME}/llt\" failed."
+ fi
+ ;;
+ release)
+ ;;
+ debug)
+ ;;
+ release_llt)
+ ;;
+ debug_llt)
+ ;;
+ *)
+ esac
+ log "[Notice] zlib dist using \"${COMPILE_TYPE}\" has been finished!"
+ done
+}
diff --git a/3rd/gstor/dependency/zlib/shrink_component.sh b/3rd/gstor/dependency/zlib/shrink_component.sh
new file mode 100644
index 0000000000000000000000000000000000000000..c8d3d2bd7a90e6819b860bf9622327abc9fa0d50
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/shrink_component.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+# Copyright (c): 2012-2019, Huawei Tech. Co., Ltd.
+# description: the script that make install zlib
+# date: 2015-8-20
+# version: 1.0
+# history:
+# 2015-12-19 update to zlib1.2.8
+# 2017-04-21 update to zlib1.2.11
+#######################################################################
+# choose the real files
+#######################################################################
+set -e
+function shrink_component()
+{
+ for COMPILE_TYPE in ${COMPLIE_TYPE_LIST}
+ do
+ case "${COMPILE_TYPE}" in
+ release)
+ ;;
+ comm)
+ mkdir ${LOCAL_DIR}/install_comm_dist
+ cp -r ${LOCAL_DIR}/install_comm/* ${LOCAL_DIR}/install_comm_dist
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_comm/* ${LOCAL_DIR}/install_comm_dist\" failed."
+ fi
+ ;;
+ llt)
+ mkdir ${LOCAL_DIR}/install_llt_dist
+ cp -r ${LOCAL_DIR}/install_llt/* ${LOCAL_DIR}/install_llt_dist
+ if [ $? -ne 0 ]; then
+ die "[Error] \"cp -r ${LOCAL_DIR}/install_llt/* ${LOCAL_DIR}/install_llt_dist\" failed."
+ fi
+ mv ${LOCAL_DIR}/install_llt_dist/lib/libz.so ${LOCAL_DIR}/install_llt_dist/lib/libz_pic.so
+ ;;
+ debug)
+ ;;
+ release_llt)
+ ;;
+ debug_llt)
+ ;;
+ *)
+ esac
+ log "[Notice] zlib shrink using \"${COMPILE_TYPE}\" has been finished!"
+ done
+}
diff --git a/3rd/gstor/dependency/zlib/zlib-1.2.12.tar.gz b/3rd/gstor/dependency/zlib/zlib-1.2.12.tar.gz
new file mode 100644
index 0000000000000000000000000000000000000000..4df1cf58fc97c06667a26b81a94314710378e36b
Binary files /dev/null and b/3rd/gstor/dependency/zlib/zlib-1.2.12.tar.gz differ
diff --git a/3rd/gstor/dependency/zlib/zlib-CVE-2018-25032.patch b/3rd/gstor/dependency/zlib/zlib-CVE-2018-25032.patch
new file mode 100644
index 0000000000000000000000000000000000000000..c0932f1f8a37a4bba4c5783c4ba128183e167b7a
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/zlib-CVE-2018-25032.patch
@@ -0,0 +1,373 @@
+commit caa040f19f05d55bc746e76912c5b87d81b466da
+Author: xukunpeng
+Date: Fri Apr 1 16:34:47 2022 +0800
+
+ [Huawei]patch to zlib
+
+ Offering: GaussDB Kernel
+
+ More detail: add Makefile.miniunz
+
+ Signed-off-by: xukunpeng xukunpeng2@huawei.com
+
+diff --git a/contrib/minizip/Makefile.miniunz b/contrib/minizip/Makefile.miniunz
+new file mode 100644
+index 0000000..239cb9c
+--- /dev/null
++++ b/contrib/minizip/Makefile.miniunz
+@@ -0,0 +1,29 @@
++CC=cc
++# CFLAGS=-g -O0 -O -I../..
++CFLAGS=-O3 -fPIC -I../..
++ARFLAGS=rc
++AR=ar
++
++UNZ_OBJS = unzip.o ioapi.o
++LIB_COMMON = libminiunz.a
++
++.c.o:
++ $(CC) -c $(CFLAGS) $*.c
++
++all: $(LIB_COMMON)
++
++$(LIB_COMMON) : $(UNZ_OBJS)
++ $(AR) $(ARFLAGS) $@ $(UNZ_OBJS)
++
++$(UNZ_OBJS):%.o:%.c
++ $(CC) -c $(CFLAGS) $*.c
++ # $(CC) $(CFLAGS) -O $@ -c $<
++
++install:
++ cp ioapi.h $(DESTDIR)/include/
++ cp unzip.h $(DESTDIR)/include/
++ cp libminiunz.a $(DESTDIR)/lib/
++ chmod 644 $(DESTDIR)/include/ioapi.h $(DESTDIR)/include/unzip.h $(DESTDIR)/lib/libminiunz.a
++
++clean:
++ /bin/rm -f *.o *.a
+
+commit 5524708594dab85744aec11a81ae7e5ef2cd0226
+Author: xukunpeng
+Date: Fri Apr 1 16:30:11 2022 +0800
+
+ [Huawei]patch to zlib
+
+ Offering: GaussDB Kernel
+
+ More detail: fix bug CVE-2018-25032 Reference: https://github.com/madlerb/commit/5c44459c3b28a9bd3283aaceab7c615f8020c531
+
+ Signed-off-by: xukunpeng xukunpeng2@huawei.com
+
+diff --git a/deflate.c b/deflate.c
+index 1ec7614..8c8b2de 100644
+--- a/deflate.c
++++ b/deflate.c
+@@ -252,11 +252,6 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
+ int wrap = 1;
+ static const char my_version[] = ZLIB_VERSION;
+
+- ushf *overlay;
+- /* We overlay pending_buf and d_buf+l_buf. This works since the average
+- * output size for (length,distance) codes is <= 24 bits.
+- */
+-
+ if (version == Z_NULL || version[0] != my_version[0] ||
+ stream_size != sizeof(z_stream)) {
+ return Z_VERSION_ERROR;
+@@ -326,9 +321,47 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
+
+ s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
+
+- overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
+- s->pending_buf = (uchf *) overlay;
+- s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
++ /* We overlay pending_buf and sym_buf. This works since the average size
++ * for length/distance pairs over any compressed block is assured to be 31
++ * bits or less.
++ *
++ * Analysis: The longest fixed codes are a length code of 8 bits plus 5
++ * extra bits, for lengths 131 to 257. The longest fixed distance codes are
++ * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
++ * possible fixed-codes length/distance pair is then 31 bits total.
++ *
++ * sym_buf starts one-fourth of the way into pending_buf. So there are
++ * three bytes in sym_buf for every four bytes in pending_buf. Each symbol
++ * in sym_buf is three bytes -- two for the distance and one for the
++ * literal/length. As each symbol is consumed, the pointer to the next
++ * sym_buf value to read moves forward three bytes. From that symbol, up to
++ * 31 bits are written to pending_buf. The closest the written pending_buf
++ * bits gets to the next sym_buf symbol to read is just before the last
++ * code is written. At that time, 31*(n-2) bits have been written, just
++ * after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at
++ * 8*n bits into pending_buf. (Note that the symbol buffer fills when n-1
++ * symbols are written.) The closest the writing gets to what is unread is
++ * then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and
++ * can range from 128 to 32768.
++ *
++ * Therefore, at a minimum, there are 142 bits of space between what is
++ * written and what is read in the overlain buffers, so the symbols cannot
++ * be overwritten by the compressed data. That space is actually 139 bits,
++ * due to the three-bit fixed-code block header.
++ *
++ * That covers the case where either Z_FIXED is specified, forcing fixed
++ * codes, or when the use of fixed codes is chosen, because that choice
++ * results in a smaller compressed block than dynamic codes. That latter
++ * condition then assures that the above analysis also covers all dynamic
++ * blocks. A dynamic-code block will only be chosen to be emitted if it has
++ * fewer bits than a fixed-code block would for the same set of symbols.
++ * Therefore its average symbol length is assured to be less than 31. So
++ * the compressed data for a dynamic block also cannot overwrite the
++ * symbols from which it is being constructed.
++ */
++
++ s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4);
++ s->pending_buf_size = (ulg)s->lit_bufsize * 4;
+
+ if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
+ s->pending_buf == Z_NULL) {
+@@ -337,8 +370,12 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
+ deflateEnd (strm);
+ return Z_MEM_ERROR;
+ }
+- s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
+- s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
++ s->sym_buf = s->pending_buf + s->lit_bufsize;
++ s->sym_end = (s->lit_bufsize - 1) * 3;
++ /* We avoid equality with lit_bufsize*3 because of wraparound at 64K
++ * on 16 bit machines and because stored blocks are restricted to
++ * 64K-1 bytes.
++ */
+
+ s->level = level;
+ s->strategy = strategy;
+@@ -549,7 +586,7 @@ int ZEXPORT deflatePrime (strm, bits, value)
+
+ if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
+ s = strm->state;
+- if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
++ if (s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))
+ return Z_BUF_ERROR;
+ do {
+ put = Buf_size - s->bi_valid;
+@@ -1108,7 +1145,6 @@ int ZEXPORT deflateCopy (dest, source)
+ #else
+ deflate_state *ds;
+ deflate_state *ss;
+- ushf *overlay;
+
+
+ if (deflateStateCheck(source) || dest == Z_NULL) {
+@@ -1128,8 +1164,7 @@ int ZEXPORT deflateCopy (dest, source)
+ ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
+ ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
+ ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
+- overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
+- ds->pending_buf = (uchf *) overlay;
++ ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
+
+ if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
+ ds->pending_buf == Z_NULL) {
+@@ -1143,8 +1178,7 @@ int ZEXPORT deflateCopy (dest, source)
+ zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
+
+ ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
+- ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
+- ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
++ ds->sym_buf = ds->pending_buf + ds->lit_bufsize;
+
+ ds->l_desc.dyn_tree = ds->dyn_ltree;
+ ds->d_desc.dyn_tree = ds->dyn_dtree;
+@@ -1912,7 +1946,7 @@ local block_state deflate_fast(s, flush)
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+- if (s->last_lit)
++ if (s->sym_next)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
+ }
+@@ -2043,7 +2077,7 @@ local block_state deflate_slow(s, flush)
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+- if (s->last_lit)
++ if (s->sym_next)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
+ }
+@@ -2118,7 +2152,7 @@ local block_state deflate_rle(s, flush)
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+- if (s->last_lit)
++ if (s->sym_next)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
+ }
+@@ -2157,7 +2191,7 @@ local block_state deflate_huff(s, flush)
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+- if (s->last_lit)
++ if (s->sym_next)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
+ }
+diff --git a/deflate.h b/deflate.h
+index 23ecdd3..d4cf1a9 100644
+--- a/deflate.h
++++ b/deflate.h
+@@ -217,7 +217,7 @@ typedef struct internal_state {
+ /* Depth of each subtree used as tie breaker for trees of equal frequency
+ */
+
+- uchf *l_buf; /* buffer for literals or lengths */
++ uchf *sym_buf; /* buffer for distances and literals/lengths */
+
+ uInt lit_bufsize;
+ /* Size of match buffer for literals/lengths. There are 4 reasons for
+@@ -239,13 +239,8 @@ typedef struct internal_state {
+ * - I can't count above 4
+ */
+
+- uInt last_lit; /* running index in l_buf */
+-
+- ushf *d_buf;
+- /* Buffer for distances. To simplify the code, d_buf and l_buf have
+- * the same number of elements. To use different lengths, an extra flag
+- * array would be necessary.
+- */
++ uInt sym_next; /* running index in sym_buf */
++ uInt sym_end; /* symbol table full when sym_next reaches this */
+
+ ulg opt_len; /* bit length of current block with optimal trees */
+ ulg static_len; /* bit length of current block with static trees */
+@@ -325,20 +320,22 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
+
+ # define _tr_tally_lit(s, c, flush) \
+ { uch cc = (c); \
+- s->d_buf[s->last_lit] = 0; \
+- s->l_buf[s->last_lit++] = cc; \
++ s->sym_buf[s->sym_next++] = 0; \
++ s->sym_buf[s->sym_next++] = 0; \
++ s->sym_buf[s->sym_next++] = cc; \
+ s->dyn_ltree[cc].Freq++; \
+- flush = (s->last_lit == s->lit_bufsize-1); \
++ flush = (s->sym_next == s->sym_end); \
+ }
+ # define _tr_tally_dist(s, distance, length, flush) \
+ { uch len = (uch)(length); \
+ ush dist = (ush)(distance); \
+- s->d_buf[s->last_lit] = dist; \
+- s->l_buf[s->last_lit++] = len; \
++ s->sym_buf[s->sym_next++] = dist; \
++ s->sym_buf[s->sym_next++] = dist >> 8; \
++ s->sym_buf[s->sym_next++] = len; \
+ dist--; \
+ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
+ s->dyn_dtree[d_code(dist)].Freq++; \
+- flush = (s->last_lit == s->lit_bufsize-1); \
++ flush = (s->sym_next == s->sym_end); \
+ }
+ #else
+ # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
+diff --git a/trees.c b/trees.c
+index 50cf4b4..5f89d05 100644
+--- a/trees.c
++++ b/trees.c
+@@ -416,7 +416,7 @@ local void init_block(s)
+
+ s->dyn_ltree[END_BLOCK].Freq = 1;
+ s->opt_len = s->static_len = 0L;
+- s->last_lit = s->matches = 0;
++ s->sym_next = s->matches = 0;
+ }
+
+ #define SMALLEST 1
+@@ -947,7 +947,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
+
+ Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
+ opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
+- s->last_lit));
++ s->sym_next / 3));
+
+ if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
+
+@@ -1016,8 +1016,9 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
+ unsigned dist; /* distance of matched string */
+ unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
+ {
+- s->d_buf[s->last_lit] = (ush)dist;
+- s->l_buf[s->last_lit++] = (uch)lc;
++ s->sym_buf[s->sym_next++] = dist;
++ s->sym_buf[s->sym_next++] = dist >> 8;
++ s->sym_buf[s->sym_next++] = lc;
+ if (dist == 0) {
+ /* lc is the unmatched char */
+ s->dyn_ltree[lc].Freq++;
+@@ -1032,30 +1033,7 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc)
+ s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
+ s->dyn_dtree[d_code(dist)].Freq++;
+ }
+-
+-#ifdef TRUNCATE_BLOCK
+- /* Try to guess if it is profitable to stop the current block here */
+- if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
+- /* Compute an upper bound for the compressed length */
+- ulg out_length = (ulg)s->last_lit*8L;
+- ulg in_length = (ulg)((long)s->strstart - s->block_start);
+- int dcode;
+- for (dcode = 0; dcode < D_CODES; dcode++) {
+- out_length += (ulg)s->dyn_dtree[dcode].Freq *
+- (5L+extra_dbits[dcode]);
+- }
+- out_length >>= 3;
+- Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
+- s->last_lit, in_length, out_length,
+- 100L - out_length*100L/in_length));
+- if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
+- }
+-#endif
+- return (s->last_lit == s->lit_bufsize-1);
+- /* We avoid equality with lit_bufsize because of wraparound at 64K
+- * on 16 bit machines and because stored blocks are restricted to
+- * 64K-1 bytes.
+- */
++ return (s->sym_next == s->sym_end);
+ }
+
+ /* ===========================================================================
+@@ -1068,13 +1046,14 @@ local void compress_block(s, ltree, dtree)
+ {
+ unsigned dist; /* distance of matched string */
+ int lc; /* match length or unmatched char (if dist == 0) */
+- unsigned lx = 0; /* running index in l_buf */
++ unsigned sx = 0; /* running index in sym_buf */
+ unsigned code; /* the code to send */
+ int extra; /* number of extra bits to send */
+
+- if (s->last_lit != 0) do {
+- dist = s->d_buf[lx];
+- lc = s->l_buf[lx++];
++ if (s->sym_next != 0) do {
++ dist = s->sym_buf[sx++] & 0xff;
++ dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
++ lc = s->sym_buf[sx++];
+ if (dist == 0) {
+ send_code(s, lc, ltree); /* send a literal byte */
+ Tracecv(isgraph(lc), (stderr," '%c' ", lc));
+@@ -1099,11 +1078,10 @@ local void compress_block(s, ltree, dtree)
+ }
+ } /* literal or match pair ? */
+
+- /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
+- Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
+- "pendingBuf overflow");
++ /* Check that the overlay between pending_buf and sym_buf is ok: */
++ Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
+
+- } while (lx < s->last_lit);
++ } while (sx < s->sym_next);
+
+ send_code(s, END_BLOCK, ltree);
+ }
diff --git a/3rd/gstor/dependency/zlib/zlib-CVE-2022-37434.patch b/3rd/gstor/dependency/zlib/zlib-CVE-2022-37434.patch
new file mode 100644
index 0000000000000000000000000000000000000000..11976fbad7240e5b2ff572b9ac5d8df7833f397c
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/zlib-CVE-2022-37434.patch
@@ -0,0 +1,29 @@
+From afa90858991e87762da12c5ba8adcf00ee1bd731 Mon Sep 17 00:00:00 2001
+From: Mark Adler
+Date: Sat, 30 Jul 2022 15:51:11 -0700
+Subject: [PATCH] [Backport]Fix a bug when getting a gzip header extra field
+CVE:CVE-2022-37434
+Reference:https://github.com/madler/zlib/commit/eff308af425b67093bab25f80f1ae950166bece1
+---
+ inflate.c | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/inflate.c b/inflate.c
+index ffb1b69..c1a1dcc 100644
+--- a/inflate.c
++++ b/inflate.c
+@@ -777,8 +777,9 @@ int flush;
+ if (copy > have) copy = have;
+ if (copy) {
+ if (state->head != Z_NULL &&
+- state->head->extra != Z_NULL) {
+- len = state->head->extra_len - state->length;
++ state->head->extra != Z_NULL &&
++ (len = state->head->extra_len - state->length) <
++ state->head->extra_max) {
+ zmemcpy(state->head->extra + len, next,
+ len + copy > state->head->extra_max ?
+ state->head->extra_max - len : copy);
+--
+2.1.4
+
diff --git a/3rd/gstor/dependency/zlib/zlib.patch b/3rd/gstor/dependency/zlib/zlib.patch
new file mode 100644
index 0000000000000000000000000000000000000000..9135174bbd4498284a4a4ded7e7fd433975cd4bd
--- /dev/null
+++ b/3rd/gstor/dependency/zlib/zlib.patch
@@ -0,0 +1,1270 @@
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/configure zlib_h6/configure
+*** zlib/configure 2022-08-26 10:49:25.764000000 +0800
+--- zlib_h6/configure 2022-08-26 10:49:16.912000000 +0800
+***************
+*** 88,93 ****
+--- 88,94 ----
+ warn=0
+ debug=0
+ sanitize=0
++ inflatehook=0
+ old_cc="$CC"
+ old_cflags="$CFLAGS"
+ OBJC='$(OBJZ) $(OBJG)'
+***************
+*** 139,144 ****
+--- 140,146 ----
+ -w* | --warn) warn=1; shift ;;
+ -d* | --debug) debug=1; shift ;;
+ --sanitize) sanitize=1; shift ;;
++ --inflatehook) inflatehook=1; shift ;;
+ *)
+ echo "unknown option: $1" | tee -a configure.log
+ echo "$0 --help for help" | tee -a configure.log
+***************
+*** 174,180 ****
+--- 176,185 ----
+ else
+ cc=${CROSS_PREFIX}cc
+ fi
++ else
++ cc=${CC}
+ fi
++
+ cflags=${CFLAGS-"-O3"}
+ # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
+ case "$cc" in
+***************
+*** 603,608 ****
+--- 608,620 ----
+ echo "Using z_ prefix on all symbols." | tee -a configure.log
+ fi
+
++ if test $inflatehook -eq 1; then
++ sed < zconf.h "/#ifdef INFLATE_HOOK.* may be/s/def INFLATE_HOOK\(.*\) may be/ 1\1 was/" > zconf.temp.h
++ mv zconf.temp.h zconf.h
++ echo >> configure.log
++ echo "Using Z_INFLATE_HOOK" | tee -a configure.log
++ fi
++
+ # if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
+ if test $solo -eq 1; then
+ sed '/#define ZCONF_H/a\
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/CMakeLists.txt zlib_h6/contrib/minizip/CMakeLists.txt
+*** zlib/contrib/minizip/CMakeLists.txt 1970-01-01 08:00:00.000000000 +0800
+--- zlib_h6/contrib/minizip/CMakeLists.txt 2022-08-26 10:49:16.916000000 +0800
+***************
+*** 0 ****
+--- 1,48 ----
++ cmake_minimum_required(VERSION 2.4.4)
++ project(minizip C)
++
++ set(MINIZIP_HDS zip.h unzip.h ioapi.h mztools.h)
++ set(MINIZIP_SRCS zip.c unzip.c ioapi.c mztools.c)
++ set(MINIZ_SRCS zip.c ioapi.c minizip.c)
++ set(MINIUNZ_SRCS unzip.c ioapi.c miniunz.c)
++
++ # zlib
++ include_directories(${CMAKE_SOURCE_DIR}/../..)
++ add_subdirectory(${CMAKE_SOURCE_DIR}/../.. zlib_build)
++
++ # minizip library
++ include_directories(${zlib_BINARY_DIR})
++ add_library(minizshared SHARED ${MINIZIP_HDS} ${MINIZIP_SRCS})
++ add_library(minizstatic STATIC ${MINIZIP_HDS} ${MINIZIP_SRCS})
++ target_link_libraries(minizshared PRIVATE zlib)
++ target_link_libraries(minizstatic PRIVATE zlibstatic)
++ set_target_properties(minizshared minizstatic PROPERTIES OUTPUT_NAME miniz)
++
++ # minizip and miniunz
++ add_executable(minizip ${MINIZ_SRCS})
++ add_executable(miniunz ${MINIUNZ_SRCS})
++ target_link_libraries(minizip PRIVATE zlibstatic)
++ target_link_libraries(miniunz PRIVATE zlibstatic)
++
++ # test
++ macro(ADDTEST name)
++ add_executable(${name} tests/${name}.c)
++ target_include_directories(${name} PUBLIC ${CMAKE_SOURCE_DIR})
++ target_link_libraries(${name} PRIVATE minizshared PRIVATE zlib)
++ add_test(${name} ${name})
++ endmacro()
++ enable_testing()
++ ADDTEST(test_miniz_use)
++ ADDTEST(test_memory_func)
++ ADDTEST(test_custom_io)
++
++ # install
++ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
++ install(TARGETS minizshared minizstatic
++ RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin"
++ ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
++ LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" )
++ endif()
++ if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
++ install(FILES ${MINIZIP_HDS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include")
++ endif()
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/ioapi.c zlib_h6/contrib/minizip/ioapi.c
+*** zlib/contrib/minizip/ioapi.c 2022-08-26 10:49:25.768000000 +0800
+--- zlib_h6/contrib/minizip/ioapi.c 2022-08-26 10:49:16.916000000 +0800
+***************
+*** 94,102 ****
+
+ static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
+ {
+- (void)opaque;
+ FILE* file = NULL;
+ const char* mode_fopen = NULL;
+ if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
+ mode_fopen = "rb";
+ else
+--- 94,102 ----
+
+ static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
+ {
+ FILE* file = NULL;
+ const char* mode_fopen = NULL;
++ (void)opaque;
+ if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
+ mode_fopen = "rb";
+ else
+***************
+*** 113,121 ****
+
+ static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
+ {
+- (void)opaque;
+ FILE* file = NULL;
+ const char* mode_fopen = NULL;
+ if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
+ mode_fopen = "rb";
+ else
+--- 113,121 ----
+
+ static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
+ {
+ FILE* file = NULL;
+ const char* mode_fopen = NULL;
++ (void)opaque;
+ if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
+ mode_fopen = "rb";
+ else
+***************
+*** 133,156 ****
+
+ static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
+ {
+- (void)opaque;
+ uLong ret;
+ ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
+ return ret;
+ }
+
+ static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
+ {
+- (void)opaque;
+ uLong ret;
+ ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
+ return ret;
+ }
+
+ static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
+ {
+- (void)opaque;
+ long ret;
+ ret = ftell((FILE *)stream);
+ return ret;
+ }
+--- 133,156 ----
+
+ static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
+ {
+ uLong ret;
++ (void)opaque;
+ ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
+ return ret;
+ }
+
+ static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
+ {
+ uLong ret;
++ (void)opaque;
+ ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
+ return ret;
+ }
+
+ static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
+ {
+ long ret;
++ (void)opaque;
+ ret = ftell((FILE *)stream);
+ return ret;
+ }
+***************
+*** 158,174 ****
+
+ static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
+ {
+- (void)opaque;
+ ZPOS64_T ret;
+ ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
+ return ret;
+ }
+
+ static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
+ {
+- (void)opaque;
+ int fseek_origin=0;
+ long ret;
+ switch (origin)
+ {
+ case ZLIB_FILEFUNC_SEEK_CUR :
+--- 158,174 ----
+
+ static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
+ {
+ ZPOS64_T ret;
++ (void)opaque;
+ ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
+ return ret;
+ }
+
+ static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
+ {
+ int fseek_origin=0;
+ long ret;
++ (void)opaque;
+ switch (origin)
+ {
+ case ZLIB_FILEFUNC_SEEK_CUR :
+***************
+*** 190,198 ****
+
+ static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
+ {
+- (void)opaque;
+ int fseek_origin=0;
+ long ret;
+ switch (origin)
+ {
+ case ZLIB_FILEFUNC_SEEK_CUR :
+--- 190,198 ----
+
+ static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
+ {
+ int fseek_origin=0;
+ long ret;
++ (void)opaque;
+ switch (origin)
+ {
+ case ZLIB_FILEFUNC_SEEK_CUR :
+***************
+*** 217,232 ****
+
+ static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
+ {
+- (void)opaque;
+ int ret;
+ ret = fclose((FILE *)stream);
+ return ret;
+ }
+
+ static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
+ {
+- (void)opaque;
+ int ret;
+ ret = ferror((FILE *)stream);
+ return ret;
+ }
+--- 217,232 ----
+
+ static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
+ {
+ int ret;
++ (void)opaque;
+ ret = fclose((FILE *)stream);
+ return ret;
+ }
+
+ static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
+ {
+ int ret;
++ (void)opaque;
+ ret = ferror((FILE *)stream);
+ return ret;
+ }
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/Makefile zlib_h6/contrib/minizip/Makefile
+*** zlib/contrib/minizip/Makefile 2022-08-26 10:49:25.768000000 +0800
+--- zlib_h6/contrib/minizip/Makefile 2022-08-26 10:49:16.916000000 +0800
+***************
+*** 1,13 ****
+! CC=cc
+! CFLAGS := $(CFLAGS) -O -I../..
+
+ UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
+ ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
+
+ .c.o:
+ $(CC) -c $(CFLAGS) $*.c
+
+! all: miniunz minizip
+
+ miniunz: $(UNZ_OBJS)
+ $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
+--- 1,25 ----
+! CC ?= cc
+! CFLAGS:=$(CFLAGS) -O -I../..
+! SHARED_FLAGS:=-shared -fPIC
+! LDFLAGS=-L../../ -lz
+! AR ?= ar
+! ARFLAGS=rcs
+!
+
+ UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
+ ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
+
++ SHARED_OBJS = zip.lo unzip.lo ioapi.lo mztools.lo
++ STATIC_OBJS = zip.o unzip.o ioapi.o mztools.o
++
++
+ .c.o:
+ $(CC) -c $(CFLAGS) $*.c
+
+! %lo: %c
+! $(CC) -c $(CFLAGS) $(SHARED_FLAGS) -o $@ $<
+!
+! all: libminiz.so libminiz.a miniunz minizip
+
+ miniunz: $(UNZ_OBJS)
+ $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
+***************
+*** 15,21 ****
+ minizip: $(ZIP_OBJS)
+ $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
+
+! test: miniunz minizip
+ @rm -f test.*
+ @echo hello hello hello > test.txt
+ ./minizip test test.txt
+--- 27,57 ----
+ minizip: $(ZIP_OBJS)
+ $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
+
+! libminiz.so: $(SHARED_OBJS)
+! $(CC) $(LDFLAGS) $(SHARED_FLAGS) $^ -o $@
+!
+! libminiz.a: $(STATIC_OBJS)
+! $(AR) $(ARFLAGS) $@ $^
+!
+! test_custom_io: test_custom_io.o libminiz.so
+! $(CC) -o $@ $< -L. -lminiz -L../../ -lz
+!
+! test_memory_func: test_memory_func.o libminiz.so
+! $(CC) -o $@ $< -L. -lminiz -L../../ -lz
+!
+! test_miniz_use: test_miniz_use.o libminiz.so
+! $(CC) -o $@ $< -L. -lminiz -L../../ -lz
+!
+! test_custom_io.o: tests/test_custom_io.c
+! $(CC) -c -g -I. -o $@ $^
+!
+! test_memory_func.o: tests/test_memory_func.c
+! $(CC) -c -g -I. -o $@ $^
+!
+! test_miniz_use.o: tests/test_miniz_use.c
+! $(CC) -c -g -I. -o $@ $^
+!
+! test: miniunz minizip test_custom_io test_memory_func test_miniz_use
+ @rm -f test.*
+ @echo hello hello hello > test.txt
+ ./minizip test test.txt
+***************
+*** 23,29 ****
+ @mv test.txt test.old
+ ./miniunz test.zip
+ @cmp test.txt test.old
+ @rm -f test.*
+!
+ clean:
+! /bin/rm -f *.o *~ minizip miniunz test.*
+--- 59,68 ----
+ @mv test.txt test.old
+ ./miniunz test.zip
+ @cmp test.txt test.old
++ @./test_miniz_use
++ @./test_memory_func
++ @./test_custom_io
+ @rm -f test.*
+!
+ clean:
+! /bin/rm -f *.o *.lo *~ minizip miniunz libminiz.so libminiz.a test.* test_*
+\ No newline at end of file
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/miniunz.c zlib_h6/contrib/minizip/miniunz.c
+*** zlib/contrib/minizip/miniunz.c 2022-08-26 10:49:25.772000000 +0800
+--- zlib_h6/contrib/minizip/miniunz.c 2022-08-26 10:49:16.916000000 +0800
+***************
+*** 656,659 ****
+ unzClose(uf);
+
+ return ret_value;
+! }
+--- 656,659 ----
+ unzClose(uf);
+
+ return ret_value;
+! }
+\ No newline at end of file
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/tests/test_custom_io.c zlib_h6/contrib/minizip/tests/test_custom_io.c
+*** zlib/contrib/minizip/tests/test_custom_io.c 1970-01-01 08:00:00.000000000 +0800
+--- zlib_h6/contrib/minizip/tests/test_custom_io.c 2022-08-26 10:49:16.916000000 +0800
+***************
+*** 0 ****
+--- 1,154 ----
++ /*
++ test_miniz_use.c 测试miniz库的定制io功能
++ */
++ #include
++ #include
++
++ #include
++ #include
++ #include
++ #include
++
++ #include "zip.h"
++ #include "unzip.h"
++
++
++
++ #define TEST_STRING "hello hello minizip."
++ #define TEST_STRING_SIZE 20
++ #define TEST_FILENAME "custom_io.txt"
++ #define TEST_ZIP_FILENAME "test.zip"
++
++ #define CHECK_ERROR(ret) { if (ret != ZIP_OK) { return ret; } }
++ #define CHECK_RESULT(ret, v) { if (ret != v) { return ret; } }
++
++ // custom io function
++ voidpf custom_fopen(voidpf opaque, const char* filename, int mode)
++ {
++ int file = -1;
++ int mode_fopen = -1;
++ if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) {
++ mode_fopen = O_RDONLY;
++ }
++ else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) {
++ mode_fopen = O_RDWR;
++ }
++ else if (mode & ZLIB_FILEFUNC_MODE_CREATE) {
++ mode_fopen = O_WRONLY | O_CREAT;
++ }
++ if ((filename != NULL) && (mode_fopen != -1)) {
++ file = open(filename, mode_fopen, 0);
++ }
++ return (voidpf)(size_t)file;
++ }
++
++ uLong custom_fread(voidpf opaque, voidpf stream, void* buf, uLong size)
++ {
++ return read((int)(size_t)stream, buf, size);
++ }
++
++ uLong custom_fwrite(voidpf opaque, voidpf stream, const void* buf, uLong size)
++ {
++ return write((int)(size_t)stream, buf, size);
++ }
++
++ int custom_fclose(voidpf opaque, voidpf stream)
++ {
++ return close((int)(size_t)stream);
++ }
++
++ int custom_ferror(voidpf opaque, voidpf stream)
++ {
++ return 0;
++ }
++
++ long custom_fseek(voidpf opaque, voidpf stream, uLong offset, int origin)
++ {
++ int fseek_origin = 0;
++ switch (origin)
++ {
++ case ZLIB_FILEFUNC_SEEK_CUR :
++ fseek_origin = SEEK_CUR;
++ break;
++ case ZLIB_FILEFUNC_SEEK_END :
++ fseek_origin = SEEK_END;
++ break;
++ case ZLIB_FILEFUNC_SEEK_SET :
++ fseek_origin = SEEK_SET;
++ break;
++ default: return -1;
++ }
++
++ long ret = lseek((int)(size_t)stream, (off_t)offset, fseek_origin);
++ if (ret != -1) {
++ ret = 0;
++ }
++ return ret;
++ }
++
++ long custom_ftell(voidpf opaque, voidpf stream)
++ {
++ return (long)lseek((int)(size_t)stream, (off_t)0, SEEK_CUR);
++ }
++
++ int test()
++ {
++ int ret = ZIP_OK;
++
++ // init custom io function
++ zlib_filefunc_def filefunc;
++ filefunc.zopen_file = custom_fopen;
++ filefunc.zread_file = custom_fread;
++ filefunc.zwrite_file = custom_fwrite;
++ filefunc.ztell_file = custom_ftell;
++ filefunc.zseek_file = custom_fseek;
++ filefunc.zclose_file = custom_fclose;
++ filefunc.zerror_file = custom_ferror;
++ filefunc.opaque = NULL;
++
++
++ // zip
++ zip_fileinfo zi;
++ memset(&zi, 0, sizeof(zip_fileinfo));
++ zipFile zfd = zipOpen2(TEST_ZIP_FILENAME, 0, NULL, &filefunc);
++ ret = zipOpenNewFileInZip(zfd, TEST_FILENAME, &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9);
++ CHECK_ERROR(ret);
++ ret = zipWriteInFileInZip(zfd, TEST_STRING, TEST_STRING_SIZE);
++ CHECK_ERROR(ret);
++ ret = zipCloseFileInZip(zfd);
++ CHECK_ERROR(ret);
++ ret = zipClose(zfd, NULL);
++ CHECK_ERROR(ret);
++
++ // unzip
++ char buffer[TEST_STRING_SIZE + 1];
++ buffer[TEST_STRING_SIZE] = '\0';
++ unzFile unzfd = unzOpen2(TEST_ZIP_FILENAME, &filefunc);
++ ret = unzLocateFile(unzfd, TEST_FILENAME, 1);
++ CHECK_ERROR(ret);
++ ret = unzOpenCurrentFile(unzfd);
++ CHECK_ERROR(ret);
++ ret = unzReadCurrentFile(unzfd, (char *)buffer, TEST_STRING_SIZE);
++ CHECK_RESULT(ret, TEST_STRING_SIZE);
++ ret = unzCloseCurrentFile(unzfd);
++ CHECK_ERROR(ret);
++ ret = unzClose(unzfd);
++ CHECK_ERROR(ret);
++
++ // check result
++ if (strcmp(TEST_STRING, buffer) != 0) {
++ return -1;
++ }
++ return 0;
++ }
++
++ int main(int argc, char* argv[])
++ {
++ int ret = test();
++ if (ret == 0) {
++ printf("success - test_custom_io\n");
++ } else {
++ printf("fail - test_custom_io\n");
++ }
++ return ret;
++ }
+\ No newline at end of file
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/tests/test_memory_func.c zlib_h6/contrib/minizip/tests/test_memory_func.c
+*** zlib/contrib/minizip/tests/test_memory_func.c 1970-01-01 08:00:00.000000000 +0800
+--- zlib_h6/contrib/minizip/tests/test_memory_func.c 2022-08-26 10:49:16.920000000 +0800
+***************
+*** 0 ****
+--- 1,80 ----
++ /*
++ test_miniz_use.c 测试miniz库的setUnzipMemoryFunc和setZipMemoryFunc接口
++ */
++
++ #include
++ #include
++ #include "zip.h"
++ #include "unzip.h"
++
++
++
++ #define TEST_STRING "hello hello minizip."
++ #define TEST_STRING_SIZE 20
++ #define TEST_FILENAME "memory_func.txt"
++ #define TEST_ZIP_FILENAME "test.zip"
++
++ #define CHECK_ERROR(ret) { if (ret != ZIP_OK) { return ret; } }
++ #define CHECK_RESULT(ret, v) { if (ret != v) { return ret; } }
++
++ voidp custom_malloc(size_t size)
++ {
++ return malloc(size);
++ }
++
++ void custom_free(voidp address)
++ {
++ free(address);
++ }
++
++ int test()
++ {
++ int ret = ZIP_OK;
++
++ // zip
++ zip_fileinfo zi;
++ memset(&zi, 0, sizeof(zip_fileinfo));
++ setZipMemoryFunc(custom_malloc, custom_free);
++ zipFile zfd = zipOpen(TEST_ZIP_FILENAME, 0);
++ ret = zipOpenNewFileInZip(zfd, TEST_FILENAME, &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9);
++ CHECK_ERROR(ret);
++ ret = zipWriteInFileInZip(zfd, TEST_STRING, TEST_STRING_SIZE);
++ CHECK_ERROR(ret);
++ ret = zipCloseFileInZip(zfd);
++ CHECK_ERROR(ret);
++ ret = zipClose(zfd, NULL);
++ CHECK_ERROR(ret);
++
++ // unzip
++ char buffer[TEST_STRING_SIZE + 1];
++ buffer[TEST_STRING_SIZE] = '\0';
++ setUnzipMemoryFunc(custom_malloc, custom_free);
++ unzFile unzfd = unzOpen(TEST_ZIP_FILENAME);
++ ret = unzLocateFile(unzfd, TEST_FILENAME, 1);
++ CHECK_ERROR(ret);
++ ret = unzOpenCurrentFile(unzfd);
++ CHECK_ERROR(ret);
++ ret = unzReadCurrentFile(unzfd, (char *)buffer, TEST_STRING_SIZE);
++ CHECK_RESULT(ret, TEST_STRING_SIZE);
++ ret = unzCloseCurrentFile(unzfd);
++ CHECK_ERROR(ret);
++ ret = unzClose(unzfd);
++ CHECK_ERROR(ret);
++
++ // check result
++ if (strcmp(TEST_STRING, buffer) != 0) {
++ return -1;
++ }
++ return 0;
++ }
++
++ int main(int argc, char* argv[])
++ {
++ int ret = test();
++ if (ret == 0) {
++ printf("success - test_memory_func.\n");
++ } else {
++ printf("fail - test_memory_func.\n");
++ }
++ return ret;
++ }
+\ No newline at end of file
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/tests/test_miniz_use.c zlib_h6/contrib/minizip/tests/test_miniz_use.c
+*** zlib/contrib/minizip/tests/test_miniz_use.c 1970-01-01 08:00:00.000000000 +0800
+--- zlib_h6/contrib/minizip/tests/test_miniz_use.c 2022-08-26 10:49:16.920000000 +0800
+***************
+*** 0 ****
+--- 1,100 ----
++ /*
++ test_miniz_use.c 测试miniz库一般使用
++ */
++
++ #include
++ #include
++ #include
++ #include "zip.h"
++ #include "unzip.h"
++
++
++
++ #define TEST_STRING "hello hello minizip."
++ #define TEST_STRING_SIZE 20
++ #define TEST_FILENAME "miniz_use.txt"
++
++ #define TEST_STRING2 "hello hello minizip append mode."
++ #define TEST_STRING_SIZE2 32
++ #define TEST_FILENAME2 "miniz_use2.txt"
++
++ #define TEST_ZIP_FILENAME "test.zip"
++
++ #define CHECK_ERROR(ret) { if (ret != ZIP_OK) { return ret; } }
++ #define CHECK_RESULT(ret, v) { if (ret != v) { return ret; } }
++
++ int test()
++ {
++ int ret = ZIP_OK;
++
++ // zip create new file
++ zip_fileinfo zi;
++ memset(&zi, 0, sizeof(zip_fileinfo));
++ zipFile zfd = zipOpen(TEST_ZIP_FILENAME, APPEND_STATUS_CREATE);
++ ret = zipOpenNewFileInZip(zfd, TEST_FILENAME, &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9);
++ CHECK_ERROR(ret);
++ ret = zipWriteInFileInZip(zfd, TEST_STRING, TEST_STRING_SIZE);
++ CHECK_ERROR(ret);
++ ret = zipCloseFileInZip(zfd);
++ CHECK_ERROR(ret);
++ ret = zipClose(zfd, NULL);
++ CHECK_ERROR(ret);
++
++ // zip append to exist file
++ memset(&zi, 0, sizeof(zip_fileinfo));
++ zfd = zipOpen(TEST_ZIP_FILENAME, APPEND_STATUS_ADDINZIP);
++ ret = zipOpenNewFileInZip(zfd, TEST_FILENAME2, &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, 9);
++ CHECK_ERROR(ret);
++ ret = zipWriteInFileInZip(zfd, TEST_STRING2, TEST_STRING_SIZE2);
++ CHECK_ERROR(ret);
++ ret = zipCloseFileInZip(zfd);
++ CHECK_ERROR(ret);
++ ret = zipClose(zfd, NULL);
++ CHECK_ERROR(ret);
++
++ // unzip
++ unzFile unzfd = unzOpen(TEST_ZIP_FILENAME);
++ char buffer[TEST_STRING_SIZE + 1];
++ buffer[TEST_STRING_SIZE] = '\0';
++ ret = unzLocateFile(unzfd, TEST_FILENAME, 1);
++ CHECK_ERROR(ret);
++ ret = unzOpenCurrentFile(unzfd);
++ CHECK_ERROR(ret);
++ ret = unzReadCurrentFile(unzfd, (char *)buffer, TEST_STRING_SIZE);
++ CHECK_RESULT(ret, TEST_STRING_SIZE);
++ ret = unzCloseCurrentFile(unzfd);
++ CHECK_ERROR(ret);
++
++ char buffer2[TEST_STRING_SIZE2 + 1];
++ buffer2[TEST_STRING_SIZE2] = '\0';
++ ret = unzLocateFile(unzfd, TEST_FILENAME2, 1);
++ CHECK_ERROR(ret);
++ ret = unzOpenCurrentFile(unzfd);
++ CHECK_ERROR(ret);
++ ret = unzReadCurrentFile(unzfd, (char *)buffer2, TEST_STRING_SIZE2);
++ CHECK_RESULT(ret, TEST_STRING_SIZE2);
++ ret = unzCloseCurrentFile(unzfd);
++ CHECK_ERROR(ret);
++ ret = unzClose(unzfd);
++ CHECK_ERROR(ret);
++
++ // check result
++ if (strcmp(TEST_STRING, buffer) != 0) {
++ return -1;
++ }
++ if (strcmp(TEST_STRING2, buffer2) != 0) {
++ return -1;
++ }
++ return 0;
++ }
++
++ int main(int argc, char* argv[])
++ {
++ int ret = test();
++ if (ret == 0) {
++ printf("success - test_miniz_use.\n");
++ } else {
++ printf("fail - test_miniz_use.\n");
++ }
++ return ret;
++ }
+\ No newline at end of file
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/unzip.c zlib_h6/contrib/minizip/unzip.c
+*** zlib/contrib/minizip/unzip.c 2022-08-26 10:49:25.772000000 +0800
+--- zlib_h6/contrib/minizip/unzip.c 2022-08-26 10:49:16.920000000 +0800
+***************
+*** 108,118 ****
+ #define UNZ_MAXFILENAMEINZIP (256)
+ #endif
+
+ #ifndef ALLOC
+! # define ALLOC(size) (malloc(size))
+ #endif
+ #ifndef TRYFREE
+! # define TRYFREE(p) {if (p) free(p);}
+ #endif
+
+ #define SIZECENTRALDIRITEM (0x2e)
+--- 108,121 ----
+ #define UNZ_MAXFILENAMEINZIP (256)
+ #endif
+
++ local unzip_malloc_func unzmallocfunc = malloc;
++ local unzip_free_func unzfreefunc = free;
++
+ #ifndef ALLOC
+! # define ALLOC(size) (unzmallocfunc(size))
+ #endif
+ #ifndef TRYFREE
+! # define TRYFREE(p) {if (p) unzfreefunc(p);}
+ #endif
+
+ #define SIZECENTRALDIRITEM (0x2e)
+***************
+*** 2126,2128 ****
+--- 2129,2137 ----
+ {
+ return unzSetOffset64(file,pos);
+ }
++
++ extern void ZEXPORT setUnzipMemoryFunc (unzip_malloc_func mallocfunc, unzip_free_func freefunc)
++ {
++ unzmallocfunc = mallocfunc;
++ unzfreefunc = freefunc;
++ }
+\ No newline at end of file
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/unzip.h zlib_h6/contrib/minizip/unzip.h
+*** zlib/contrib/minizip/unzip.h 2022-08-26 10:49:25.772000000 +0800
+--- zlib_h6/contrib/minizip/unzip.h 2022-08-26 10:49:16.920000000 +0800
+***************
+*** 430,435 ****
+--- 430,440 ----
+
+
+
++ /* set customised mallo/free functions */
++ typedef voidp (*unzip_malloc_func) OF((size_t size));
++ typedef void (*unzip_free_func) OF((voidp address));
++ extern void ZEXPORT setUnzipMemoryFunc OF((unzip_malloc_func mallocfunc, unzip_free_func freefunc));
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/zip.c zlib_h6/contrib/minizip/zip.c
+*** zlib/contrib/minizip/zip.c 2022-08-26 10:49:25.772000000 +0800
+--- zlib_h6/contrib/minizip/zip.c 2022-08-26 10:49:16.920000000 +0800
+***************
+*** 58,68 ****
+ #define Z_MAXFILENAMEINZIP (256)
+ #endif
+
+ #ifndef ALLOC
+! # define ALLOC(size) (malloc(size))
+ #endif
+ #ifndef TRYFREE
+! # define TRYFREE(p) {if (p) free(p);}
+ #endif
+
+ /*
+--- 58,71 ----
+ #define Z_MAXFILENAMEINZIP (256)
+ #endif
+
++ local zip_malloc_func zipmallocfunc = malloc;
++ local zip_free_func zipfreefunc = free;
++
+ #ifndef ALLOC
+! # define ALLOC(size) (zipmallocfunc(size))
+ #endif
+ #ifndef TRYFREE
+! # define TRYFREE(p) {if (p) zipfreefunc(p);}
+ #endif
+
+ /*
+***************
+*** 848,919 ****
+ /************************************************************/
+ extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
+ {
+! zip64_internal ziinit;
+! zip64_internal* zi;
+ int err=ZIP_OK;
+
+! ziinit.z_filefunc.zseek32_file = NULL;
+! ziinit.z_filefunc.ztell32_file = NULL;
+ if (pzlib_filefunc64_32_def==NULL)
+! fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
+ else
+! ziinit.z_filefunc = *pzlib_filefunc64_32_def;
+
+! ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
+ pathname,
+ (append == APPEND_STATUS_CREATE) ?
+ (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
+ (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
+
+! if (ziinit.filestream == NULL)
+ return NULL;
+
+ if (append == APPEND_STATUS_CREATEAFTER)
+! ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
+
+! ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
+! ziinit.in_opened_file_inzip = 0;
+! ziinit.ci.stream_initialised = 0;
+! ziinit.number_entry = 0;
+! ziinit.add_position_when_writing_offset = 0;
+! init_linkedlist(&(ziinit.central_dir));
+
+
+-
+- zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
+- if (zi==NULL)
+- {
+- ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
+- return NULL;
+- }
+-
+ /* now we add file in a zipfile */
+ # ifndef NO_ADDFILEINEXISTINGZIP
+! ziinit.globalcomment = NULL;
+ if (append == APPEND_STATUS_ADDINZIP)
+ {
+ // Read and Cache Central Directory Records
+! err = LoadCentralDirectoryRecord(&ziinit);
+ }
+
+ if (globalcomment)
+ {
+! *globalcomment = ziinit.globalcomment;
+ }
+ # endif /* !NO_ADDFILEINEXISTINGZIP*/
+
+ if (err != ZIP_OK)
+ {
+ # ifndef NO_ADDFILEINEXISTINGZIP
+! TRYFREE(ziinit.globalcomment);
+ # endif /* !NO_ADDFILEINEXISTINGZIP*/
+! TRYFREE(zi);
+ return NULL;
+ }
+ else
+ {
+! *zi = ziinit;
+! return (zipFile)zi;
+ }
+ }
+
+--- 851,921 ----
+ /************************************************************/
+ extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
+ {
+! zip64_internal *p_ziinit = NULL;
+ int err=ZIP_OK;
+
+! p_ziinit = (zip64_internal*)ALLOC(sizeof(zip64_internal));
+! if (p_ziinit==NULL)
+! {
+! return NULL;
+! }
+!
+! p_ziinit->z_filefunc.zseek32_file = NULL;
+! p_ziinit->z_filefunc.ztell32_file = NULL;
+ if (pzlib_filefunc64_32_def==NULL)
+! fill_fopen64_filefunc(&p_ziinit->z_filefunc.zfile_func64);
+ else
+! p_ziinit->z_filefunc = *pzlib_filefunc64_32_def;
+
+! p_ziinit->filestream = ZOPEN64(p_ziinit->z_filefunc,
+ pathname,
+ (append == APPEND_STATUS_CREATE) ?
+ (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
+ (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
+
+! if (p_ziinit->filestream == NULL)
+! {
+! TRYFREE(p_ziinit);
+ return NULL;
++ }
+
+ if (append == APPEND_STATUS_CREATEAFTER)
+! ZSEEK64(p_ziinit->z_filefunc,p_ziinit->filestream,0,SEEK_END);
+
+! p_ziinit->begin_pos = ZTELL64(p_ziinit->z_filefunc,p_ziinit->filestream);
+! p_ziinit->in_opened_file_inzip = 0;
+! p_ziinit->ci.stream_initialised = 0;
+! p_ziinit->number_entry = 0;
+! p_ziinit->add_position_when_writing_offset = 0;
+! init_linkedlist(&(p_ziinit->central_dir));
+
+
+ /* now we add file in a zipfile */
+ # ifndef NO_ADDFILEINEXISTINGZIP
+! p_ziinit->globalcomment = NULL;
+ if (append == APPEND_STATUS_ADDINZIP)
+ {
+ // Read and Cache Central Directory Records
+! err = LoadCentralDirectoryRecord(p_ziinit);
+ }
+
+ if (globalcomment)
+ {
+! *globalcomment = p_ziinit->globalcomment;
+ }
+ # endif /* !NO_ADDFILEINEXISTINGZIP*/
+
+ if (err != ZIP_OK)
+ {
+ # ifndef NO_ADDFILEINEXISTINGZIP
+! TRYFREE(p_ziinit->globalcomment);
+ # endif /* !NO_ADDFILEINEXISTINGZIP*/
+! TRYFREE(p_ziinit);
+ return NULL;
+ }
+ else
+ {
+! return (zipFile)p_ziinit;
+ }
+ }
+
+***************
+*** 1697,1703 ****
+ if (err==ZIP_OK)
+ err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
+
+! free(zi->ci.central_header);
+
+ if (err==ZIP_OK)
+ {
+--- 1699,1705 ----
+ if (err==ZIP_OK)
+ err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
+
+! TRYFREE(zi->ci.central_header);
+
+ if (err==ZIP_OK)
+ {
+***************
+*** 2005,2007 ****
+--- 2007,2015 ----
+
+ return retVal;
+ }
++
++ extern void ZEXPORT setZipMemoryFunc (zip_malloc_func mallocfunc, zip_free_func freefunc)
++ {
++ zipmallocfunc = mallocfunc;
++ zipfreefunc = freefunc;
++ }
+\ No newline at end of file
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/contrib/minizip/zip.h zlib_h6/contrib/minizip/zip.h
+*** zlib/contrib/minizip/zip.h 2022-08-26 10:49:25.772000000 +0800
+--- zlib_h6/contrib/minizip/zip.h 2022-08-26 10:49:16.920000000 +0800
+***************
+*** 360,365 ****
+--- 360,373 ----
+ zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
+ */
+
++
++ typedef voidp (*zip_malloc_func) OF((size_t size));
++ typedef void (*zip_free_func) OF((voidp address));
++ extern void ZEXPORT setZipMemoryFunc OF((zip_malloc_func mfunc, zip_free_func ffunc));
++ /*
++ set customised mallo/free functions
++ */
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/crc32.c zlib_h6/crc32.c
+*** zlib/crc32.c 2022-08-26 10:49:25.776000000 +0800
+--- zlib_h6/crc32.c 2022-08-26 10:49:16.924000000 +0800
+***************
+*** 101,106 ****
+--- 101,109 ----
+ /* Local functions. */
+ local z_crc_t multmodp OF((z_crc_t a, z_crc_t b));
+ local z_crc_t x2nmodp OF((z_off64_t n, unsigned k));
++ local z_word_t byte_swap OF((z_word_t word));
++ local z_crc_t crc_word OF((z_word_t data));
++ local z_word_t crc_word_big OF((z_word_t data));
+
+ /* If available, use the ARM processor CRC32 instruction. */
+ #if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) && W == 8
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/inflate.c zlib_h6/inflate.c
+*** zlib/inflate.c 2022-08-26 10:49:25.788000000 +0800
+--- zlib_h6/inflate.c 2022-08-26 10:49:16.936000000 +0800
+***************
+*** 101,106 ****
+--- 101,114 ----
+ #endif
+ local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
+ unsigned len));
++
++ #ifdef Z_INFLATE_HOOK
++ local inflate_hook_func z_InflateTaskHook = Z_NULL;
++ void ZEXPORT inflateHookFuncRegister(inflate_hook_func func)
++ {
++ z_InflateTaskHook = func;
++ }
++ #endif
+
+ local int inflateStateCheck(strm)
+ z_streamp strm;
+***************
+*** 653,659 ****
+ in = have;
+ out = left;
+ ret = Z_OK;
+! for (;;)
+ switch (state->mode) {
+ case HEAD:
+ if (state->wrap == 0) {
+--- 661,672 ----
+ in = have;
+ out = left;
+ ret = Z_OK;
+! for (;;) {
+! #ifdef Z_INFLATE_HOOK
+! if (z_InflateTaskHook != Z_NULL) {
+! z_InflateTaskHook();
+! }
+! #endif
+ switch (state->mode) {
+ case HEAD:
+ if (state->wrap == 0) {
+***************
+*** 1267,1272 ****
+--- 1280,1286 ----
+ default:
+ return Z_STREAM_ERROR;
+ }
++ }
+
+ /*
+ Return from inflate(), updating the total counts and the check value.
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/zconf.h zlib_h6/zconf.h
+*** zlib/zconf.h 2022-08-26 10:49:25.792000000 +0800
+--- zlib_h6/zconf.h 2022-08-26 10:49:16.940000000 +0800
+***************
+*** 8,13 ****
+--- 8,17 ----
+ #ifndef ZCONF_H
+ #define ZCONF_H
+
++ #ifdef INFLATE_HOOK /* may be set to # if 1 by ./configure --inflatehook */
++ #define Z_INFLATE_HOOK
++ #endif
++
+ /*
+ * If you *really* need a unique prefix for all types and library functions,
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
+***************
+*** 125,130 ****
+--- 129,137 ----
+ # define inflate_copyright z_inflate_copyright
+ # define inflate_fast z_inflate_fast
+ # define inflate_table z_inflate_table
++ # ifdef Z_INFLATE_HOOK
++ # define inflateHookFuncRegister z_inflateHookFuncRegister
++ # endif
+ # ifndef Z_SOLO
+ # define uncompress z_uncompress
+ # define uncompress2 z_uncompress2
+***************
+*** 163,168 ****
+--- 170,177 ----
+ # define gz_header_s z_gz_header_s
+ # define internal_state z_internal_state
+
++ /* variable from zutil.h */
++ # define z_errmsg z_z_errmsg
+ #endif
+
+ #if defined(__MSDOS__) && !defined(MSDOS)
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/zconf.h.cmakein zlib_h6/zconf.h.cmakein
+*** zlib/zconf.h.cmakein 2022-08-26 10:49:25.792000000 +0800
+--- zlib_h6/zconf.h.cmakein 2022-08-26 10:49:16.940000000 +0800
+***************
+*** 9,14 ****
+--- 9,15 ----
+ #define ZCONF_H
+ #cmakedefine Z_PREFIX
+ #cmakedefine Z_HAVE_UNISTD_H
++ #cmakedefine Z_INFLATE_HOOK
+
+ /*
+ * If you *really* need a unique prefix for all types and library functions,
+***************
+*** 127,132 ****
+--- 128,136 ----
+ # define inflate_copyright z_inflate_copyright
+ # define inflate_fast z_inflate_fast
+ # define inflate_table z_inflate_table
++ # ifdef Z_INFLATE_HOOK
++ # define inflateHookFuncRegister z_inflateHookFuncRegister
++ # endif
+ # ifndef Z_SOLO
+ # define uncompress z_uncompress
+ # define uncompress2 z_uncompress2
+***************
+*** 165,170 ****
+--- 169,176 ----
+ # define gz_header_s z_gz_header_s
+ # define internal_state z_internal_state
+
++ /* variable from zutil.h */
++ # define z_errmsg z_z_errmsg
+ #endif
+
+ #if defined(__MSDOS__) && !defined(MSDOS)
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/zconf.h.in zlib_h6/zconf.h.in
+*** zlib/zconf.h.in 2022-08-26 10:49:25.792000000 +0800
+--- zlib_h6/zconf.h.in 2022-08-26 10:49:16.940000000 +0800
+***************
+*** 8,13 ****
+--- 8,17 ----
+ #ifndef ZCONF_H
+ #define ZCONF_H
+
++ #ifdef INFLATE_HOOK /* may be set to # if 1 by ./configure --inflatehook */
++ #define Z_INFLATE_HOOK
++ #endif
++
+ /*
+ * If you *really* need a unique prefix for all types and library functions,
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
+***************
+*** 125,130 ****
+--- 129,137 ----
+ # define inflate_copyright z_inflate_copyright
+ # define inflate_fast z_inflate_fast
+ # define inflate_table z_inflate_table
++ # ifdef Z_INFLATE_HOOK
++ # define inflateHookFuncRegister z_inflateHookFuncRegister
++ # endif
+ # ifndef Z_SOLO
+ # define uncompress z_uncompress
+ # define uncompress2 z_uncompress2
+***************
+*** 163,168 ****
+--- 170,177 ----
+ # define gz_header_s z_gz_header_s
+ # define internal_state z_internal_state
+
++ /* variable from zutil.h */
++ # define z_errmsg z_z_errmsg
+ #endif
+
+ #if defined(__MSDOS__) && !defined(MSDOS)
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/zlib.h zlib_h6/zlib.h
+*** zlib/zlib.h 2022-08-26 10:49:25.796000000 +0800
+--- zlib_h6/zlib.h 2022-08-26 10:49:16.940000000 +0800
+***************
+*** 217,222 ****
+--- 217,227 ----
+
+ /* basic functions */
+
++ #ifdef Z_INFLATE_HOOK
++ typedef void (*inflate_hook_func)(void);
++ ZEXTERN void ZEXPORT inflateHookFuncRegister(inflate_hook_func func);
++ #endif
++
+ ZEXTERN const char * ZEXPORT zlibVersion OF((void));
+ /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
+ If the first character differs, the library code actually used is not
+diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' zlib/zutil.h zlib_h6/zutil.h
+*** zlib/zutil.h 2022-08-26 10:49:25.796000000 +0800
+--- zlib_h6/zutil.h 2022-08-26 10:49:16.940000000 +0800
+***************
+*** 193,198 ****
+--- 193,199 ----
+ (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
+ ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
+ ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
++ ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t));
+ #endif
+
+ /* common defaults */
diff --git a/3rd/gstor/dependency/zstd/.gitignore b/3rd/gstor/dependency/zstd/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..5438a468d4a0b02cc192a1d91cc192327e8ae32e
--- /dev/null
+++ b/3rd/gstor/dependency/zstd/.gitignore
@@ -0,0 +1 @@
+zstd/
diff --git a/3rd/gstor/dependency/zstd/README.txt b/3rd/gstor/dependency/zstd/README.txt
new file mode 100644
index 0000000000000000000000000000000000000000..ec6b09a7c412b8e1a32b70393c0ba2158b880963
--- /dev/null
+++ b/3rd/gstor/dependency/zstd/README.txt
@@ -0,0 +1,10 @@
+open source target name :zstd
+source code repository : product warehouse
+compile dependency: NULL
+upgrade open source package method:
+----|pull command : python $(pwd)../../build/pull_open_source.py "path" "name" "id"
+ |----path : the parent directory name
+ |----name:the package name in product warehouse
+ |----id:pdm version id
+the compile command : sh ./build.sh
+Patch Info:
diff --git a/3rd/gstor/dependency/zstd/build.sh b/3rd/gstor/dependency/zstd/build.sh
new file mode 100644
index 0000000000000000000000000000000000000000..df89c7affc094b03f0e2a5255c49ee9cb84362cc
--- /dev/null
+++ b/3rd/gstor/dependency/zstd/build.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+# *************************************************************************
+# Copyright: (c) Huawei Technologies Co., Ltd. 2020. All rights reserved
+#
+# description: the script that make install zstd
+# date: 2020-01-16
+# version: 1.0
+# history:
+#
+# *************************************************************************
+set -e
+LOCAL_DIR=$(pwd)
+
+TAR_SOURCE_FILE=zstd-1.5.2.tar.gz
+export PACKAGE=zstd
+[ -n "${PACKAGE}" ] && rm -rf ${PACKAGE}
+mkdir ${PACKAGE}
+tar -zxf $TAR_SOURCE_FILE -C $PACKAGE --strip-components 1
+cd $PACKAGE
+mkdir -p ../install_comm/lib/
+cd build/cmake/
+mkdir build
+cd build
+cmake -DZSTD_BUILD_STATIC=on -DCMAKE_INSTALL_PREFIX=../../../../install_comm ..
+sed -i 's/-std=c99/-std=c99 -Wl,-z,relro,-z,now,-z,noexecstack -fPIC -fstack-protector-strong/g' ./programs/CMakeFiles/zstd.dir/flags.make
+sed -i 's/-std=c99/-std=c99 -Wl,-z,relro,-z,now,-z,noexecstack -fPIC -fstack-protector-strong/g' ./programs/CMakeFiles/zstd.dir/link.txt
+sed -i 's/-std=c99/-std=c99 -Wl,-z,relro,-z,now,-z,noexecstack -fPIC -fstack-protector-strong/g' ./programs/CMakeFiles/zstd-frugal.dir/flags.make
+sed -i 's/-std=c99/-std=c99 -Wl,-z,relro,-z,now,-z,noexecstack -fPIC -fstack-protector-strong/g' ./programs/CMakeFiles/zstd-frugal.dir/link.txt
+sed -i 's/-std=c99/-std=c99 -Wl,-z,relro,-z,now,-z,noexecstack -fPIC -fstack-protector-strong/g' ./lib/CMakeFiles/libzstd_static.dir/flags.make
+sed -i 's/-std=c99/-std=c99 -Wl,-z,relro,-z,now,-z,noexecstack -fPIC -fstack-protector-strong/g' ./lib/CMakeFiles/libzstd_static.dir/link.txt
+sed -i 's/-std=c99/-std=c99 -Wl,-z,relro,-z,now,-z,noexecstack -fPIC -fstack-protector-strong/g' ./lib/CMakeFiles/libzstd_shared.dir/flags.make
+sed -i 's/-std=c99/-std=c99 -Wl,-z,relro,-z,now,-z,noexecstack -fPIC -fstack-protector-strong/g' ./lib/CMakeFiles/libzstd_shared.dir/link.txt
+make -j4
+make install
+
+if [ -d "../../../../install_comm/lib64" ]; then
+ mv ../../../../install_comm/lib64/libzstd* ../../../../install_comm/lib/
+fi
+
+INSTALL_DIR=${LOCAL_DIR}/../../output/kernel/dependency/zstd
+# copy lib to destination
+mkdir -p ${INSTALL_DIR}/bin
+mkdir -p ${INSTALL_DIR}/include
+mkdir -p ${INSTALL_DIR}/lib
+
+cp ${LOCAL_DIR}/install_comm/bin/* ${INSTALL_DIR}/bin/
+cp ${LOCAL_DIR}/install_comm/include/* ${INSTALL_DIR}/include/
+cp -d ${LOCAL_DIR}/install_comm/lib/libzstd.* ${INSTALL_DIR}/lib/
+
diff --git a/3rd/gstor/dependency/zstd/zstd-1.5.2.tar.gz b/3rd/gstor/dependency/zstd/zstd-1.5.2.tar.gz
new file mode 100644
index 0000000000000000000000000000000000000000..c8c970db695ea9729b90511ff17d89d423a8dcdf
Binary files /dev/null and b/3rd/gstor/dependency/zstd/zstd-1.5.2.tar.gz differ
diff --git a/3rd/gstor/env.sh b/3rd/gstor/env.sh
deleted file mode 100644
index 42a787713f424d0d49ea7dcc7557a40ad20d447e..0000000000000000000000000000000000000000
--- a/3rd/gstor/env.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#export GSTOR_PATH=${PWD}/output/lib
-#export CJSON_PATH=${PWD}/library/cJSON/lib
-export BINARYLIBS=/opt/openGauss-third_party_binarylibs_Centos7.6_x86_64 # 此处需要修改为自己环境中的路径
-#export GCC_PATH=$BINARYLIBS/buildtools/gcc7.3
-#export CC=$GCC_PATH/gcc/bin/gcc
-#export CXX=$GCC_PATH/gcc/bin/g++
-#export LD_LIBRARY_PATH=${GSTOR_PATH}:${CJSON_PATH}:$GCC_PATH/gcc/lib64:$GCC_PATH/isl/lib:$GCC_PATH/mpc/lib/:$GCC_PATH/mpfr/lib/:$GCC_PATH/gmp/lib/:$LD_LIBRARY_PATH
-#export PATH=${PWD}/output/bin:$GCC_PATH/gcc/bin:$PATH
diff --git a/3rd/gstor/src/CMakeLists.txt b/3rd/gstor/src/CMakeLists.txt
index f83a280213db47c683f6152c331c8586d5b61384..23773445c31cffa8f88f8a933a2c25ede29972dd 100644
--- a/3rd/gstor/src/CMakeLists.txt
+++ b/3rd/gstor/src/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14.1)
MESSAGE(STATUS "DCC CMAKE BUILD BEGIN")
# add_subdirectory(client)
-# add_subdirectory(tools)
+add_subdirectory(interface)
add_subdirectory(storage)
# add_subdirectory(utils)
add_subdirectory(tools)
diff --git a/3rd/gstor/src/interface/c/CMakeLists.txt b/3rd/gstor/src/interface/c/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..be9fbb0121273d9e0a80616f3bf733d92f60b8d5
--- /dev/null
+++ b/3rd/gstor/src/interface/c/CMakeLists.txt
@@ -0,0 +1,270 @@
+# cmake_minimum_required(VERSION 3.14.1)
+
+# project(gstordev)
+
+# if (UNIX)
+# message(${CMAKE_BUILD_TYPE})
+# if (${CMAKE_BUILD_TYPE} STREQUAL "Debug"
+# OR ${CMAKE_BUILD_TYPE} STREQUAL "")
+# message(STATUS "CMAKE_BUILD_TYPE is Debug")
+# set(CMAKE_BUILD_TYPE Debug)
+# add_compile_definitions(_DEBUG)
+# elseif (${CMAKE_BUILD_TYPE} STREQUAL "Release")
+# message(STATUS "CMAKE_BUILD_TYPE is Release")
+# set(CMAKE_BUILD_TYPE Release)
+# set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
+# else ()
+# message(STATUS "unknown CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
+# endif ()
+
+# OPTION(ENABLE_GCOV "GSTORE Enable gcov (debug, Linux builds only)" OFF)
+# message(STATUS "GSTORE ENABLE_GCOV = ${ENABLE_GCOV}")
+# IF (ENABLE_GCOV AND NOT WIN32 AND NOT APPLE)
+# message(STATUS "GSTORE Enable gcov (debug, Linux builds only).")
+# add_compile_options(-g -O0 -fprofile-arcs -ftest-coverage)
+# ENDIF()
+
+# # Use "-fPIC" / "-fPIE" for all targets by default, including static libs
+# set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+# # CMake doesn't add "-pie" by default for executables
+# add_link_options(-pie)
+
+# execute_process(
+# COMMAND uname -p
+# OUTPUT_VARIABLE OS_ARCH
+# OUTPUT_STRIP_TRAILING_WHITESPACE
+# )
+# set(CMAKE_SYSTEM_PROCESSOR ${OS_ARCH})
+
+# if (OS_ARCH STREQUAL "aarch64")
+# message(STATUS "aarch64 CPU")
+# option(USE_H1620 OFF)
+# if (USE_H1620)
+# add_compile_options(-march=armv8-a+crc+lse)
+# message(STATUS "Toolchain: Build aarch64 USE_H1620")
+# else ()
+# add_compile_options(-march=armv8-a+crc)
+# endif (USE_H1620)
+
+# add_compile_options(-mtune=cortex-a72 -fsigned-char -g -ggdb3 -march=armv8-a+crc -funwind-tables)
+# else ()
+# message(STATUS "x86_64 CPU")
+# add_compile_options(-mtune=nocona -fsigned-char -msse4.2 )
+# endif ()
+# else ()
+# set(CMAKE_BUILD_TYPE Debug)
+# add_compile_definitions(_DEBUG)
+# endif ()
+
+# if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
+# message("++ 64 bit architecture")
+# set(ARCHBIT "64")
+# else ()
+# message("++ 32 bit architecture")
+# set(ARCHBIT "32")
+# add_compile_options(-m32)
+# endif ()
+
+# if (UNIX)
+# set_property(TARGET PROPERTY C_STANDARD 99)
+# add_compile_options(-fPIC -Wall -MMD -fno-strict-aliasing -fsigned-char -fms-extensions)
+# add_compile_definitions(_GNU_SOURCE _LARGEFILE64_SOURCE KNL_PREFIX _REENTRANT)
+
+# add_compile_options(-fvisibility=default -fstack-protector-strong --param ssp-buffer-size=4)
+# add_link_options(-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now)
+# set(CMAKE_SKIP_RPATH TRUE)
+# endif ()
+
+
+
+# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -g -ldl -pthread")
+# add_compile_options(-fno-common)
+# add_compile_options(-Wtrampolines)
+# add_compile_options(-freg-struct-return)
+# add_compile_options(-pipe)
+# add_link_options(-Wl,-Bsymbolic)
+# if (UNIX)
+# add_link_options(-rdynamic)
+# endif()
+
+
+# MESSAGE(STATUS "=============== CMAKE BUILD BEGIN=============")
+
+# ## patch
+# set(GSTOR_SRC_HOME ${CMAKE_CURRENT_SOURCE_DIR}/../../)
+
+# set(API_C_PATH ${CMAKE_CURRENT_SOURCE_DIR})
+# set(STORAGE_PATH ${GSTOR_SRC_HOME}/storage/)
+# set(STORAGE_GSTOR_PATH ${GSTOR_SRC_HOME}/storage/gstor/)
+# set(GSTOR_ZEKERNEL_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/)
+# set(ZEKERNEL_COMMON_PATH_1 ${GSTOR_SRC_HOME}/storage/gstor/zekernel/common/)
+# set(ZEKERNEL_COMMON_PATH_2 ${GSTOR_SRC_HOME}/storage/gstor/zekernel/common/variant/)
+# set(ZEKERNEL_KERNEL_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/)
+# set(KERNEL_BACKUP_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/backup/)
+# set(KERNEL_BUFFER_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/buffer/)
+# set(KERNEL_CATALOG_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/catalog/)
+# set(KERNEL_COMMON_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/common/)
+# set(KERNEL_DAEMON_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/daemon/)
+# set(KERNEL_FLASHBACK_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/flashback/)
+# set(KERNEL_INCLUDE_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/include/)
+# set(KERNEL_INDEX_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/index/)
+# set(KERNEL_LOB_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/lob/)
+# set(KERNEL_PERSIST_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/persist/)
+# # set(KERNEL_BACKUP_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/replication/)
+# set(KERNEL_SEQUENCE_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/sequence/)
+# # set(KERNEL_BACKUP_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/statistics/)
+# set(KERNEL_TABLE_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/table/)
+# set(KERNEL_TABLESPACE_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/tablespace/)
+# set(KERNEL_XACT_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/kernel/xact/)
+# set(ZEKERNEL_PROTOCOL_PATH ${GSTOR_SRC_HOME}/storage/gstor/zekernel/protocol/)
+# set(STORAGE_KV_EXECUTOR_PATH ${GSTOR_SRC_HOME}/storage/kv_executor/)
+
+# ## 3rd path
+# set(GSTOR_HOME ${CMAKE_CURRENT_SOURCE_DIR}/../../../)
+# set(SECUREC_INC_PATH "${GSTOR_HOME}/output/inc/huawei_security")
+# set(OPENSSL_PATH "${GSTOR_HOME}/output/inc/openssl/")
+# set(OPENSSL_PATH_EX "${GSTOR_HOME}/output/inc/openssl/openssl")
+# set(LZ4_INC_PATH "${GSTOR_HOME}/output/inc/lz4")
+# set(ZLIB_INC_PATH "${GSTOR_HOME}/output/inc/zlib")
+# set(ZSTANDARD_INC_PATH "${GSTOR_HOME}/output/inc/zstd")
+# set(LIBAIO_INC_PATH "${GSTOR_HOME}/output/inc/libaio")
+# set(PCRE_INC_PATH "${GSTOR_HOME}/library/pcre/include")
+# # 3rd lib path
+# set(SECUREC_LIB_PATH "${GSTOR_HOME}/output/lib")
+# set(OPENSSL_LIB_PATH "${GSTOR_HOME}/output/lib")
+# set(LZ4_LIB_PATH "${GSTOR_HOME}/output/lib")
+# set(ZLIB_LIB_PATH "${GSTOR_HOME}/output/lib")
+# set(ZSTANDARD_LIB_PATH "${GSTOR_HOME}/output/lib")
+# set(PCRE_LIB_PATH "${GSTOR_HOME}/library/pcre/lib")
+
+# ## 3rd include
+# include_directories(${SECUREC_INC_PATH})
+# include_directories(${OPENSSL_PATH})
+# include_directories(${OPENSSL_PATH_EX})
+# include_directories(${LZ4_INC_PATH})
+# include_directories(${ZLIB_INC_PATH})
+# include_directories(${ZSTANDARD_INC_PATH})
+# include_directories(${LIBAIO_INC_PATH})
+# include_directories(${PCRE_INC_PATH})
+
+
+# ## include
+# include_directories(${GSTOR_SRC_HOME})
+# include_directories(${API_C_PATH})
+# include_directories(${STORAGE_PATH})
+# include_directories(${STORAGE_GSTOR_PATH})
+# include_directories(${GSTOR_ZEKERNEL_PATH})
+# include_directories(${ZEKERNEL_COMMON_PATH_1})
+# include_directories(${ZEKERNEL_COMMON_PATH_2})
+# include_directories(${ZEKERNEL_KERNEL_PATH})
+# include_directories(${KERNEL_BACKUP_PATH})
+# include_directories(${KERNEL_BUFFER_PATH})
+# include_directories(${KERNEL_CATALOG_PATH})
+# include_directories(${KERNEL_COMMON_PATH})
+# include_directories(${KERNEL_DAEMON_PATH})
+# include_directories(${KERNEL_FLASHBACK_PATH})
+# include_directories(${KERNEL_INCLUDE_PATH})
+# include_directories(${KERNEL_INDEX_PATH})
+# include_directories(${KERNEL_LOB_PATH})
+# include_directories(${KERNEL_PERSIST_PATH})
+# include_directories(${KERNEL_SEQUENCE_PATH})
+# include_directories(${KERNEL_TABLE_PATH})
+# include_directories(${KERNEL_TABLESPACE_PATH})
+# include_directories(${KERNEL_XACT_PATH})
+# include_directories(${ZEKERNEL_PROTOCOL_PATH})
+# include_directories(${STORAGE_KV_EXECUTOR_PATH})
+
+# ## link path
+# link_directories(${SECUREC_LIB_PATH} ${OPENSSL_LIB_PATH} ${LZ4_LIB_PATH} ${ZLIB_LIB_PATH} ${ZSTANDARD_LIB_PATH} ${LIBRARY_OUTPUT_PATH} ${PCRE_LIB_PATH})
+
+# ## source
+# aux_source_directory(${API_C_PATH} API_C_SRC)
+# aux_source_directory(${STORAGE_PATH} STORAGE_SRC)
+# aux_source_directory(${STORAGE_GSTOR_PATH} STORAGE_GSTOR_SRC)
+# aux_source_directory(${GSTOR_ZEKERNEL_PATH} GSTOR_ZEKERNEL_SRC)
+# aux_source_directory(${ZEKERNEL_COMMON_PATH_1} ZEKERNEL_COMMON_SRC)
+# aux_source_directory(${ZEKERNEL_COMMON_PATH_2} ZEKERNEL_COMMON_SRC)
+# aux_source_directory(${ZEKERNEL_KERNEL_PATH} ZEKERNEL_KERNEL_SRC)
+# aux_source_directory(${KERNEL_BACKUP_PATH} KERNEL_BACKUP_SRC)
+# aux_source_directory(${KERNEL_BUFFER_PATH} KERNEL_BUFFER_SRC)
+# aux_source_directory(${KERNEL_CATALOG_PATH} KERNEL_CATALOG_SRC)
+# aux_source_directory(${KERNEL_COMMON_PATH} KERNEL_COMMON_SRC)
+# aux_source_directory(${KERNEL_DAEMON_PATH} KERNEL_DAEMON_SRC)
+# aux_source_directory(${KERNEL_FLASHBACK_PATH} KERNEL_FLASHBACK_SRC)
+# aux_source_directory(${KERNEL_INCLUDE_PATH} KERNEL_INCLUDE_SRC)
+# aux_source_directory(${KERNEL_INDEX_PATH} KERNEL_INDEX_SRC)
+# aux_source_directory(${KERNEL_LOB_PATH} KERNEL_LOB_SRC)
+# aux_source_directory(${KERNEL_PERSIST_PATH} KERNEL_PERSIST_SRC)
+# aux_source_directory(${KERNEL_SEQUENCE_PATH} KERNEL_SEQUENCE_SRC)
+# aux_source_directory(${KERNEL_TABLE_PATH} KERNEL_TABLE_SRC)
+# aux_source_directory(${KERNEL_TABLESPACE_PATH} KERNEL_TABLESPACE_SRC)
+# aux_source_directory(${KERNEL_XACT_PATH} KERNEL_XACT_SRC)
+# aux_source_directory(${ZEKERNEL_PROTOCOL_PATH} ZEKERNEL_PROTOCOL_SRC)
+# aux_source_directory(${STORAGE_KV_EXECUTOR_PATH} STORAGE_KV_EXECUTOR_SRC)
+
+
+# set(GSTOR_TOTAL_SRC
+# ${API_C_SRC}
+# ${STORAGE_SRC}
+# ${STORAGE_GSTOR_SRC}
+# ${KERNEL_CM_SRC}
+# ${GSTOR_ZEKERNEL_SRC}
+# ${ZEKERNEL_COMMON_SRC}
+# ${ZEKERNEL_KERNEL_SRC}
+# ${KERNEL_BACKUP_SRC}
+# ${KERNEL_BUFFER_SRC}
+# ${KERNEL_CATALOG_SRC}
+# ${KERNEL_COMMON_SRC}
+# ${KERNEL_DAEMON_SRC}
+# ${KERNEL_FLASHBACK_SRC}
+# ${KERNEL_INCLUDE_SRC}
+# ${KERNEL_INDEX_SRC}
+# ${KERNEL_LOB_SRC}
+# ${KERNEL_PERSIST_SRC}
+# ${KERNEL_SEQUENCE_SRC}
+# ${KERNEL_TABLE_SRC}
+# ${KERNEL_TABLESPACE_SRC}
+# ${KERNEL_XACT_SRC}
+# ${ZEKERNEL_PROTOCOL_SRC}
+# ${STORAGE_KV_EXECUTOR_SRC})
+
+# MESSAGE(STATUS "------------------------------------------------------------")
+# MESSAGE(STATUS "API_C_PATH: ${API_C_PATH}")
+# MESSAGE(STATUS "ZEKERNEL_KERNEL_PATH: ${ZEKERNEL_KERNEL_PATH}")
+# MESSAGE(STATUS "STORAGE_KV_EXECUTOR_PATH: ${STORAGE_KV_EXECUTOR_PATH}")
+# MESSAGE(STATUS "------------------------------------------------------------")
+
+# set(vpp_libsecurec "securec")
+# set(3rd_liblz4 "lz4")
+# set(3rd_libz "z")
+# set(3rd_libzstd "zstd")
+# set(3rd_libssl "ssl")
+# set(3rd_lib_crypto "crypto")
+# set(3rd_libpcre "pcre")
+
+# add_library(gstor_dev_c SHARED ${GSTOR_TOTAL_SRC})
+# target_link_libraries(gstor_dev_c PRIVATE ${3rd_libzstd} ${3rd_libssl} ${3rd_lib_crypto} ${3rd_liblz4} ${3rd_libz} ${vpp_libsecurec})
+
+MESSAGE(STATUS "=============== CMAKE BUILD BEGIN=============")
+
+cmake_minimum_required(VERSION 3.14.1)
+
+# open source include
+set(GSTOR_SRC_HOME ${CMAKE_CURRENT_SOURCE_DIR}/../../)
+set(GSTOR_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../output/lib/)
+
+include_directories(${GSTOR_SRC_HOME})
+include_directories(${DCC_GSTOR_INC_PATH})
+include_directories(${DCC_SECUREC_INC_PATH})
+
+link_directories(${GSTOR_LIB_PATH})
+
+# aux_source_directory(. GSTOR_DEV_C_SRC)
+
+set(GSTOR_DEV_C_SRC
+ ${CMAKE_CURRENT_SOURCE_DIR}/gstor.c
+)
+
+add_library(gstor_dev_c SHARED ${GSTOR_DEV_C_SRC})
+target_link_libraries(gstor_dev_c PUBLIC storage pthread dl m rt ${G_BIN_EXT_LIBS})
+target_include_directories(gstor_dev_c PUBLIC ${GSTOR_LIB_PATH})
diff --git a/3rd/gstor/src/interface/c/gstor.c b/3rd/gstor/src/interface/c/gstor.c
index c9d6928a73fbee9acd20ea0aaa20e7ca0f1b0329..a6928c2b89890ae0186991bd1070819052a6d4fc 100644
--- a/3rd/gstor/src/interface/c/gstor.c
+++ b/3rd/gstor/src/interface/c/gstor.c
@@ -136,7 +136,7 @@ status_t gstor_kv_rollback(void *handle)
return kv_rollback(handle);
}
-void freeReplyObject(gstorReply *reply)
+void gstor_freeReplyObject(gstorReply *reply)
{
if (reply) {
free(reply);
diff --git a/3rd/gstor/src/interface/c/gstor.h b/3rd/gstor/src/interface/c/gstor.h
index 942d301e125cff5884a4dd4e2b205bb050b1e4f1..eeb78dcba7ee049568df462ce5ae8fb2d5dfa3c0 100644
--- a/3rd/gstor/src/interface/c/gstor.h
+++ b/3rd/gstor/src/interface/c/gstor.h
@@ -26,7 +26,7 @@
#include "stdio.h"
-#include "storage/kv_executor/kv_executor.h"
+#include "storage/storage.h"
#ifdef __cplusplus
extern "C" {
@@ -45,21 +45,21 @@ typedef struct gstorContext_t {
char errstr[128]; /* String representation of error when applicable */
} gstorContext;
-status_t gstor_startup_db(int dbtype, char *path);
-void gstor_shutdown_db(void);
+EXPORT_API status_t gstor_startup_db(int dbtype, char *path);
+EXPORT_API void gstor_shutdown_db(void);
-status_t alloc_kv_handle(void **handle);
-void free_kv_handle(void *handle);
+EXPORT_API status_t alloc_kv_handle(void **handle);
+EXPORT_API void free_kv_handle(void *handle);
-void *gstor_command_set(void *handle, char *key, char *val);
-void *gstor_command_get(void *handle, char *key);
-void *gstor_command_del(void *handle, char *key, int prefix, int *count);
+EXPORT_API void *gstor_command_set(void *handle, char *key, char *val);
+EXPORT_API void *gstor_command_get(void *handle, char *key);
+EXPORT_API void *gstor_command_del(void *handle, char *key, int prefix, int *count);
-status_t gstor_kv_begin(void *handle);
-status_t gstor_kv_commit(void *handle);
-status_t gstor_kv_rollback(void *handle);
+EXPORT_API status_t gstor_kv_begin(void *handle);
+EXPORT_API status_t gstor_kv_commit(void *handle);
+EXPORT_API status_t gstor_kv_rollback(void *handle);
-void freeReplyObject(gstorReply *reply);
+EXPORT_API void gstor_freeReplyObject(gstorReply *reply);
#ifdef __cplusplus
}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/.idea/.gitignore b/3rd/gstor/src/interface/rust/ncti-orm/.idea/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/.idea/modules.xml b/3rd/gstor/src/interface/rust/ncti-orm/.idea/modules.xml
new file mode 100644
index 0000000000000000000000000000000000000000..add67983fe39fe910e8b20cad4407d0f3416b7b9
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/.idea/ncti-orm.iml b/3rd/gstor/src/interface/rust/ncti-orm/.idea/ncti-orm.iml
new file mode 100644
index 0000000000000000000000000000000000000000..0c752845101c6193d38b6e3d654b15da9f3fba51
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/.idea/ncti-orm.iml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/.idea/vcs.xml b/3rd/gstor/src/interface/rust/ncti-orm/.idea/vcs.xml
new file mode 100644
index 0000000000000000000000000000000000000000..821e530ddc3b630be065c610c6d0f2f9dfba9472
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/Cargo.toml b/3rd/gstor/src/interface/rust/ncti-orm/Cargo.toml
new file mode 100644
index 0000000000000000000000000000000000000000..855ce7910843cfccaa3d3a0858453f39e28c3b77
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/Cargo.toml
@@ -0,0 +1,32 @@
+[workspace]
+members = [
+ ".",
+ "rbs",
+ "codegen",
+ "macro_driver",
+ "interface"
+]
+[package]
+name = "ncti_orm"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+
+[dependencies]
+rbs = { version = "0.1.0", path = "rbs" }
+macro_driver = { version = "0.1.0", path = "macro_driver" }
+codegen = { version = "0.1.0", path = "codegen"}
+interface = {path = "interface"}
+quote = "1.0"
+regex = "1"
+serde_json = "1.0"
+serde = { version = "1.0", features = ["derive"] }
+syn = { version = "1.0", features = ["full"] }
+fastdate = { version = "0.1"}
+deadpool = {version="0.9.5", features = ["managed"] }
+tokio = { version = "1", features = ["full"] }
+# actix for unit test
+actix-rt = "*"
+libc = "0.2"
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/README.md b/3rd/gstor/src/interface/rust/ncti-orm/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..bc6be9b0da4cc7e080d3cd3a269037fe0df58807
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/README.md
@@ -0,0 +1,46 @@
+# Ncti Orm
+
+# Ncti Orm
+
+#### 一、工程说明
+##### 1、编程语言:Rust
+##### 2、编译工程:Cargo
+##### 3、目录说明:
+- src: 源代码目录,按子目录划分模块解耦;
+- 依赖工程代码
+ rbs //rbatis 工具
+ macro_driver //创建表宏,创建索引宏,crud宏
+ codegen //工具类 ,model
+ interface //rust - C接口类
+
+#### 二、编译指导
+##### 1、概述
+编译国创Rust 需要依赖gstor ,需要先编译运行gstor生成依赖包 。
+##### 2、操作系统和软件依赖要求
+支持以下操作系统:
+- CentOS 7.6(x86)
+- Cargo
+##### 3、编译工具
+1.VS code remote ssh
+2.Idea remote ssh
+需要安装rust插件
+安装rust环境问题解决:
+1.rust环境搭建
+https://www.runoob.com/rust/rust-setup.html
+2.不做 https 下载验证 ,curl ssl 验证失败
+https://www.codenong.com/35770372/
+ $ curl -s https://install.meteor.com | grep curl
+ curl --progress-bar --fail"$TARBALL_URL" | tar -xzf - -C"$INSTALL_TMPDIR" -o
+要将curl按下,可以在curlrc中添加--insecure:
+ $ echo insecure >> ~/.curlrc
+或者只使用http:
+ $ curl http://install.meteor.com
+3.Vscode Rust linux环境报错
+"/root/.vscode-server/extensions/rust-lang.rust-analyzer-0.3.1394/server/rust-analyzer: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by /root/.vscode-server/extensions/rust-lang.rust-analyzer-0.3.1394/server/rust-analyzer)\n"
+升级 libc
+https://blog.csdn.net/LJL_1003/article/details/127968993
+
+##### 4、代码编译
+
+#####DEMO示例
+运行src 下的main
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/codegen/Cargo.toml b/3rd/gstor/src/interface/rust/ncti-orm/codegen/Cargo.toml
new file mode 100644
index 0000000000000000000000000000000000000000..ee6acf49b4027d2961d575eabc057065b1821433
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/codegen/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "codegen"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+rbs = { version = "0.1.0", path = "../rbs" }
+syn = "1.0"
+quote = "1.0"
+regex = "1"
+serde_json = "1.0"
+serde = { version = "1.0", features = ["derive"] }
+fastdate = { version = "0.1"}
+deadpool = {version="0.9.5", features = ["managed"] }
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/lib.rs b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/lib.rs
new file mode 100644
index 0000000000000000000000000000000000000000..b5614dd82335c52db29069c990b16b6c71b5a8b8
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/lib.rs
@@ -0,0 +1 @@
+pub mod utils;
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/main.rs b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/main.rs
new file mode 100644
index 0000000000000000000000000000000000000000..79757f9f8bd5f81a23ed995c13c49cfee8a18fc9
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/main.rs
@@ -0,0 +1,19 @@
+
+use codegen::utils::model;
+
+fn main() {
+
+ let index=model::StIndexDef {
+ name: "".to_string(),
+ cols: vec![],
+ col_count: 0,
+ is_unique: 0,
+ is_primary: 0,
+ };
+ // Convert the JSON string back to a Point.
+ let mut columns : Vec = Vec::new();
+ columns.push(index);
+ let serialized = serde_json::to_string(&columns).unwrap();
+
+ println!("Hello, world: {}", serialized);
+}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/db.rs b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/db.rs
new file mode 100644
index 0000000000000000000000000000000000000000..0dc3d596caf45fc4ab0bc5f8bdf9d86a8c31df49
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/db.rs
@@ -0,0 +1,39 @@
+use crate::utils::error::Error;
+use rbs::Value;
+use std::fmt::{Debug, Display, Formatter};
+
+
+
+#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
+pub struct ExecResult {
+ pub results: String,
+ pub code: i32
+}
+
+impl Display for ExecResult {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ f.debug_map()
+ .key(&"results")
+ .value(&self.results)
+ .key(&"code")
+ .value(&self.code)
+ .finish()
+ }
+}
+
+
+/// Result set from executing a query against a statement
+pub trait Row: 'static + Send + Debug {
+ /// get meta data about this result set
+ fn meta_data(&self) -> Box;
+
+ /// get Value from index
+ fn get(&mut self, i: usize) -> Result;
+}
+
+/// Meta data for result set
+pub trait MetaData: Debug {
+ fn column_len(&self) -> usize;
+ fn column_name(&self, i: usize) -> String;
+ fn column_type(&self, i: usize) -> String;
+}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/error.rs b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/error.rs
new file mode 100644
index 0000000000000000000000000000000000000000..54aaedc614362db07e2728bc59d77dc2b7cf7ef3
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/error.rs
@@ -0,0 +1,113 @@
+use std::fmt::{Display, Formatter};
+use std::num::{ParseFloatError, ParseIntError, TryFromIntError};
+use std::str::Utf8Error;
+
+#[derive(Debug)]
+pub enum Error {
+ E(String),
+ Io(std::io::Error),
+}
+
+impl Error {
+ #[allow(dead_code)]
+ #[inline]
+ pub fn protocol(err: impl Display) -> Self {
+ Error::E(err.to_string())
+ }
+}
+
+impl Display for Error {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Error::E(e) => std::fmt::Display::fmt(&e, f),
+ Error::Io(e) => f.write_str(&e.to_string()),
+ }
+ }
+}
+impl std::error::Error for Error {}
+impl serde::ser::Error for Error {
+ fn custom(msg: T) -> Self
+ where
+ T: Display,
+ {
+ Self::E(msg.to_string())
+ }
+}
+
+impl From for Error {
+ fn from(arg: std::io::Error) -> Self {
+ Error::E(arg.to_string())
+ }
+}
+
+#[cfg(all(feature = "_tls-native-tls"))]
+impl From for Error {
+ fn from(e: native_tls::Error) -> Self {
+ Error::E(e.to_string())
+ }
+}
+
+impl From for Error {
+ fn from(e: Utf8Error) -> Self {
+ Error::E(e.to_string())
+ }
+}
+
+impl From<&str> for Error {
+ fn from(arg: &str) -> Self {
+ Error::E(arg.to_string())
+ }
+}
+impl From for Error {
+ fn from(arg: String) -> Self {
+ Error::E(arg)
+ }
+}
+
+impl From for Error {
+ fn from(arg: ParseIntError) -> Self {
+ Error::E(arg.to_string())
+ }
+}
+
+impl From for Error {
+ fn from(arg: ParseFloatError) -> Self {
+ Error::E(arg.to_string())
+ }
+}
+
+impl From for Error {
+ fn from(arg: fastdate::error::Error) -> Self {
+ Error::E(arg.to_string())
+ }
+}
+
+impl From for Error {
+ fn from(e: TryFromIntError) -> Self {
+ Error::from(e.to_string())
+ }
+}
+
+impl From for Error {
+ fn from(arg: rbs::Error) -> Self {
+ Error::from(arg.to_string())
+ }
+}
+
+impl From> for Error {
+ fn from(arg: deadpool::managed::PoolError) -> Self {
+ Error::from(format!("{:?}", arg))
+ }
+}
+
+// Format an error message as a `Protocol` error
+#[macro_export]
+macro_rules! err_protocol {
+ ($expr:expr) => {
+ $crate::Error::E($expr.into())
+ };
+
+ ($fmt:expr, $($arg:tt)*) => {
+ $crate::Error::E(format!($fmt, $($arg)*))
+ };
+}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/mod.rs b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/mod.rs
new file mode 100644
index 0000000000000000000000000000000000000000..12200748c9e31c9d4483c455151ef365c5f35c15
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/mod.rs
@@ -0,0 +1,5 @@
+pub mod result;
+pub mod string_util;
+pub mod model;
+pub mod db;
+pub mod error;
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/model.rs b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/model.rs
new file mode 100644
index 0000000000000000000000000000000000000000..eea8a6b7bcdc6593d6d8189e02fb79e158b610fd
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/model.rs
@@ -0,0 +1,98 @@
+use serde::Serialize;
+use serde::Deserialize;
+
+#[derive(Debug, Default,Serialize, Deserialize)]
+pub struct StColumnDef {
+ pub name: String,
+ pub types: String, //字符串VARCHAR,int BIGINT
+ pub col_slot : u16, //字段槽位------加一个字段槽位字段,也就是表字段的序号,从0开始
+ pub size: u16,
+ pub nullable: u8,
+ pub is_primary: u8,
+ pub is_default: u8,
+ pub default_val: String,
+ pub crud_value: String,
+ pub precision: u16,
+ pub comment: String
+}
+
+#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+pub struct StColumnDef4C {
+ pub name: String,
+ pub types: String, //字符串VARCHAR,int BIGINT
+ pub col_slot : u16, //字段槽位------加一个字段槽位字段,也就是表字段的序号,从0开始
+ pub size: u16,
+ pub nullable: u8,
+ pub is_primary: u8,
+ pub is_default: u8,
+ pub default_val: String,
+ pub crud_value: String,
+ pub precision: u16,
+ pub comment: String,
+ pub assign_type_t: u8 //条件类型
+}
+
+
+#[derive(Debug, Default, Serialize, Deserialize)]
+pub struct StIndexDef {
+ pub name: String,
+ pub cols: Vec,
+ pub idx_slot : u16, //索引槽位------加一个索引槽位字段,也就是表索引的序号,从0开始
+ pub col_count: u32,
+ pub is_unique: u8,
+ pub is_primary: u8
+}
+
+
+#[derive(Debug)]
+pub struct Restriction{
+ pub name: String,
+ pub value: String,
+ pub assign: u8
+}
+/**
+ ASSIGN_TYPE_EQUAL = 0, //等于
+ ASSIGN_TYPE_LESS = ASSIGN_TYPE_EQUAL + 1, //小于
+ ASSIGN_TYPE_MORE = ASSIGN_TYPE_EQUAL + 2, //大于
+ ASSIGN_TYPE_LESS_EQUAL = ASSIGN_TYPE_EQUAL + 3, //小于等于
+ ASSIGN_TYPE_MORE_EQUAL = ASSIGN_TYPE_EQUAL + 4, //大于等于
+eq NOT EQUAL 等于
+NE NOT EQUAL 不等于
+GT GREATER THAN 大于
+LT LESS THAN 小于
+GE GREATER THAN OR EQUAL 大于等于
+LE LESS THAN OR EQUAL 小于等于
+**/
+impl Restriction {
+ //构建结构体
+ // pub fn new(name: String, value: String,assign : u8) -> Self {
+ // return Self { name, value,assign};
+ // }
+ //等于
+ pub fn equ(name: String, value: String) -> Self {
+ return Self { name, value, assign: 0 };
+ }
+ // //小于
+ // pub fn lt(name: String, value: String) -> Self {
+ // return Self { name, value, assign: 1 };
+ // }
+ // //大于
+ // pub fn gt(name: String, value: String) -> Self {
+ // return Self { name, value, assign: 2 };
+ // }
+ //
+ // //小于等于
+ // pub fn le(name: String, value: String) -> Self {
+ // return Self { name, value, assign: 3 };
+ // }
+ //
+ // //大于等于
+ // pub fn ge(name: String, value: String) -> Self {
+ // return Self { name, value, assign: 4 };
+ // }
+ //
+ // //不等于
+ // pub fn ne(name: String, value: String) -> Self {
+ // return Self { name, value, assign: 5 };
+ // }
+}
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/result.rs b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/result.rs
new file mode 100644
index 0000000000000000000000000000000000000000..fd569a163b86f52684cef155b83a22b3bdeb25a0
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/result.rs
@@ -0,0 +1,17 @@
+use std::fmt;
+use std::fmt::Formatter;
+
+pub type Result = std::result::Result;
+
+#[derive(Debug, Clone)]
+pub enum CheckError {
+ Simple(String),
+}
+
+impl fmt::Display for CheckError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ match self {
+ CheckError::Simple(txt) => write!(f, "{}", txt),
+ }
+ }
+}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/string_util.rs b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/string_util.rs
new file mode 100644
index 0000000000000000000000000000000000000000..f01b977baebe1d85221a6b91e3e992c8b9346c19
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/codegen/src/utils/string_util.rs
@@ -0,0 +1,21 @@
+pub const LOG_SPACE: &'static str = " ";
+/// convert name to snake name
+pub fn to_snake_name(name: &str) -> String {
+ let len = name.len();
+ let bytes = name.as_bytes();
+ let mut new_name = String::with_capacity(name.len());
+ let mut index = 0;
+ for x in bytes {
+ let c = *x as char;
+ if c.is_ascii_uppercase() {
+ if index != 0 &&(index + 1) != len {
+ new_name.push('_');
+ }
+ new_name.push(c.to_ascii_lowercase() as char);
+ } else {
+ new_name.push(c);
+ }
+ index += 1;
+ }
+ return new_name;
+}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/interface/Cargo.toml b/3rd/gstor/src/interface/rust/ncti-orm/interface/Cargo.toml
new file mode 100644
index 0000000000000000000000000000000000000000..b30702f1e98f3f24ff8cc968720a7717a9c55b5e
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/interface/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "interface"
+version = "0.1.0"
+edition = "2021"
+build = "build.rs"
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+libc = "0.2"
+codegen = { version = "0.1.0", path = "../codegen"}
+serde_json = "1.0"
+serde = { version = "1.0", features = ["derive"] }
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/interface/README.md b/3rd/gstor/src/interface/rust/ncti-orm/interface/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..4a5540e4588e677a378c0171dea38465eb436c42
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/interface/README.md
@@ -0,0 +1,25 @@
+# interface README
+引用代码
+interface文件夹是rust的调用存储引擎适配层C接口的lib库,如果要引用该库,需要以下几个步骤:
+ 1. 将整个文件夹代码加入到工程根目录下
+ 2. 修改根目录下Cargo.toml文件,将interface添加到members中,如果没有members,则添加members,例如:
+ members = [
+ ".",
+ "interface",
+ ]
+ 3. 修改interface下的build.rs脚本中的rustc-link-search选项,将最后面的路径替换成gstor动态库的目录,例如:
+ println!("cargo:rustc-link-search=native=/opengauss-embedded/3rd/gstor/output/lib");
+ 4. 调用引用,在main.rs中引入interface模块,使用如下语句:
+ use interface;
+ 然后在引入模块类和函数即可:
+ use crate::interface::{Interface, GS_FALSE, GS_TRUE };
+
+调用代码(暂时)
+ 1. 先使用Interface的new函数新建interface对象:
+ let mut conn = Interface::new(data_path, DB_TYPE_GSTOR);
+ 2. 调用打开数据库接口:
+ conn.open_db();
+ 3. 初始化数据库handle:
+ conn.init_handle();
+ 4. 即可调用操作函数,open、create、update等函数,例如:
+ conn.create_table(table_name.clone(), column_list.len() as libc::c_int, column_list.as_ptr(), 0 as libc::c_int, index_list.as_ptr());
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/interface/build.rs b/3rd/gstor/src/interface/rust/ncti-orm/interface/build.rs
new file mode 100644
index 0000000000000000000000000000000000000000..d8b85e47d587e04d29fc25e720355e2b6e829054
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/interface/build.rs
@@ -0,0 +1,11 @@
+#![allow(warnings, unused)]
+use std::process::Command;
+use std::env;
+
+fn main() {
+ println!("pre build ...");
+ let pwd = Command::new("pwd").output().expect("get pwd error");
+ println!("[INFO]: {}", String::from_utf8_lossy(&pwd.stdout));
+ println!("cargo:rerun-if-changed=build.rs");
+ println!("cargo:rustc-link-search=native={}/../../../../../output/lib/", String::from_utf8_lossy(&pwd.stdout).replace("\n", ""));
+}
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/interface/src/data.rs b/3rd/gstor/src/interface/rust/ncti-orm/interface/src/data.rs
new file mode 100644
index 0000000000000000000000000000000000000000..ab897a8bf47772f9bb8ef61fa29ae0c999482544
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/interface/src/data.rs
@@ -0,0 +1,531 @@
+extern crate libc;
+use libc::{c_char, c_int, c_uint};
+
+pub const GS_FALSE:u32 = 0;
+pub const GS_TRUE:u32 = 1;
+
+// #[default] GS_TYPE_VARCHAR;
+#[derive(Debug, Clone, Copy)]
+// #[derive(#[default] GS_TYPE_VARCHAR)]
+#[repr(C)]
+pub enum gs_type_t {
+ GS_TYPE_UNKNOWN = -1,
+ GS_TYPE_BASE = 20000,
+ GS_TYPE_INTEGER = 20000 + 1, /* native 32 bits integer */ // u8 u16 u32
+ GS_TYPE_BIGINT = 20000 + 2, /* native 64 bits integer */
+ GS_TYPE_REAL = 20000 + 3, /* 8-byte native double */
+ GS_TYPE_NUMBER = 20000 + 4, /* number */
+ GS_TYPE_DECIMAL = 20000 + 5, /* decimal, internal used */
+ GS_TYPE_DATE = 20000 + 6, /* datetime */
+ GS_TYPE_TIMESTAMP = 20000 + 7, /* timestamp */
+ GS_TYPE_CHAR = 20000 + 8, /* char(n) */
+ GS_TYPE_VARCHAR = 20000 + 9, /* varchar, varchar2 */
+ GS_TYPE_STRING = 20000 + 10, /* native char * */
+ GS_TYPE_BINARY = 20000 + 11, /* binary */
+ GS_TYPE_VARBINARY = 20000 + 12, /* varbinary */
+ GS_TYPE_CLOB = 20000 + 13, /* clob */
+ GS_TYPE_BLOB = 20000 + 14, /* blob */
+ GS_TYPE_CURSOR = 20000 + 15, /* resultset, for stored procedure */
+ GS_TYPE_COLUMN = 20000 + 16, /* column type, internal used */
+ GS_TYPE_BOOLEAN = 20000 + 17,
+
+ /* timestamp with time zone ,this type is fake, it is abandoned now,
+ * you can treat it as GS_TYPE_TIMESTAMP just for compatibility */
+ GS_TYPE_TIMESTAMP_TZ_FAKE = 20000 + 18,
+ GS_TYPE_TIMESTAMP_LTZ = 20000 + 19, /* timestamp with local time zone */
+ GS_TYPE_INTERVAL = 20000 + 20, /* interval of Postgre style, no use */
+ GS_TYPE_INTERVAL_YM = 20000 + 21, /* interval YEAR TO MONTH */
+ GS_TYPE_INTERVAL_DS = 20000 + 22, /* interval DAY TO SECOND */
+ GS_TYPE_RAW = 20000 + 23, /* raw */
+ GS_TYPE_IMAGE = 20000 + 24, /* image, equals to longblob */
+ GS_TYPE_UINT32 = 20000 + 25, /* unsigned integer */
+ GS_TYPE_UINT64 = 20000 + 26, /* unsigned bigint */
+ GS_TYPE_SMALLINT = 20000 + 27, /* 16-bit integer */
+ GS_TYPE_USMALLINT = 20000 + 28, /* unsigned 16-bit integer */
+ GS_TYPE_TINYINT = 20000 + 29, /* 8-bit integer */
+ GS_TYPE_UTINYINT = 20000 + 30, /* unsigned 8-bit integer */
+ GS_TYPE_FLOAT = 20000 + 31, /* 4-byte float */
+ // !!!add new member must ensure not exceed the limitation of g_type_maps in sql_oper_func.c
+ /* the real tz type , GS_TYPE_TIMESTAMP_TZ_FAKE will be not used , it will be the same as GS_TYPE_TIMESTAMP */
+ GS_TYPE_TIMESTAMP_TZ = 20000 + 32, /* timestamp with time zone */
+ GS_TYPE_ARRAY = 20000 + 33, /* array */
+ /* com */
+ /* caution: SCALAR type must defined above */
+ GS_TYPE_OPERAND_CEIL = 20000 + 40, // ceil of operand type
+
+ /* The datatype can't used in datatype caculation system. only used for
+ * decl in/out param in pl/sql */
+ GS_TYPE_RECORD = 20000 + 41,
+ GS_TYPE_COLLECTION = 20000 + 42,
+ GS_TYPE_OBJECT = 20000 + 43,
+ /* The datatype below the GS_TYPE__DO_NOT_USE can be used as database DATATYPE.
+ * In some extend, GS_TYPE__DO_NOT_USE represents the maximal number
+ * of DATATYPE that Zenith are supported. The newly adding datatype
+ * must before GS_TYPE__DO_NOT_USE, and the type_id must be consecutive
+ */
+ GS_TYPE__DO_NOT_USE = 20000 + 44,
+
+ /* The following datatypes are functional datatypes, which can help
+ * to implement some features when needed. Note that they can not be
+ * used as database DATATYPE */
+ /* to present a datatype node, for example cast(para1, typenode),
+ * the second argument is an expr_node storing the information of
+ * a datatype, such as length, precision, scale, etc.. */
+ GS_TYPE_FUNC_BASE = 20000 + 200,
+ GS_TYPE_TYPMODE = 20000 + 200 + 1,
+
+ /* This datatype only be used in winsort aggr */
+ GS_TYPE_VM_ROWID = 20000 + 200 + 2,
+ GS_TYPE_ITVL_UNIT = 20000 + 200 + 3,
+ GS_TYPE_UNINITIALIZED = 20000 + 200 + 4,
+
+ /* The following datatypes be used for native date or timestamp type value to bind */
+ GS_TYPE_NATIVE_DATE = 20000 + 200 + 5, // native datetime, internal used
+ GS_TYPE_NATIVE_TIMESTAMP = 20000 + 200 + 6, // native timestamp, internal used
+ GS_TYPE_LOGIC_TRUE = 20000 + 200 + 7, // native true, internal used
+
+}
+
+// #[allow(non_camel_case_types)]
+#[repr(C)]
+pub enum table_type_t {
+ TABLE_TYPE_HEAP = 0,
+ TABLE_TYPE_IOT = 1,
+ TABLE_TYPE_TRANS_TEMP = 2,
+ TABLE_TYPE_SESSION_TEMP = 3,
+ TABLE_TYPE_NOLOGGING = 4,
+ TABLE_TYPE_EXTERNAL = 5,
+}
+
+#[repr(C)]
+pub enum dbtype_t {
+ DB_TYPE_GSTOR = 0,
+ DB_TYPE_CEIL = 1,
+}
+
+#[derive(Debug, Default, Clone, Copy)]
+#[repr(C)]
+pub enum assign_type_t {
+ #[default]
+ ASSIGN_TYPE_EQUAL = 0, //等于
+ ASSIGN_TYPE_LESS = 0 + 1, //小于
+ ASSIGN_TYPE_MORE = 0 + 2, //大于
+ ASSIGN_TYPE_LESS_EQUAL = 0 + 3, //小于等于
+ ASSIGN_TYPE_MORE_EQUAL = 0 + 4, //大于等于
+ ASSIGN_TYPE_UNEQUAL = 0 + 5, //不等于
+}
+
+#[derive(Debug, Clone, Copy)]
+#[repr(C)]
+pub struct col_text_t {
+ pub str: *mut c_char,
+ pub len: u32,
+ pub assign: assign_type_t,
+}
+
+#[derive(Clone, Copy)]
+#[repr(C)]
+pub struct exp_column_def_t {
+ pub name: col_text_t, //字段名
+ pub col_type: gs_type_t, //字段类型
+ pub col_slot: u16, //字段槽位
+ pub size: u16, //字段长度
+ pub nullable: u32, //是否可空
+ pub is_primary: u32, //是否主键字段
+ pub is_default: u32, //是否有默认值
+ pub default_val: col_text_t, //默认值
+ pub crud_value: col_text_t, //列值(查询、插入、修改、删除时用到)
+ pub precision: u16, //精度(即小数点后的位数)
+ pub comment: col_text_t, //备注
+}
+
+#[derive(PartialEq, Eq)]
+#[repr(C)]
+pub enum status_t {
+ GS_ERROR = -1,
+ GS_SUCCESS = 0,
+ GS_TIMEDOUT = 1,
+}
+
+#[repr(C)]
+pub struct exp_index_def_t {
+ pub name: col_text_t, //索引名
+ pub cols: *const col_text_t, //索引列列表
+ pub col_count: u32, //索引列列数
+ pub is_unique: u32, //是否唯一索引
+ pub is_primary: u32, //是否主键索引
+}
+
+#[repr(C)]
+pub struct res_row_def_t
+{
+ pub column_count: i32, //行数
+ pub row_column_list: *mut exp_column_def_t, //行包含的列列表
+}
+
+impl assign_type_t{
+
+ pub fn as_u8(&self) -> u8 {
+ match *self {
+ assign_type_t::ASSIGN_TYPE_EQUAL => {
+ return 0;
+ },
+ assign_type_t::ASSIGN_TYPE_LESS => {
+ return 1;
+ },
+ assign_type_t::ASSIGN_TYPE_MORE => {
+ return 2;
+ },
+ assign_type_t::ASSIGN_TYPE_LESS_EQUAL => {
+ return 3;
+ },
+ assign_type_t::ASSIGN_TYPE_MORE_EQUAL => {
+ return 4;
+ },
+ assign_type_t::ASSIGN_TYPE_UNEQUAL => {
+ return 5;
+ },
+ _ => {
+ return 0;
+ },
+ }
+ }
+}
+
+impl From for assign_type_t {
+ #[inline]
+ fn from(v: u8) -> Self {
+ match v {
+ 0 => {
+ return assign_type_t::ASSIGN_TYPE_EQUAL;
+ },
+ 1 => {
+ return assign_type_t::ASSIGN_TYPE_LESS;
+ },
+ 2 => {
+ return assign_type_t::ASSIGN_TYPE_MORE;
+ },
+ 3 => {
+ return assign_type_t::ASSIGN_TYPE_LESS_EQUAL;
+ },
+ 4 => {
+ return assign_type_t::ASSIGN_TYPE_MORE_EQUAL;
+ },
+ 5 => {
+ return assign_type_t::ASSIGN_TYPE_UNEQUAL;
+ },
+ _ => {
+ return assign_type_t::ASSIGN_TYPE_EQUAL;;
+ },
+ }
+ }
+}
+
+impl gs_type_t {
+ pub fn as_string(&self) -> String {
+ match *self {
+ gs_type_t::GS_TYPE_UNKNOWN => { return String::from("UNKNOWN");
+ },
+ gs_type_t::GS_TYPE_BASE => {
+ return String::from("BASE");
+ },
+ gs_type_t::GS_TYPE_INTEGER => {
+ return String::from("INTEGER");
+ },
+ gs_type_t::GS_TYPE_BIGINT => {
+ return String::from("BIGINT");
+ },
+ gs_type_t::GS_TYPE_REAL => {
+ return String::from("REAL");
+ },
+ gs_type_t::GS_TYPE_NUMBER => {
+ return String::from("NUMBER");
+ },
+ gs_type_t::GS_TYPE_DECIMAL => {
+ return String::from("DECIMAL");
+ },
+ gs_type_t::GS_TYPE_DATE => {
+ return String::from("DATE");
+ },
+ gs_type_t::GS_TYPE_TIMESTAMP => {
+ return String::from("TIMESTAMP");
+ },
+ gs_type_t::GS_TYPE_CHAR => {
+ return String::from("CHAR");
+ },
+ gs_type_t::GS_TYPE_VARCHAR => {
+ return String::from("VARCHAR");
+ },
+ gs_type_t::GS_TYPE_STRING => {
+ return String::from("STRING");
+ },
+ gs_type_t::GS_TYPE_BINARY => {
+ return String::from("BINARY");
+ },
+ gs_type_t::GS_TYPE_VARBINARY => {
+ return String::from("VARBINARY");
+ },
+ gs_type_t::GS_TYPE_CLOB => {
+ return String::from("CLOB");
+ },
+ gs_type_t::GS_TYPE_BLOB => {
+ return String::from("BLOB");
+ },
+ gs_type_t::GS_TYPE_CURSOR => {
+ return String::from("CURSOR");
+ },
+ gs_type_t::GS_TYPE_COLUMN => {
+ return String::from("COLUMN");
+ },
+ gs_type_t::GS_TYPE_BOOLEAN => {
+ return String::from("BOOLEAN");
+ },
+ gs_type_t::GS_TYPE_TIMESTAMP_TZ_FAKE => {
+ return String::from("TIMESTAMP_TZ_FAKE");
+ },
+ gs_type_t::GS_TYPE_TIMESTAMP_LTZ => {
+ return String::from("TIMESTAMP_LTZ");
+ },
+ gs_type_t::GS_TYPE_INTERVAL => {
+ return String::from("INTERVAL");
+ },
+ gs_type_t::GS_TYPE_INTERVAL_YM => {
+ return String::from("INTERVAL_YM");
+ },
+ gs_type_t::GS_TYPE_INTERVAL_DS => {
+ return String::from("INTERVAL_DS");
+ },
+ gs_type_t::GS_TYPE_RAW => {
+ return String::from("RAW");
+ },
+ gs_type_t::GS_TYPE_IMAGE => {
+ return String::from("IMAGE");
+ },
+ gs_type_t::GS_TYPE_UINT32 => {
+ return String::from("UINT32");
+ },
+ gs_type_t::GS_TYPE_UINT64 => {
+ return String::from("UINT64");
+ },
+ gs_type_t::GS_TYPE_SMALLINT => {
+ return String::from("SMALLINT");
+ },
+ gs_type_t::GS_TYPE_USMALLINT => {
+ return String::from("USMALLINT");
+ },
+ gs_type_t::GS_TYPE_TINYINT => {
+ return String::from("TINYINT");
+ },
+ gs_type_t::GS_TYPE_UTINYINT => {
+ return String::from("UTINYINT");
+ },
+ gs_type_t::GS_TYPE_FLOAT => {
+ return String::from("FLOAT");
+ },
+ gs_type_t::GS_TYPE_TIMESTAMP_TZ => {
+ return String::from("TIMESTAMP_TZ");
+ },
+ gs_type_t::GS_TYPE_ARRAY => {
+ return String::from("ARRAY");
+ },
+ gs_type_t::GS_TYPE_OPERAND_CEIL => {
+ return String::from("OPERAND_CEIL");
+ },
+ gs_type_t::GS_TYPE_RECORD => {
+ return String::from("RECORD");
+ },
+ gs_type_t::GS_TYPE_COLLECTION => {
+ return String::from("COLLECTION");
+ },
+ gs_type_t::GS_TYPE_OBJECT => {
+ return String::from("OBJECT");
+ },
+ gs_type_t::GS_TYPE__DO_NOT_USE => {
+ return String::from("_DO_NOT_USE");
+ },
+ gs_type_t::GS_TYPE_FUNC_BASE => {
+ return String::from("FUNC_BASE");
+ },
+ gs_type_t::GS_TYPE_TYPMODE => {
+ return String::from("TYPMODE");
+ },
+ gs_type_t::GS_TYPE_VM_ROWID => {
+ return String::from("VM_ROWID");
+ },
+ gs_type_t::GS_TYPE_ITVL_UNIT => {
+ return String::from("ITVL_UNIT");
+ },
+ gs_type_t::GS_TYPE_UNINITIALIZED => {
+ return String::from("UNINITIALIZED");
+ },
+ gs_type_t::GS_TYPE_NATIVE_DATE => {
+ return String::from("NATIVE_DATE");
+ },
+ gs_type_t::GS_TYPE_NATIVE_TIMESTAMP => {
+ return String::from("NATIVE_TIMESTAMP");
+ },
+ gs_type_t::GS_TYPE_LOGIC_TRUE => {
+ return String::from("LOGIC_TRUE");
+ },
+ gs_type_t::GS_TYPE_UNKNOWN => {
+ return String::from("UNKNOWN");
+ },
+ }
+ }
+}
+
+impl From<&String> for gs_type_t{
+ #[inline]
+ fn from(v: &String) -> Self {
+ match &v as &str {
+ "UNKNOWN" => {
+ return gs_type_t::GS_TYPE_UNKNOWN;
+ },
+ "BASE" => {
+ return gs_type_t::GS_TYPE_BASE;
+ },
+ "INTEGER" => {
+ return gs_type_t::GS_TYPE_INTEGER;
+ },
+ "BIGINT" => {
+ return gs_type_t::GS_TYPE_BIGINT;
+ },
+ "REAL" => {
+ return gs_type_t::GS_TYPE_REAL;
+ },
+ "NUMBER" => {
+ return gs_type_t::GS_TYPE_NUMBER;
+ },
+ "DECIMAL" => {
+ return gs_type_t::GS_TYPE_DECIMAL;
+ },
+ "DATE" => {
+ return gs_type_t::GS_TYPE_DATE;
+ },
+ "TIMESTAMP" => {
+ return gs_type_t::GS_TYPE_TIMESTAMP;
+ },
+ "CHAR" => {
+ return gs_type_t::GS_TYPE_CHAR;
+ },
+ "VARCHAR" => {
+ return gs_type_t::GS_TYPE_VARCHAR;
+ },
+ "STRING" => {
+ return gs_type_t::GS_TYPE_STRING;
+ },
+ "BINARY" => {
+ return gs_type_t::GS_TYPE_BINARY;
+ },
+ "VARBINARY" => {
+ return gs_type_t::GS_TYPE_VARBINARY;
+ },
+ "CLOB" => {
+ return gs_type_t::GS_TYPE_CLOB;
+ },
+ "BLOB" => {
+ return gs_type_t::GS_TYPE_BLOB;
+ },
+ "CURSOR" => {
+ return gs_type_t::GS_TYPE_CURSOR;
+ },
+ "COLUMN" => {
+ return gs_type_t::GS_TYPE_COLUMN;
+ },
+ "BOOLEAN" => {
+ return gs_type_t::GS_TYPE_BOOLEAN;
+ },
+ "TIMESTAMP_TZ_FAKE" => {
+ return gs_type_t::GS_TYPE_TIMESTAMP_TZ_FAKE;
+ },
+ "TIMESTAMP_LTZ" => {
+ return gs_type_t::GS_TYPE_TIMESTAMP_LTZ;
+ },
+ "INTERVAL" => {
+ return gs_type_t::GS_TYPE_INTERVAL;
+ },
+ "INTERVAL_YM" => {
+ return gs_type_t::GS_TYPE_INTERVAL_YM;
+ },
+ "INTERVAL_DS" => {
+ return gs_type_t::GS_TYPE_INTERVAL_DS;
+ },
+ "RAW" => {
+ return gs_type_t::GS_TYPE_RAW;
+ },
+ "IMAGE" => {
+ return gs_type_t::GS_TYPE_IMAGE;
+ },
+ "UINT32" => {
+ return gs_type_t::GS_TYPE_UINT32;
+ },
+ "UINT64" => {
+ return gs_type_t::GS_TYPE_UINT64;
+ },
+ "SMALLINT" => {
+ return gs_type_t::GS_TYPE_SMALLINT;
+ },
+ "USMALLINT" => {
+ return gs_type_t::GS_TYPE_USMALLINT;
+ },
+ "TINYINT" => {
+ return gs_type_t::GS_TYPE_TINYINT;
+ },
+ "UTINYINT" => {
+ return gs_type_t::GS_TYPE_UTINYINT;
+ },
+ "FLOAT" => {
+ return gs_type_t::GS_TYPE_FLOAT;
+ },
+ "TIMESTAMP_TZ" => {
+ return gs_type_t::GS_TYPE_TIMESTAMP_TZ;
+ },
+ "ARRAY" => {
+ return gs_type_t::GS_TYPE_ARRAY;
+ },
+ "OPERAND_CEIL" => {
+ return gs_type_t::GS_TYPE_OPERAND_CEIL;
+ },
+ "RECORD" => {
+ return gs_type_t::GS_TYPE_RECORD;
+ },
+ "COLLECTION" => {
+ return gs_type_t::GS_TYPE_COLLECTION;
+ },
+ "OBJECT" => {
+ return gs_type_t::GS_TYPE_OBJECT;
+ },
+ "_DO_NOT_USE" => {
+ return gs_type_t::GS_TYPE__DO_NOT_USE;
+ },
+ "FUNC_BASE" => {
+ return gs_type_t::GS_TYPE_FUNC_BASE;
+ },
+ "TYPMODE" => {
+ return gs_type_t::GS_TYPE_TYPMODE;
+ },
+ "VM_ROWID" => {
+ return gs_type_t::GS_TYPE_VM_ROWID;
+ },
+ "ITVL_UNIT" => {
+ return gs_type_t::GS_TYPE_ITVL_UNIT;
+ },
+ "UNINITIALIZED" => {
+ return gs_type_t::GS_TYPE_UNINITIALIZED;
+ },
+ "NATIVE_DATE" => {
+ return gs_type_t::GS_TYPE_NATIVE_DATE;
+ },
+ "NATIVE_TIMESTAMP" => {
+ return gs_type_t::GS_TYPE_NATIVE_TIMESTAMP;
+ },
+ "LOGIC_TRUE" => {
+ return gs_type_t::GS_TYPE_LOGIC_TRUE;
+ },
+ _ => {
+ return gs_type_t::GS_TYPE_UNKNOWN;
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/interface/src/func.rs b/3rd/gstor/src/interface/rust/ncti-orm/interface/src/func.rs
new file mode 100644
index 0000000000000000000000000000000000000000..3981e7c757be4b5bf2689270bd243a6621b4b2d8
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/interface/src/func.rs
@@ -0,0 +1,299 @@
+// use crate::executor::Executor;
+#![allow(warnings, unused)]
+#[allow(non_camel_case_types)]
+
+extern crate libc;
+use std::fmt::{Debug, Display};
+use std::ffi::CString;
+use std::ffi::CStr;
+use std::str::FromStr;
+use libc::{c_char, c_int, c_uint};
+use std::slice;
+use serde_json::{Value, json};
+use codegen::utils::model::{StColumnDef4C, StIndexDef, Restriction};
+
+use crate::{Interface, data::exp_column_def_t, data::exp_index_def_t, data::GS_FALSE, data::GS_TRUE, data::dbtype_t, data::gs_type_t, data::assign_type_t, data::col_text_t, data::status_t, data::res_row_def_t};
+
+impl Interface {
+ pub fn open_db(&mut self) -> i32 {
+ self.open_db_and_init()
+ }
+
+ pub fn create_table_with_index(&mut self, table_name: &String, columndefs: & Vec, indexdefs: & Vec) -> i32 {
+
+ let mut column_list: Vec = Vec::new();
+ Interface::col_data_convert(&columndefs, &mut column_list);
+
+ let mut index_list: Vec = Vec::new();
+ Interface::index_data_convert(&indexdefs, &mut index_list);
+
+ self.create_table(table_name, column_list.len() as libc::c_int, column_list.as_ptr(), index_list.len() as libc::c_int, index_list.as_ptr())
+ }
+
+ pub fn create_table_without_index(&mut self, table_name: &String, columndefs: & Vec) -> i32 {
+
+ let mut column_list: Vec = Vec::new();
+
+ Interface::col_data_convert(&columndefs, &mut column_list);
+
+ self.create_table(table_name, column_list.len() as libc::c_int, column_list.as_ptr(), 0, std::ptr::null())
+
+ }
+
+ pub fn open_table(&mut self, table_name: &String) -> i32 {
+ self.open_table_with_name(table_name)
+ }
+
+ pub fn create_table_index(&mut self, table_name: &String, indexdef: & StIndexDef) -> i32 {
+
+ let ret = self.open_table(table_name);
+ if status_t::GS_SUCCESS as libc::c_int != ret {
+ // println!("db open table fail! table name is {}", table_name);
+ return ret;
+ }
+
+ let mut index_cols: Vec = Vec::new();
+
+ for cols_string in indexdef.cols.iter() {
+ index_cols.push(
+ col_text_t{
+ str: CString::new(cols_string.clone()).unwrap().into_raw(),
+ len: cols_string.len() as u32,
+ assign: assign_type_t::ASSIGN_TYPE_EQUAL,
+ }
+ )
+ }
+
+ let mut index_def = exp_index_def_t{
+ name: col_text_t{
+ str: CString::new(indexdef.name.clone()).unwrap().into_raw(),
+ len: indexdef.name.len() as u32,
+ assign: assign_type_t::ASSIGN_TYPE_EQUAL,
+ },
+ cols: index_cols.as_ptr(),
+ col_count:index_cols.len() as libc::c_uint,
+ is_unique: indexdef.is_unique as u32,
+ is_primary: indexdef.is_primary as u32,
+ };
+
+ self.create_index(table_name, &index_def)
+
+ }
+
+ pub fn intert_table_rows(&mut self, table_name: &String, columndefs: & Vec) -> i32 {
+
+ let ret = self.open_table(table_name);
+ if status_t::GS_SUCCESS as libc::c_int != ret {
+ // println!("db open table fail! table name is {}", table_name);
+ return ret;
+ }
+
+ let mut column_list: Vec = Vec::new();
+
+ Interface::col_data_convert(&columndefs, &mut column_list);
+
+ self.insert_row(table_name, column_list.len() as libc::c_int, column_list.as_ptr())
+
+ }
+
+ pub fn update_table_rows(&mut self, table_name: &String, upd_column_defs: & Vec, cond_column_defs: & Vec) -> i32 {
+
+ let ret = self.open_table(table_name);
+ if status_t::GS_SUCCESS as libc::c_int != ret {
+ // println!("db open table fail! table name is {}", table_name);
+ return ret;
+ }
+ let mut upd_column_list: Vec = Vec::new();
+ Interface::col_data_convert(&upd_column_defs, &mut upd_column_list);
+
+ let mut cond_column_list: Vec = Vec::new();
+ Interface::col_data_convert(&cond_column_defs, &mut cond_column_list);
+
+
+ self.update_row(table_name, upd_column_list.len() as libc::c_int, upd_column_list.as_ptr(), cond_column_list.len() as libc::c_int, cond_column_list.as_ptr())
+
+ }
+
+ pub fn table_delete_row(&mut self, table_name: &String, del_count: *mut libc::c_int, cond_column_defs: &Vec) -> i32 {
+ let ret = self.open_table(table_name);
+ if status_t::GS_SUCCESS as libc::c_int != ret {
+ // println!("db open table fail! table name is {}", table_name);
+ return ret;
+ }
+ let mut cond_column_list: Vec = Vec::new();
+
+ Interface::col_data_convert(&cond_column_defs, &mut cond_column_list);
+
+ self.delete_row(table_name, del_count, cond_column_list.len() as libc::c_int, cond_column_list.as_ptr())
+ }
+
+ pub fn table_fetch_data(&mut self, table_name: &String, cond_column_defs: & Vec, sel_column_defs: &Vec, res_row_defs: &mut Vec) -> i32 {
+
+ let ret = self.open_table(table_name);
+ if status_t::GS_SUCCESS as libc::c_int != ret {
+ // println!("db open table fail! table name is {}", table_name);
+ return ret;
+ }
+
+ let mut cond_column_list: Vec = Vec::new();
+ Interface::col_data_convert(&cond_column_defs, &mut cond_column_list);
+ let mut eof = GS_TRUE;
+
+ let mut ret = self.open_cursor(table_name, cond_column_list.len() as libc::c_int, cond_column_list.as_ptr(), &mut eof, 0);
+ if status_t::GS_SUCCESS as libc::c_int != ret {
+ println!("db open cursor fail! table name is {}", table_name);
+ return ret
+ }
+
+ if(eof == GS_TRUE) {
+ println!("--eof!!");
+ // return ret;
+ }
+ let mut sel_column_list: Vec = Vec::new();
+
+ Interface::col_data_convert(&sel_column_defs, &mut sel_column_list);
+
+ let mut row_count = 0;
+
+ while (self.cursor_next(&mut eof) == status_t::GS_SUCCESS as i32) {
+ if(eof == GS_TRUE) {
+ println!("--db_cursor_next eof!!");
+ break;
+ }
+ let mut res_column_list = Vec::::with_capacity(sel_column_list.len());
+ let mut res_row_list = res_row_def_t {
+ column_count: sel_column_list.len() as i32,
+ row_column_list: res_column_list.as_mut_ptr(),
+ };
+
+ let ret = self.cursor_fetch(sel_column_list.len() as libc::c_int, sel_column_list.as_ptr(), &mut row_count, &mut res_row_list);
+
+ if status_t::GS_SUCCESS as libc::c_int != ret {
+ println!("db cursor fetch fail!");
+ return ret
+ }
+
+ let mut vec = unsafe {
+ std::slice::from_raw_parts((res_row_list.row_column_list) as *const exp_column_def_t, res_row_list.column_count as usize).to_vec()
+ };
+ let mut i = 0;
+ let mut jsonValue:serde_json::value::Value = json!({});
+ for row_info in &vec {
+ let name= sel_column_defs[i].name.clone();
+ let val= unsafe {String::from_utf8_lossy(CStr::from_ptr((row_info.crud_value.str)).to_bytes()).to_string()};
+ match row_info.col_type.as_string().as_str(){
+ "VARCHAR" => {
+ jsonValue.as_object_mut().unwrap().insert(name.to_string(), serde_json::value::Value::String(val));
+ },
+ "BIGINT" => {
+ let n=val.parse::().unwrap();
+ jsonValue.as_object_mut().unwrap().insert(name.to_string(), serde_json::value::Value::Number(n.into()));
+ },
+ _ => {
+ jsonValue.as_object_mut().unwrap().insert(name.to_string(), serde_json::value::Value::String(val));
+ },
+ }
+ // res_row_defs.push(
+ // StColumnDef4C {
+ // name: unsafe {
+ // sel_column_defs[i].name.clone()
+ // // String::from_utf8_lossy(CStr::from_ptr((row_info.name.str)).to_bytes()).to_string()
+ // },
+ // types: row_info.col_type.as_string(), //String::from("GS_TYPE_VARCHAR"),
+ // col_slot: row_info.col_slot,
+ // size: row_info.size,
+ // nullable: row_info.nullable as u8,
+ // is_primary: row_info.is_primary as u8,
+ // is_default: row_info.is_default as u8,
+ // default_val: unsafe {
+ // String::from("")
+ // // CString::from_raw((row_list.default_val.str)).into_string().unwrap()
+ // },
+ // crud_value: unsafe {
+ // // String::from("")
+ // String::from_utf8_lossy(CStr::from_ptr((row_info.crud_value.str)).to_bytes()).to_string()
+ // },
+ // precision: row_info.precision,
+ // comment: unsafe {
+ // String::from("")
+ // // CString::from_raw((row_list.comment.str)).into_string().unwrap()
+ // },
+ // assign_type_t: row_info.crud_value.assign as u8,
+ // }
+ // );
+ i = i + 1;
+ }
+ res_row_defs.push(jsonValue);
+
+ }
+ ret
+ }
+
+ fn col_data_convert(st_column_list: &Vec, exp_column_list: &mut Vec) {
+
+ for column in st_column_list {
+ exp_column_list.push(
+ exp_column_def_t{
+ name: col_text_t {
+ str: CString::new(column.name.clone()).unwrap().into_raw(),
+ len: column.name.len() as u32,
+ assign: assign_type_t::from(column.assign_type_t), //assign_type_t::ASSIGN_TYPE_EQUAL,
+ },
+ col_type: gs_type_t::from(&column.types), //get_column_type(&column.types), //gs_type_t::GS_TYPE_VARCHAR,
+ col_slot: column.col_slot,
+ size: column.size,
+ nullable: column.nullable as u32,
+ is_primary: column.is_primary as u32,
+ is_default: column.is_default as u32,
+ default_val: col_text_t {
+ str: CString::new(column.default_val.clone()).unwrap().into_raw(),
+ len: column.default_val.len() as u32,
+ assign: assign_type_t::from(column.assign_type_t), //assign_type_t::ASSIGN_TYPE_EQUAL,
+ },
+ crud_value: col_text_t {
+ str: CString::new(column.crud_value.clone()).unwrap().into_raw(),
+ len: column.crud_value.len() as u32,
+ assign: assign_type_t::from(column.assign_type_t), //assign_type_t::ASSIGN_TYPE_EQUAL,
+ },
+ precision: column.precision ,
+ comment: col_text_t {
+ str: CString::new(column.comment.clone()).unwrap().into_raw(),
+ len: column.comment.len() as u32,
+ assign: assign_type_t::from(column.assign_type_t), //assign_type_t::ASSIGN_TYPE_EQUAL,
+ },
+ }
+ );
+ }
+ }
+
+ fn index_data_convert(st_index_list: &Vec, exp_index_list: &mut Vec) {
+
+ for index in st_index_list {
+ let mut index_cols: Vec = Vec::new();
+ for cols_string in index.cols.iter() {
+ index_cols.push(
+ col_text_t{
+ str: CString::new(cols_string.clone()).unwrap().into_raw(),
+ len: cols_string.len() as u32,
+ assign: assign_type_t::ASSIGN_TYPE_EQUAL,
+ }
+ )
+ }
+ exp_index_list.push(
+ exp_index_def_t {
+ name: col_text_t{
+ str: CString::new(index.name.clone()).unwrap().into_raw(),
+ len: index.name.len() as u32,
+ assign: assign_type_t::ASSIGN_TYPE_EQUAL,
+ },
+ cols: index_cols.as_ptr(),
+ col_count:index_cols.len() as libc::c_uint,
+ is_unique: index.is_unique as u32,
+ is_primary: index.is_primary as u32,
+ }
+
+ )
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/interface/src/lib.rs b/3rd/gstor/src/interface/rust/ncti-orm/interface/src/lib.rs
new file mode 100644
index 0000000000000000000000000000000000000000..212dc2e4cce14d1ae449ed206d94dd0cd662e81a
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/interface/src/lib.rs
@@ -0,0 +1,226 @@
+// use crate::executor::Executor;
+#![allow(warnings, unused)]
+#[allow(non_camel_case_types)]
+
+extern crate libc;
+use std::fmt::{Debug, Display};
+use std::ffi::CString;
+use std::ffi::CStr;
+use libc::{c_char, c_int, c_uint};
+
+use codegen;
+
+pub mod data;
+pub mod func;
+
+// pub mod connection;
+
+use crate::{data::exp_column_def_t, data::exp_index_def_t, data::GS_FALSE, data::GS_TRUE, data::dbtype_t, data::gs_type_t, data::assign_type_t, data::col_text_t, data::status_t, data::res_row_def_t};
+
+#[link(name = "gstor")]
+#[link(name = "gstor_dev_c")]
+#[link(name = "storage")]
+
+extern "C" {
+ fn db_alloc(handle: *const u64) -> libc::c_int;
+
+ fn gstor_shutdown();
+
+ fn gstor_startup_db(dbtype: libc::c_int, data_path: *const c_char) -> status_t;
+
+ fn db_open_table(handle: u64, table_name: *const c_char) -> libc::c_int;
+
+ fn gstor_create_user_table(handle: u64, table_name: *const c_char, column_count: libc::c_int, column_list: *const exp_column_def_t, index_count: libc::c_int, index_list: *const exp_index_def_t) -> libc::c_int;
+ fn gstor_create_index(handle: u64, table_name: *const c_char, index_def: *const exp_index_def_t) -> libc::c_int;
+
+ fn gstor_insert_row(handle: u64, table_name: *const c_char, column_count: libc::c_int, column_list: *const exp_column_def_t) -> status_t;
+
+ fn gstor_update_row(handle: u64, table_name: *const c_char, upd_column_count: libc::c_int, upd_column_list: *const exp_column_def_t, cond_column_count: libc::c_int, cond_column_list: *const exp_column_def_t) -> libc::c_int;
+
+ fn gstor_delete_row(handle: u64, table_name: *const c_char, del_count: *mut libc::c_int, cond_column_count: libc::c_int, cond_column_list: *const exp_column_def_t) -> libc::c_int;
+
+ fn db_open_cursor(handle: u64, table_name: *const c_char, cond_column_count: libc::c_int, cond_column_list: *const exp_column_def_t, eof: *mut libc::c_uint, idx_slot: libc::c_int) -> status_t;
+
+ fn db_cursor_next(handle: u64, eof: *mut libc::c_uint) -> status_t;
+
+ fn db_cursor_fetch(handle: u64, sel_column_count: libc::c_int, sel_column_list: *const exp_column_def_t, res_row_count: *mut libc::c_int, res_row_list: *mut res_row_def_t) -> status_t;
+
+ // EXPORT_API status_t db_commit(void *handle);
+ fn db_commit(handle: u64) -> status_t;
+
+ // EXPORT_API status_t db_rollback(void *handle);
+ fn db_rollback(handle: u64) -> status_t;
+
+}
+
+pub struct Interface {
+ db_type: libc::c_int,
+ path: String,
+ handle: Box::,
+}
+
+impl Interface {
+ pub fn new(data_path: String, db_type_id: libc::c_int) -> Self {
+ return Self {
+ db_type: db_type_id,
+ path: data_path,
+ handle: Box::::new(0),
+ }
+ }
+
+ fn open_db_and_init(&mut self) -> i32 {
+ let ret = unsafe {
+ gstor_startup_db(self.db_type as libc::c_int, CString::new(self.path.clone()).unwrap().into_raw())
+ };
+ if status_t::GS_SUCCESS == ret {
+ println!("open db success! db path is {}",self.path);
+ self.init_handle();
+ } else {
+ println!("open db error! db path is {}",self.path);
+ }
+ ret as i32
+ }
+
+ fn init_handle(&mut self) {
+ let ret = unsafe {
+ db_alloc(self.handle.as_ref())
+ };
+ if status_t::GS_SUCCESS as libc::c_int == ret {
+ println!("alloc db handle success!");
+ } else {
+ println!("alloc db handle fail!");
+ }
+
+ }
+
+ fn open_table_with_name(&mut self, table_name: &String) -> i32 {
+ let ret = unsafe {
+ db_open_table(*(self.handle), CString::new(table_name.clone()).unwrap().into_raw())
+ };
+ if status_t::GS_SUCCESS as libc::c_int == ret {
+ println!("db open table success! table name is {}", table_name);
+ } else {
+ println!("db open table fail! table name is {}", table_name);
+ }
+ ret
+ }
+
+ fn create_table(&mut self, table_name: &String, column_count: libc::c_int, column_list: *const exp_column_def_t, index_count: libc::c_int, index_list: *const exp_index_def_t) -> i32{
+ let ret = unsafe {
+ gstor_create_user_table(*(self.handle), CString::new(table_name.clone()).unwrap().into_raw(), column_count, column_list, index_count, index_list)
+ };
+ if status_t::GS_SUCCESS as libc::c_int == ret {
+ println!("db create table success! table name is {}", table_name);
+ } else {
+ println!("db create table fail! table name is {}", table_name);
+ }
+ ret
+ }
+ fn create_index(&mut self, table_name: &String, index_def: *const exp_index_def_t) -> i32 {
+
+ let ret = unsafe {
+ gstor_create_index(*(self.handle), CString::new(table_name.clone()).unwrap().into_raw(), index_def)
+ };
+ if status_t::GS_SUCCESS as libc::c_int == ret {
+
+ println!("db create table index success! table name is {}, index is {:?}", table_name, index_def);
+ } else {
+ println!("db create table index fail! table name is {}, index is {:?} ", table_name, index_def);
+ }
+ ret
+ }
+
+ fn insert_row(&mut self, table_name: &String, column_count: libc::c_int, column_list: *const exp_column_def_t) -> i32 {
+ let ret = unsafe {
+ gstor_insert_row(*(self.handle), CString::new(table_name.clone()).unwrap().into_raw(), column_count, column_list)
+ };
+ if status_t::GS_SUCCESS as status_t == ret {
+ println!("db insert row success! table name is {}", table_name);
+ } else {
+ println!("db insert row fail! table name is {}", table_name);
+ }
+ ret as i32
+ }
+
+ fn update_row(&mut self, table_name: &String, upd_column_count: libc::c_int, upd_column_list: *const exp_column_def_t, cond_column_count: libc::c_int, cond_column_list: *const exp_column_def_t) -> i32 {
+ let ret = unsafe {
+ gstor_update_row(*(self.handle), CString::new(table_name.clone()).unwrap().into_raw(), upd_column_count, upd_column_list, cond_column_count, cond_column_list)
+ };
+ if status_t::GS_SUCCESS as libc::c_int == ret {
+ println!("db update row success! table name is {}", table_name);
+ } else {
+ println!("db update row fail! table name is {}", table_name);
+ }
+ ret
+ }
+ fn delete_row(&mut self, table_name: &String, del_count: *mut libc::c_int, cond_column_count: libc::c_int, cond_column_list: *const exp_column_def_t) -> i32 {
+ let ret = unsafe {
+ gstor_delete_row(*self.handle, CString::new(table_name.clone()).unwrap().into_raw(), del_count, cond_column_count, cond_column_list)
+ };
+ if status_t::GS_SUCCESS as libc::c_int == ret {
+ println!("db delete row success! table name is {}", table_name);
+ } else {
+ println!("db delete row fail! table name is {}", table_name);
+ }
+ ret
+ }
+
+ fn open_cursor(&mut self, table_name: &String, cond_column_count: libc::c_int, cond_column_list: *const exp_column_def_t, eof: *mut libc::c_uint, idx_slot: libc::c_int) -> i32 {
+ let ret = unsafe {
+ db_open_cursor(*self.handle, CString::new(table_name.clone()).unwrap().into_raw(), cond_column_count, cond_column_list, eof, idx_slot)
+ };
+ if status_t::GS_SUCCESS == ret {
+ println!("db open cursor success! table name is {}", table_name);
+ } else {
+ println!("db open cursor fail! table name is {}", table_name);
+ }
+ ret as i32
+ }
+
+ fn cursor_next(&mut self, eof: *mut libc::c_uint) -> i32 {
+ let ret = unsafe {
+ db_cursor_next(*self.handle, eof)
+ };
+ if status_t::GS_SUCCESS == ret {
+ println!("db cursor next success!");
+ } else {
+ println!("db cursor next fail! ");
+ }
+ ret as i32
+ }
+
+ fn cursor_fetch(&mut self, sel_column_count: libc::c_int, sel_column_list: *const exp_column_def_t, res_row_count: *mut libc::c_int, res_row_list: *mut res_row_def_t ) -> i32 {
+ let ret = unsafe {
+ db_cursor_fetch(*self.handle, sel_column_count, sel_column_list, res_row_count, res_row_list)
+ };
+ if status_t::GS_SUCCESS == ret {
+ println!("db cursor fetch success!");
+ } else {
+ println!("db cursor fetch fail!");
+ }
+ ret as i32
+ }
+
+ pub fn db_commit(&mut self) {
+ let ret = unsafe {
+ db_commit(*(self.handle))
+ };
+ if status_t::GS_SUCCESS == ret {
+ println!("db commit success!");
+ } else {
+ println!("db commit fail!");
+ }
+ }
+
+ pub fn db_rollback(&mut self) {
+ let ret = unsafe {
+ db_rollback(*(self.handle))
+ };
+ if status_t::GS_SUCCESS == ret {
+ println!("db rollback success!");
+ } else {
+ println!("db rollback fail!");
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/macro_driver/Cargo.toml b/3rd/gstor/src/interface/rust/ncti-orm/macro_driver/Cargo.toml
new file mode 100644
index 0000000000000000000000000000000000000000..e569e27b36a758ccd0bc548a5dc91dfb0b10f046
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/macro_driver/Cargo.toml
@@ -0,0 +1,18 @@
+[package]
+name = "macro_driver"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+[lib]
+proc-macro = true
+[dependencies]
+proc-macro2 = "1.0"
+codegen = { version = "0.1.0", path = "../codegen"}
+interface = { version = "0.1.0", path = "../interface"}
+quote = "1.0"
+regex = "1"
+serde_json = "1.0"
+serde = { version = "1.0", features = ["derive"] }
+syn = { version = "1.0", features = ["full"] }
+
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/macro_driver/src/lib.rs b/3rd/gstor/src/interface/rust/ncti-orm/macro_driver/src/lib.rs
new file mode 100644
index 0000000000000000000000000000000000000000..d9505dc0a77909fe7869a1c8b8501809c60722a6
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/macro_driver/src/lib.rs
@@ -0,0 +1,362 @@
+extern crate proc_macro;
+extern crate regex;
+
+use crate::proc_macro::TokenStream;
+use quote::quote;
+use syn;
+
+use quote::ToTokens;
+
+/**
+column 字段定义,json格式 {"name":"id","types":"uint16","size":1,"nullable":0,"is_primary":0,"is_defualt":0,"crud_value":"","precision":0,"comment":""}
+column 字段名字是列名
+text_t type; //列字段类型
+uint16 size; //列宽
+bool32 nullable; //是否可空 1是0否
+bool32 is_primary //是否主键字段 1是0否
+bool32 is_defualt //是否有默认值 1是0否
+text_t default_val //默认值
+text_t crud_value //列值(查询、插入、修改时用到)
+uint16 precision //精度(即小数点后的位数)
+text_t comment //备注
+
+index 字段定义,json格式 {"name":"id","cols":["id"],"col_count":1,"is_unique":0,"is_primary":0}
+text_t name; //索引名
+text_t *cols; //索引列(可多个)
+uint32 col_count; //索引包含列的数量
+bool32 is_unique; //是否唯一 1是0否
+bool32 is_primary //是主键索引 1是0否
+ */
+#[proc_macro_derive(Create, attributes(column, index))]
+pub fn create_macro(input: TokenStream) -> TokenStream {
+ let ast = syn::parse(input).unwrap();
+ create_macro_impl(&ast)
+}
+
+fn create_macro_impl(ast: &syn::DeriveInput) -> TokenStream {
+ //结构体名
+ let name = &ast.ident;
+ let mut column_count_quote = quote! {};
+ let mut create_table_column_quote = quote! {};
+ let mut create_table_index_quote = quote! {};
+ let table_name_quote = quote! {
+ let table_name = codegen::utils::string_util::to_snake_name(stringify!(#name));
+ };
+ let mut column_count: u16 = 0;
+ match &ast.data {
+ syn::Data::Struct(ds) => match &ds.fields {
+ syn::Fields::Named(ff) => {
+ let mut num: u16 = 0;
+ ff.named.iter().for_each(|f| {
+ // let ident = &f.ident;
+ // let mut attr = String::from("");
+ // match ident {
+ // Some(i) => attr = i.to_string(),
+ // _ => {}
+ // };
+ // println!("attr: {}", attr);
+ column_count = column_count + 1;
+ column_count_quote = quote! {let mut column_count:u16 = #column_count;};
+ // let ty = &f.ty;
+ let attrs = &f.attrs;
+ // let mut ft = String::from("");
+ // match ty {
+ // syn::Type::Path(p) => {
+ // ft = format!("{}", p.path.segments[0].ident);
+ // }
+ // _ => {}
+ // }
+ // println!("type:{}", ft);
+ attrs.iter().for_each(|at| {
+ let mut prop = String::from("");
+
+ let mut param = String::from("");
+ if !at.path.segments.is_empty() && at.path.segments.len() > 0 {
+ prop = format!("{}", at.path.segments[0].ident);
+ }
+ // println!("prop: {}", prop);
+ if !at.tokens.is_empty() {
+ param = format!("{}", at.tokens);
+ }
+ if prop == "column".to_string() && param.len() > 0 {
+ create_table_column_quote = quote! {
+ #create_table_column_quote
+ let mut column_string= String::from(#param).replace("(r", "").replace("#\"", "").replace("\"#", "").replace(")", "");
+ let stColumnDef: codegen::utils::model::StColumnDef=serde_json::from_str(&column_string).unwrap();
+ let mut s4c=codegen::utils::model::StColumnDef4C {
+ name: stColumnDef.name,
+ types:stColumnDef.types,
+ col_slot: stColumnDef.col_slot,
+ size: stColumnDef.size,
+ nullable: stColumnDef.nullable,
+ is_primary: stColumnDef.is_primary,
+ is_default: stColumnDef.is_default,
+ default_val: stColumnDef.default_val,
+ crud_value: stColumnDef.crud_value,
+ precision: stColumnDef.precision,
+ comment: stColumnDef.comment,
+ assign_type_t: 0
+ };
+ columns.push(s4c);
+
+ };
+ } else if prop == "index".to_string() && param.len() > 0 {
+ create_table_index_quote = quote! {
+ #create_table_index_quote
+ let mut index_string= String::from(#param).replace("(r", "").replace("#\"", "").replace("\"#", "").replace(")", "");
+ let idnex_model: codegen::utils::model::StIndexDef = serde_json::from_str(&index_string).unwrap();
+ indexs.push( idnex_model);
+ };
+ };
+ });
+ num = num + 1;
+ });
+ }
+ _ => {}
+ },
+ _ => {}
+ }
+
+ TokenStream::from(quote! {
+ impl Create
+ for #name {
+ //创建表
+ fn create_table( &self, conn: &mut interface::Interface) -> std::result::Result {
+ use std::collections::HashMap;
+ let mut columns : Vec = Vec::new();
+ let mut indexs : Vec = Vec::new();
+ //表名
+ #table_name_quote
+ //字段
+ #create_table_column_quote
+ //索引
+ #create_table_index_quote
+ let mut primary_map:HashMap = HashMap::new();
+ for c in &columns.clone() {
+ if(c.is_primary==1){
+ primary_map.insert(c.name.clone(),c.clone());
+ };
+ }
+ //创建表至少有一个索引
+ if(indexs.len()<1){
+ panic !("Configure at least one index indexs.len:{}",indexs.len());
+ }
+ //创建表至少有一个主键索引 column.is_primary=1,index.is_unique,is_primary=1
+ let mut b=false;
+ for index in &indexs {
+ if(index.is_primary==1 && index.is_unique==1 && primary_map.contains_key(&index.name)){
+ b=true;
+ }
+ }
+ // if(!b){
+ // panic !("At least one primary key index is configured indexs.len:{}",indexs.len());
+ // }
+ //创建表
+ let ret= conn.create_table_without_index(&table_name, &columns);
+ println!("create_table ret*****: {}", ret.to_string());
+ //创建索引
+ let mut rets:i32=0;
+ for index in &indexs {
+ let ret= conn.create_table_index(&table_name,&index.clone());
+ if(ret !=0){
+ rets=-1;
+ }
+ println!("create_index ret**********{}: {}",index.name, ret.to_string());
+ }
+ Ok(ret)
+ }
+
+ fn get_table_colums_info(&self) -> Vec {
+ let mut columns : Vec = Vec::new();
+ //字段
+ #create_table_column_quote
+ columns
+ }
+
+ fn get_table_indexs(&self) -> Vec {
+ let mut indexs : Vec = Vec::new();
+ //索引
+ #create_table_index_quote
+ indexs
+ }
+
+ //创建索引
+ fn create_index( &self, conn: &mut interface::Interface) ->std::result::Result {
+ let mut indexs : Vec = Vec::new();
+ //表名
+ #table_name_quote
+ //索引
+ #create_table_index_quote
+ let mut rets:i32=0;
+ for index in &indexs {
+ let ret= conn.create_table_index(&table_name,&index.clone());
+ if(ret !=0){
+ rets=-1;
+ }
+ println!("create_index ret**********{}: {}",index.name, ret.to_string());
+ }
+ Ok(rets)
+ }
+
+ }
+ })
+}
+
+#[proc_macro_attribute]
+pub fn insert_macro_attribute(_args: TokenStream, _func: TokenStream) -> TokenStream {
+ // 通过syn来解析输入的TokenStream
+ let input_fn = syn::parse_macro_input!(_func as syn::ItemFn);
+ // 获取该token对应的类型:ident
+ // let name = input_fn.sig.ident.clone();
+ let func_args_stream = input_fn.sig.inputs.to_token_stream();
+ let st_column_def_quote = quote! {
+ let mut stColumnDef = codegen::utils::model::StColumnDef::default ();
+ stColumnDef.name = km.as_str().unwrap().to_string();
+ if vm.is_str(){
+ stColumnDef.crud_value = vm.as_str().unwrap().to_string();
+ }else{
+ stColumnDef.crud_value = vm.to_string().to_string();
+ }
+ columns.push(stColumnDef);
+ };
+ let insert_quote = quote! {
+ pub fn insert_macro(
+ #func_args_stream
+ ) -> std::result::Result < i32, codegen::utils::error::Error > {
+ use std::collections::HashMap;
+ use serde::{Serialize, Deserialize};
+ let mut table_vec = Vec::new();
+ table_vec.push(table);
+ let mut arr = rbs::to_value(table_vec).unwrap_or_default();
+ let mut columns: Vec < codegen::utils::model::StColumnDef > = Vec::new();
+ //获取属性名,属性值
+ for (k, v) in arr{
+ for (km, vm) in & v { //km字段名,vm字段值
+ #st_column_def_quote
+ }
+ }
+ // 重新组装insert字段集合
+ // insert字段集合
+ let mut insertVec : Vec = Vec::new();
+ for column in columns {
+ let mut column_option = colums_map.get(&column.name.clone());
+ match column_option {
+ Some(col_opt) =>{
+ let mut col = ( * col_opt).clone();
+ col.name = column.name.clone();
+ col.crud_value = column.crud_value.clone();
+ insertVec.push(col);
+ },
+ None =>panic !("in columns no found field {}",&column.name.clone().to_string())
+ } ;
+ }
+ let ret= conn.intert_table_rows(&table_name,&insertVec);
+ if(commit){
+ if(ret==0){
+ conn.db_commit();
+ }else{
+ conn.db_rollback();
+ }
+ }
+ println!("intert_table_rows ret**********: {}", ret.to_string());
+ Ok(ret)
+ };
+ };
+ return insert_quote.into();
+}
+
+
+#[proc_macro_attribute]
+pub fn update_macro_attribute(_args: TokenStream, _func: TokenStream) -> TokenStream {
+ // 通过syn来解析输入的TokenStream
+ let input_fn = syn::parse_macro_input!(_func as syn::ItemFn);
+ // 获取该token对应的类型:ident
+ // let name = input_fn.sig.ident.clone();
+ let func_args_stream = input_fn.sig.inputs.to_token_stream();
+ let st_column_def_quote = quote! {
+ let mut stColumnDef = codegen::utils::model::StColumnDef::default ();
+ if vm.is_str(){
+ stColumnDef.name = km.as_str().unwrap().to_string();
+ stColumnDef.crud_value = vm.as_str().unwrap().to_string();
+ columns.push(stColumnDef);
+ }else if !vm.is_null(){//非None,非字符串
+ stColumnDef.name = km.as_str().unwrap().to_string();
+ stColumnDef.crud_value = vm.to_string().to_string();
+ columns.push(stColumnDef);
+ }
+
+ };
+ let update_quote = quote! {
+ pub fn update_macro(
+ #func_args_stream
+ ) -> std::result::Result < i32, codegen::utils::error::Error > {
+ let mut table_vec = Vec::new();
+ table_vec.push(table);
+ let mut arr = rbs::to_value(table_vec).unwrap_or_default();
+ use std::collections::HashMap;
+ use serde::{Serialize, Deserialize};
+ let mut columns: Vec < codegen::utils::model::StColumnDef > = Vec::new();
+ //获取属性名,属性值
+ for (k, v) in arr{
+ for (km, vm) in & v { //km字段名,vm字段值
+ #st_column_def_quote
+ }
+ }
+ //重新组装更新字段集合
+ //update字段集合
+ let mut updateVec : Vec = Vec::new();
+ //条件字段集合
+ let mut restrictionVec : Vec = Vec::new();
+ for column in columns {
+ let mut column_option = colums_map.get(&column.name.clone());
+ match column_option {
+ Some(col_opt) =>{
+ let mut col = ( * col_opt).clone();
+ col.name = column.name.clone();
+ col.crud_value = column.crud_value.clone();
+ updateVec.push(col);
+ },
+ None =>panic !("in columns no found field {}",&column.name.clone().to_string())
+ } ;
+ }
+
+ for column in restrictions {
+ let mut column_option = colums_map.get(&column.name.clone());
+ match column_option {
+ Some(col_opt) =>{
+ let mut col = ( * col_opt).clone();
+ col.name = column.name.clone();
+ col.crud_value = column.value.clone();
+ col.assign_type_t = column.assign.clone();
+ restrictionVec.push(col);
+ },
+ None =>panic !("in restrictions no found field {}",&column.name.clone().to_string())
+ } ;
+ }
+ let ret= conn.update_table_rows(&table_name,&updateVec,&restrictionVec);
+ if(commit){
+ if(ret==0){
+ conn.db_commit();
+ }else{
+ conn.db_rollback();
+ }
+ }
+ println!("update_table_rows ret**********: {}", ret.to_string());
+ Ok(ret)
+ };
+ };
+ return update_quote.into();
+}
+
+// #[proc_macro_attribute]
+// pub fn py_sql(args: TokenStream, func: TokenStream) -> TokenStream {
+// let args = parse_macro_input!(args as AttributeArgs);
+// println!(".........************.py_sql.**TokenStream********...........{}",func.to_string());
+//
+// let target_fn: ItemFn = syn::parse(func).unwrap();
+// let stream = impl_macro_py_sql(&target_fn, &args);
+// println!("{}",stream.to_string());
+// println!(".........************.py_sql.**********...........");
+//
+// stream
+// }
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/macro_driver/src/main.rs b/3rd/gstor/src/interface/rust/ncti-orm/macro_driver/src/main.rs
new file mode 100644
index 0000000000000000000000000000000000000000..c2364913834d949a46b34350d0a769e0d945b560
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/macro_driver/src/main.rs
@@ -0,0 +1,6 @@
+
+fn main() {
+
+ println!("create_index json: ", );
+
+}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/ncti_orm.iml b/3rd/gstor/src/interface/rust/ncti-orm/ncti_orm.iml
new file mode 100644
index 0000000000000000000000000000000000000000..134f44bd7b2d9f543e52fe0d50cadeab11e824a9
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/ncti_orm.iml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/rbs/Cargo.toml b/3rd/gstor/src/interface/rust/ncti-orm/rbs/Cargo.toml
new file mode 100644
index 0000000000000000000000000000000000000000..c563831c3800d9113c01392fdc3f144c5365e7f1
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/rbs/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "rbs"
+version = "0.1.0"
+edition = "2021"
+description = "Serialization framework for ORM"
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+num-traits = "0.2"
+rmp = "0.8"
+serde = {version="1.0",features=["derive"]}
+serde_bytes = "0.11"
+quickcheck = "1.0"
+byteorder = "1.4"
+serde_derive = "1.0"
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/index.rs b/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/index.rs
new file mode 100644
index 0000000000000000000000000000000000000000..3996f46f1da2318f98eee590ba64033164df03b1
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/index.rs
@@ -0,0 +1,73 @@
+use crate::Value;
+use std::ops::{Index, IndexMut};
+
+impl Index for Value {
+ type Output = Value;
+
+ fn index(&self, index: usize) -> &Value {
+ match self {
+ Value::Array(arr) => &arr[index],
+ Value::Ext(_, ext) => {
+ return ext.index(index);
+ }
+ _ => &Value::Null,
+ }
+ }
+}
+
+impl IndexMut for Value {
+ fn index_mut(&mut self, index: usize) -> &mut Self::Output {
+ match self {
+ Value::Array(arr) => &mut arr[index],
+ Value::Ext(_, ext) => {
+ return ext.index_mut(index);
+ }
+ _ => {
+ panic!("not an array!")
+ }
+ }
+ }
+}
+
+impl Index<&str> for Value {
+ type Output = Value;
+ fn index(&self, index: &str) -> &Self::Output {
+ match self {
+ Value::Map(m) => {
+ for (k, v) in m {
+ if k.as_str().unwrap_or_default().eq(index) {
+ return v;
+ }
+ }
+ return &Value::Null;
+ }
+ Value::Ext(_, ext) => {
+ return ext.index(index);
+ }
+ _ => {
+ return &Value::Null;
+ }
+ }
+ }
+}
+
+impl IndexMut<&str> for Value {
+ fn index_mut(&mut self, index: &str) -> &mut Self::Output {
+ match self {
+ Value::Map(m) => {
+ for (k, v) in m {
+ if k.as_str().unwrap_or_default().eq(index) {
+ return v;
+ }
+ }
+ panic!("not have index={}", index)
+ }
+ Value::Ext(_, ext) => {
+ return ext.index_mut(index);
+ }
+ _ => {
+ panic!("not have index={}", index)
+ }
+ }
+ }
+}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/lib.rs b/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/lib.rs
new file mode 100644
index 0000000000000000000000000000000000000000..2fce0991a22a95eb3caa7abe922f884247f65a8e
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/lib.rs
@@ -0,0 +1,47 @@
+#[macro_use]
+extern crate serde;
+extern crate core;
+
+pub mod index;
+#[allow(deprecated)]
+pub mod value;
+
+pub use crate::value::ext::Error;
+pub use value::ext::{deserialize_from, from_value};
+pub use value::ext::{to_value, to_value_def};
+pub use value::Value;
+
+impl Value {
+ pub fn into_ext(self, name: &'static str) -> Self {
+ match self {
+ Value::Ext(_, _) => self,
+ _ => Value::Ext(name, Box::new(self)),
+ }
+ }
+
+ pub fn is_empty(&self) -> bool {
+ match self {
+ Value::Null => true,
+ Value::Bool(_) => false,
+ Value::I32(_) => false,
+ Value::I64(_) => false,
+ Value::U32(_) => false,
+ Value::U64(_) => false,
+ Value::F32(_) => false,
+ Value::F64(_) => false,
+ Value::String(v) => v.is_empty(),
+ Value::Binary(v) => v.is_empty(),
+ Value::Array(v) => v.is_empty(),
+ Value::Map(v) => v.is_empty(),
+ Value::Ext(_, v) => v.is_empty(),
+ }
+ }
+}
+//注解说明宏应该是可用的。 如果没有该注解,这个宏不能被引入作用域。
+#[macro_export]
+//使用 macro_rules! 和宏名称开始宏定义,且所定义的宏并 不带 感叹号。名字后跟大括号表示宏定义体,在该例中宏名称是 to_value 。
+macro_rules! to_value {
+ ($arg:expr) => {
+ $crate::to_value($arg).unwrap_or_default()
+ };
+}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/main.rs b/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/main.rs
new file mode 100644
index 0000000000000000000000000000000000000000..9649b63d1c90e1d1b202cd47e362eff758025548
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/main.rs
@@ -0,0 +1,9 @@
+use rbs::value::map::ValueMap;
+
+fn main() {
+ println!("Hello, world!");
+ let mut m = ValueMap::new();
+ m.insert("1".into(), 1.into());
+ m.insert("2".into(), 2.into());
+ assert_eq!(m.to_string(), r#"{"1":1,"2":2}"#);
+}
diff --git a/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/value/ext/de.rs b/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/value/ext/de.rs
new file mode 100644
index 0000000000000000000000000000000000000000..8071d91d6779c4c64ce2ea945b8f66db737db2f6
--- /dev/null
+++ b/3rd/gstor/src/interface/rust/ncti-orm/rbs/src/value/ext/de.rs
@@ -0,0 +1,656 @@
+use std::fmt::{self, Display, Formatter};
+use std::iter::ExactSizeIterator;
+use std::vec::IntoIter;
+
+use serde::de::{self, DeserializeSeed, IntoDeserializer, SeqAccess, Unexpected, Visitor};
+use serde::{self, Deserialize, Deserializer};
+
+
+use crate::value::map::ValueMap;
+use crate::value::Value;
+
+use super::{Error, ValueExt};
+//在rust下,通常使用 serde、serde_json三方库进行序列化与反序列化操作;
+//map反射转对象
+/// from_value
+#[inline]
+pub fn from_value(val: Value) -> Result
+where
+ T: for<'de> Deserialize<'de>,
+{
+ println!("from_value>>>>> deserialize_from={:?}", val);
+ deserialize_from(val)
+}
+
+/// deserialize_from
+#[inline]
+pub fn deserialize_from<'de, T, D>(val: D) -> Result
+where
+ T: Deserialize<'de>,
+ D: Deserializer<'de, Error = Error>,
+{
+ Deserialize::deserialize(val)
+}
+
+impl de::Error for Error {
+ #[cold]
+ fn custom(msg: T) -> Self {
+ Error::Syntax(format!("{}", msg))
+ }
+}
+
+//反序列化,映射对应的字段和值 ,map数组对象
+impl<'de> Deserialize<'de> for Value {
+ #[inline]
+ fn deserialize(de: D) -> Result
+ where
+ D: de::Deserializer<'de>,
+ {
+ struct ValueVisitor;
+ impl<'de> serde::de::Visitor<'de> for ValueVisitor {
+ type Value = Value;
+ // cold- 该函数不太可能被执行,因此请对其进行优化(并调用) 到它)不同。
+ #[cold]
+ fn expecting(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
+ "any valid MessagePack value".fmt(fmt)
+ }
+//提示编译器执行内联扩展。
+ #[inline]
+ fn visit_some(self, de: D) -> Result
+ where
+ D: de::Deserializer<'de>,
+ {
+ Deserialize::deserialize(de)
+ }
+
+ #[inline]
+ fn visit_none(self) -> Result {
+ Ok(Value::Null)
+ }
+
+ #[inline]
+ fn visit_unit(self) -> Result {
+ Ok(Value::Null)
+ }
+
+ #[inline]
+ fn visit_bool(self, value: bool) -> Result {
+ Ok(Value::Bool(value))
+ }
+
+ fn visit_u32(self, v: u32) -> Result
+ where
+ E: de::Error,
+ {
+ Ok(Value::U32(v))
+ }
+
+ #[inline]
+ fn visit_u64(self, value: u64) -> Result {
+ Ok(Value::U64(value))
+ }
+
+ fn visit_i32(self, v: i32) -> Result
+ where
+ E: de::Error,
+ {
+ Ok(Value::I32(v))
+ }
+
+ #[inline]
+ fn visit_i64(self, value: i64) -> Result {
+
+ Ok(Value::I64(value))
+ }
+
+ #[inline]
+ fn visit_f32(self, value: f32) -> Result {
+ Ok(Value::F32(value))
+ }
+
+ #[inline]
+ fn visit_f64(self, value: f64) -> Result {
+ Ok(Value::F64(value))
+ }
+
+ #[inline]
+ fn visit_string(self, value: String) -> Result {
+ Ok(Value::String(value))
+ }
+
+ #[inline]
+ fn visit_str(self, value: &str) -> Result
+ where
+ E: de::Error,
+ {
+
+ self.visit_string(String::from(value))
+ }
+
+ #[inline]
+ fn visit_seq(self, mut visitor: V) -> Result
+ where
+ V: SeqAccess<'de>,
+ {
+ let mut vec = {
+ match visitor.size_hint() {
+ None => {
+ vec![]
+ }
+ Some(l) => Vec::with_capacity(l),
+ }
+ };
+ while let Some(elem) = visitor.next_element()? {
+ vec.push(elem);
+ }
+ Ok(Value::Array(vec))
+ }
+
+ #[inline]
+ fn visit_bytes