提交 829fba90 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!1 commit bounds_checking_function source code

Merge pull request !1 from 刘嘉健/master
木兰宽松许可证, 第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
# bounds_checking_function
#### Description
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
#### Software Architecture
Software architecture 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.
#### Installation
- other standard functions in C11 Annex K will be analyzed in the future and implemented in this organization if necessary.
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
- handles the release, update, and maintenance of bounds_checking_function.
# bounds_checking_function
#### 介绍
{**以下是码云平台说明,您可以替换此简介**
码云是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
无论是个人、团队、或是企业,都能够用码云实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 码云特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
- 遵循C11 Annex K (Bounds-checking interfaces)的标准,选取并实现了常见的内存/字符串操作类的函数,如memcpy_s、strcpy_s等函数。
- 未来将分析C11 Annex K中的其他标准函数,如果有必要,将在该组织中实现。
- 处理边界检查函数的版本发布、更新以及维护。
此差异已折叠。
/*
* 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: 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;
}
/*
* 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
/*
* 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 <wchar.h>
#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
此差异已折叠。
/*
* 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));
}
/*
* 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 <wchar.h>
#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));
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
/*
* 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"
/*
* <FUNCTION DESCRIPTION>
* 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.
*
* <INPUT PARAMETERS>
* strDest Storage location for output.
* destMax Maximum number of characters to store.
* format Format-control string.
* ... Optional arguments
*
* <OUTPUT PARAMETERS>
* strDest is updated
*
* <RETURN VALUE>
* 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
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册