提交 1182b874 编写于 作者: L liu

add source code

上级 70410ac7
木兰宽松许可证, 第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
此差异已折叠。
/*
* 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 <linux/kernel.h>
#include <linux/module.h>
#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 <stdio.h>
#endif
#if SECUREC_HAVE_STRING_H
#include <string.h>
#endif
#if SECUREC_HAVE_STDLIB_H
#include <stdlib.h>
#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 <stddef.h>
#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
/*
* 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"
/*
* <FUNCTION 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*)
* 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.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
* format Format control string, see Format Specifications.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The convered value stored in user assigned address
*
* <RETURN VALUE>
* 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;
}
/*
* 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"
/*
* <FUNCTION DESCRIPTION>
* 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.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
* format Format control string, see Format Specifications.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* 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;
}
/*
* 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 */
}
}
/*
* <FUNCTION DESCRIPTION>
* 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.
*
* <INPUT PARAMETERS>
* buffer Storage location for input string.
* destMax The size of the buffer.
*
* <OUTPUT PARAMETERS>
* buffer is updated
*
* <RETURN VALUE>
* 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;
}
此差异已折叠。
此差异已折叠。
/*
* 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
/*
* <FUNCTION DESCRIPTION>
* The memmove_s function copies count bytes of characters from src to dest.
* This function can be assigned correctly when memory overlaps.
* <INPUT PARAMETERS>
* dest Destination object.
* destMax Size of the destination buffer.
* src Source object.
* count Number of characters to copy.
*
* <OUTPUT PARAMETERS>
* dest buffer is uptdated.
*
* <RETURN VALUE>
* 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
/*
* 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;
}
/*
* <FUNCTION 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.
*
* <INPUT PARAMETERS>
* dest Pointer to destination.
* destMax The size of the buffer.
* c Character to set.
* count Number of characters.
*
* <OUTPUT PARAMETERS>
* dest buffer is uptdated.
*
* <RETURN VALUE>
* 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
此差异已折叠。
/*
* 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"
/*
* <FUNCTION DESCRIPTION>
* 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.
*
* <INPUT PARAMETERS>
* format Format control string.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* 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;
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册