• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 /* *
20  * @defgroup iot_secure_c Secure C library APIs
21  * @ingroup iot_secure
22  */
23 
24 #ifndef __HI_STDLIB_H__
25 #define __HI_STDLIB_H__
26 #include <hi_types_base.h>
27 
28 HI_START_HEADER
29 
30 #ifndef EOK
31 #define EOK 0
32 #endif
33 
34 #ifndef ERRNO_T
35 #define ERRNO_T
36 typedef int errno_t;
37 #endif
38 
39 #ifndef SIZE_T
40 #define SIZE_T
41 typedef unsigned int size_t;
42 #endif
43 
44 /* *
45 * @ingroup  iot_secure_c
46 * @brief  Copies the source string to the destination buffer.CNcomment:复制源字符串到目的缓冲区。CNend
47 *
48 * @par 描述: Copies the source string to the destination buffer.
49 CNcomment:复制源字符串到目的缓冲区。CNend
50 *
51 * @attention None
52 *
53 * @param dest     [OUT] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
54 * @param dest_max [IN]  type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
55 * @param src      [IN]  type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
56 *
57 * @retval #EOK Success
58 * @retval #Other Failure
59 *
60 * @par 依赖:
61 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
62 * @see None
63 * @since Hi3861_V100R001C00
64 */
65 extern errno_t strcpy_s(char *dest, size_t dest_max, const char *src);
66 
67 /* *
68 * @ingroup  iot_secure_c
69 * @brief  Copies the source string of a specified length to the destination buffer.
70 CNcomment:复制指定长度源字符串到目的缓冲区。CNend
71 *
72 * @par 描述:Copies the source string of a specified length to the destination buffer.
73 CNcomment:复制指定长度源字符串到目的缓冲区。CNend
74 * @attention None
75 *
76 * @param dest     [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
77 * @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
78 * @param src      [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
79 * @param count    [IN] type #size_t, Number of characters copied from the source buffer.
80 CNcomment:从源缓冲区中复制的字符数。CNend
81 *
82 * @retval #EOK Success
83 * @retval #Other Failure
84 *
85 * @par 依赖:
86 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
87 * @see None
88 * @since Hi3861_V100R001C00
89 */
90 extern errno_t strncpy_s(char *dest, size_t dest_max, const char *src, size_t count);
91 
92 /* *
93 * @ingroup  iot_secure_c
94 * @brief  Concatenates the source string to the end of the destination string.
95 CNcomment:将源字符串连接到目的字符串后面CNend
96 *
97 * @par 描述:Concatenates the source string to the end of the destination string.
98 CNcomment:将源字符串连接到目的字符串后面。CNend
99 * @attention None
100 *
101 * @param dest     [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
102 * @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
103 * @param src      [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
104 *
105 * @retval #EOK Success
106 * @retval #Other Failure
107 *
108 * @par 依赖:
109 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
110 * @see None
111 * @since Hi3861_V100R001C00
112 */
113 extern errno_t strcat_s(char *dest, size_t dest_max, const char *src);
114 
115 /* *
116 * @ingroup  iot_secure_c
117 * @brief  Concatenates the source string of a specified length to the end of the destination string.
118 CNcomment:将指定长度的源字符串连接到目的字符串后面。CNend
119 *
120 * @par 描述: Concatenates the source string of a specified length to the end of the destination string.
121 CNcomment:将指定长度的源字符串连接到目的字符串后面。CNend
122 * @attention None
123 *
124 * @param dest     [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
125 * @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
126 * @param src      [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
127 * @param count    [IN] type #size_t, Number of characters copied from the source buffer.
128 CNcomment:从源缓冲区连接的字符数。CNend
129 *
130 * @retval #EOK Success
131 * @retval #Other Failure
132 *
133 * @par 依赖:
134 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
135 * @see None
136 * @since Hi3861_V100R001C00
137 */
138 extern errno_t strncat_s(char *dest, size_t dest_max, const char *src, size_t count);
139 
140 /* *
141 * @ingroup  iot_secure_c
142 * @brief  Copies the data from the source buffer to the destination buffer.
143 CNcomment:复制源缓冲区的数据到目的缓冲区。CNend
144 *
145 * @par 描述: Copies the data from the source buffer to the destination buffer.
146 CNcomment:复制源缓冲区的数据到目的缓冲区。CNend
147 * @attention None
148 *
149 * @param dest     [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
150 * @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
151 * @param src      [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
152 * @param count    [IN] type #size_t, Number of characters copied from the source buffer.
153 CNcomment:从源缓冲区中复制的字符数。CNend
154 *
155 * @retval #EOK Success
156 * @retval #Other Failure
157 *
158 * @par 依赖:
159 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
160 * @see None
161 * @since Hi3861_V100R001C00
162 */
163 extern errno_t memcpy_s(void *dest, size_t dest_max, const void *src, size_t count);
164 
165 /* *
166 * @ingroup  iot_secure_c
167 * @brief  Sets the size of the destination buffer to a specific value.
168 CNcomment:设置目的缓冲区为特定值。CNend
169 *
170 * @par 描述: Sets the size of the destination buffer to a specific value.
171 CNcomment:设置目的缓冲区为特定值。CNend
172 * @attention None
173 *
174 * @param dest     [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
175 * @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
176 * @param c        [IN] type #const #char *, Source buffer.CNcomment:特定值。CNend
177 * @param count    [IN] type #size_t, Number of characters copied from the source buffer.
178 CNcomment:设置为特定值的字符数。CNend
179 *
180 * @retval #EOK Success
181 * @retval #Other Failure
182 *
183 * @par 依赖:
184 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
185 * @see None
186 * @since Hi3861_V100R001C00
187 */
188 extern errno_t memset_s(void *dest, size_t dest_max, int c, size_t count);
189 
190 /* *
191 * @ingroup  iot_secure_c
192 * @brief  Moves the data from the source buffer to the destination buffer.
193 CNcomment:移动源缓冲区的数据到目的缓冲区。CNend
194 *
195 * @par 描述:Moves the data from the source buffer to the destination buffer.
196 CNcomment:移动源缓冲区的数据到目的缓冲区。CNend
197 * @attention None
198 *
199 * @param dest     [IN] type #char *, Destination buffer.CNcomment:目的缓冲区。CNend
200 * @param dest_max [IN] type #size_t, Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
201 * @param src      [IN] type #const #char *, Source buffer.CNcomment:源缓冲区。CNend
202 * @param count    [IN] type #size_t, Number of characters copied from the source buffer.
203 CNcomment:从源缓冲区中移动的字符数。CNend
204 *
205 * @retval #EOK Success
206 * @retval #Other Failure
207 *
208 * @par 依赖:
209 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
210 * @see None
211 * @since Hi3861_V100R001C00
212 */
213 extern errno_t memmove_s(void *dest, size_t dest_max, const void *src, size_t count);
214 
215 /* *
216 * @ingroup  iot_secure_c
217 * @brief  Splits a string into substrings according to the specified separators.
218 CNcomment:将字符串按照指定的分隔符分割成子字符串。CNend
219 *
220 * @par 描述: Splits a string into substrings according to the specified separators.
221 CNcomment:将字符串按照指定的分隔符分割成子字符串。CNend
222 * @attention None
223 *
224 * @param token   [IN] type #char *。 String to be split.CNcomment:要分割的字符串。CNend
225 * @param delimit [IN] type #const char *。 String separator.CNcomment:字符串分隔符。CNend
226 * @param context [IN] type #char* 。Position information after a call to HI_strtok_s is saved.
227 CNcomment:保存调用HI_strtok_s后的位置信息。CNend
228 *
229 * @retval #char* Point to the next token. CNcomment:指向在token中的下一个token。CNend
230 * @retval #HI_NULL A specified substring is not found or an error occurs.
231 CNcomment:没有找到指定的子字符串或者发生错误。CNend
232 *
233 * @par 依赖:
234 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
235 * @see None
236 * @since Hi3861_V100R001C00
237 */
238 extern char *strtok_s(char *token, const char *delimit, char **context);
239 
240 /* *
241 * @ingroup  iot_secure_c
242 * @brief  Formats the data and outputs it to the destination buffer.
243 CNcomment:将数据格式化输出到目的缓冲区。CNend
244 *
245 * @par 描述: Formats the data and outputs it to the destination buffer.
246 CNcomment:将数据格式化输出到目的缓冲区。CNend
247 * @attention None
248 *
249 * @param dest     [OUT] type #char *。 Destination buffer.CNcomment:目的缓冲区。CNend
250 * @param dest_max [IN]  type #size_t。 Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
251 * @param format   [IN]  type #const #char *。 Formatting control string.CNcomment:格式化控制字符串。CNend
252 * @param ...      [IN]  Optional parameter CNcomment:可选参数。CNend
253 *
254 * @retval #>=0 Return the number of bytes stored in dest, not counting the terminating null character.
255 CNcomment:返回存储在dest的字节数,不包括结束符CNend
256 * @retval #-1 Failure
257 *
258 * @par 依赖:
259 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
260 * @see None
261 * @since Hi3861_V100R001C00
262 */
263 extern int sprintf_s(char *dest, size_t dest_max, const char *format, ...);
264 
265 /* *
266 * @ingroup  iot_secure_c
267 * @brief Formats the data according to a specified length and outputs the data to the destination buffer.
268 CNcomment:将数据按照指定长度格式化输出到目的缓冲区。CNend
269 *
270 * @par 描述: Formats the data according to a specified length and outputs the data to the destination buffer.
271 CNcomment:将数据按照指定长度格式化输出到目的缓冲区。CNend
272 * @attention None
273 *
274 * @param dest     [OUT] type #char *。 Destination buffer.CNcomment:目的缓冲区。CNend
275 * @param dest_max [IN]  type #size_t。 Size of the destination buffer.CNcomment:目的缓冲区大小。CNend
276 * @param count    [IN]  type #size_t。 Number of formatted characters to be output to the destination buffer.
277 CNcomment:要输出到目的缓冲区的格式化字符个数。CNend
278 * @param format   [IN]  type #const #char *。 Formatting control string.CNcomment:格式化控制字符串。CNend
279 * @param ...      [IN]  Optional parameter CNcomment:可选参数。CNend
280 *
281 * @retval #>=0 Return the number of bytes stored in dest, not counting the terminating null character.
282 CNcomment:返回存储在dest的字节数,不包括结束符CNend
283 * @retval #-1 Failure
284 *
285 * @par 依赖:
286 * @li hi_stdlib.h: This file declares the APIs.CNcomment:该接口声明所在的头文件。CNend
287 * @see None
288 * @since Hi3861_V100R001C00
289 */
290 extern int snprintf_s(char *dest, size_t dest_max, size_t count, const char *format, ...);
291 
292 /*
293  * C库接口
294  */
295 extern int memcmp(const void *str1, const void *str2, size_t n);
296 extern size_t strlen(const char *src);
297 extern int strcmp(const char *str1, const char *str2);
298 extern int strncmp(const char *str1, const char *str2, size_t n);
299 
300 #if defined(HAVE_PCLINT_CHECK)
301 #define UT_CONST const
302 #else
303 #define UT_CONST
304 #endif
305 
306 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
307 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5,0,0))
308 extern unsigned long strtoul(const char *nptr, char **endptr, int base);
309 #endif
310 #endif
311 extern UT_CONST char *strstr(const char *str1, const char *str2);
312 extern UT_CONST char *strchr(const char *s, int c);
313 
314 HI_END_HEADER
315 #endif /* __HI_STDLIB_H__ */
316