1 /**
2 * Copyright 2020 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef SECURECUTIL_H_46C86578_F8FF_4E49_8E64_9B175241761F
18 #define SECURECUTIL_H_46C86578_F8FF_4E49_8E64_9B175241761F
19 #include "securec.h"
20
21 #if (defined(_MSC_VER)) && (_MSC_VER >= 1400)
22 #define SECUREC_MASK_MSVC_CRT_WARNING __pragma(warning(push)) \
23 __pragma(warning(disable:4996 4127))
24 #define SECUREC_END_MASK_MSVC_CRT_WARNING __pragma(warning(pop))
25 #else
26 #define SECUREC_MASK_MSVC_CRT_WARNING
27 #define SECUREC_END_MASK_MSVC_CRT_WARNING
28 #endif
29 #define SECUREC_WHILE_ZERO SECUREC_MASK_MSVC_CRT_WARNING while (0) SECUREC_END_MASK_MSVC_CRT_WARNING
30
31 #ifndef SECUREC_HAVE_STRNLEN
32 #if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L)
33 #if SECUREC_IN_KERNEL
34 #define SECUREC_HAVE_STRNLEN 0
35 #else
36 #if defined(__GLIBC__) && __GLIBC__ >= 2 && defined(__GLIBC_MINOR__) && __GLIBC_MINOR__ >= 10
37 #define SECUREC_HAVE_STRNLEN 1
38 #else
39 #define SECUREC_HAVE_STRNLEN 0
40 #endif
41 #endif
42 #else
43 #define SECUREC_HAVE_STRNLEN 0
44 #endif
45 #endif
46
47 #if SECUREC_IN_KERNEL
48 /* in kernel disbale functions */
49 #ifndef SECUREC_ENABLE_SCANF_FILE
50 #define SECUREC_ENABLE_SCANF_FILE 0
51 #endif
52 #ifndef SECUREC_ENABLE_SCANF_FLOAT
53 #define SECUREC_ENABLE_SCANF_FLOAT 0
54 #endif
55 #ifndef SECUREC_ENABLE_SPRINTF_FLOAT
56 #define SECUREC_ENABLE_SPRINTF_FLOAT 0
57 #endif
58 #ifndef SECUREC_HAVE_MBTOWC
59 #define SECUREC_HAVE_MBTOWC 0
60 #endif
61 #ifndef SECUREC_HAVE_WCTOMB
62 #define SECUREC_HAVE_WCTOMB 0
63 #endif
64 #ifndef SECUREC_HAVE_WCHART
65 #define SECUREC_HAVE_WCHART 0
66 #endif
67 #else /* no in kernel */
68 /* Systems that do not support file, can define this macro to 0. */
69 #ifndef SECUREC_ENABLE_SCANF_FILE
70 #define SECUREC_ENABLE_SCANF_FILE 1
71 #endif
72 #ifndef SECUREC_ENABLE_SCANF_FLOAT
73 #define SECUREC_ENABLE_SCANF_FLOAT 1
74 #endif
75 /* Systems that do not support float, can define this macro to 0. */
76 #ifndef SECUREC_ENABLE_SPRINTF_FLOAT
77 #define SECUREC_ENABLE_SPRINTF_FLOAT 1
78 #endif
79 #ifndef SECUREC_HAVE_MBTOWC
80 #define SECUREC_HAVE_MBTOWC 1
81 #endif
82 #ifndef SECUREC_HAVE_WCTOMB
83 #define SECUREC_HAVE_WCTOMB 1
84 #endif
85 #ifndef SECUREC_HAVE_WCHART
86 #define SECUREC_HAVE_WCHART 1
87 #endif
88 #endif
89
90
91 #define SECUREC_INT_MAX 2147483647
92 #define SECUREC_MUL_SIXTEEN(x) ((x) << 4)
93 #define SECUREC_MUL_EIGHT(x) ((x) << 3)
94 #define SECUREC_MUL_TEN(x) ((((x) << 2) + (x)) << 1)
95 /* Limited format input and output width */
96 #define SECUREC_MAX_WIDTH_LEN_DIV_TEN 21474836
97 #define SECUREC_MAX_WIDTH_LEN SECUREC_MUL_TEN(SECUREC_MAX_WIDTH_LEN_DIV_TEN)
98 /* Is the x multiplied by 10 greater than */
99 #define SECUREC_MUL_TEN_ADD_BEYOND_MAX(x) (((x) > SECUREC_MAX_WIDTH_LEN_DIV_TEN))
100
101 #define SECUREC_FLOAT_BUFSIZE (309 + 40) /* Max length of double value */
102 #define SECUREC_FLOAT_BUFSIZE_LB (4932 + 40) /* Max length of long double value */
103 #define SECUREC_FLOAT_DEFAULT_PRECISION 6
104
105 /* This macro does not handle pointer equality or integer overflow */
106 #define SECUREC_MEMORY_NO_OVERLAP(dest, src, count) \
107 (((src) < (dest) && ((const char *)(src) + (count)) <= (char *)(dest)) || \
108 ((dest) < (src) && ((char *)(dest) + (count)) <= (const char *)(src)))
109
110 #define SECUREC_MEMORY_IS_OVERLAP(dest, src, count) \
111 (((src) < (dest) && ((const char *)(src) + (count)) > (char *)(dest)) || \
112 ((dest) < (src) && ((char *)(dest) + (count)) > (const char *)(src)))
113
114 /*
115 * Check whether the strings overlap, len is the length of the string not include terminator
116 * Length is related to data type char or wchar , do not force conversion of types
117 */
118 #define SECUREC_STRING_NO_OVERLAP(dest, src, len) \
119 (((src) < (dest) && ((src) + (len)) < (dest)) || \
120 ((dest) < (src) && ((dest) + (len)) < (src)))
121
122 /*
123 * Check whether the strings overlap for strcpy wcscpy function, dest len and src Len are not include terminator
124 * Length is related to data type char or wchar , do not force conversion of types
125 */
126 #define SECUREC_STRING_IS_OVERLAP(dest, src, len) \
127 (((src) < (dest) && ((src) + (len)) >= (dest)) || \
128 ((dest) < (src) && ((dest) + (len)) >= (src)))
129
130 /*
131 * Check whether the strings overlap for strcat wcscat function, dest len and src Len are not include terminator
132 * Length is related to data type char or wchar , do not force conversion of types
133 */
134 #define SECUREC_CAT_STRING_IS_OVERLAP(dest, destLen, src, srcLen) \
135 (((dest) < (src) && ((dest) + (destLen) + (srcLen)) >= (src)) || \
136 ((src) < (dest) && ((src) + (srcLen)) >= (dest)))
137
138
139 #if SECUREC_HAVE_STRNLEN
140 #define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \
141 *(outLen) = strnlen((str), (maxLen)); \
142 } SECUREC_WHILE_ZERO
143 #define SECUREC_CALC_STR_LEN_OPT(str, maxLen, outLen) do { \
144 if ((maxLen) > 8) { \
145 /* Optimization or len less then 8 */ \
146 if (*((str) + 0) == '\0') { \
147 *(outLen) = 0; \
148 } else if (*((str) + 1) == '\0') { \
149 *(outLen) = 1; \
150 } else if (*((str) + 2) == '\0') { \
151 *(outLen) = 2; \
152 } else if (*((str) + 3) == '\0') { \
153 *(outLen) = 3; \
154 } else if (*((str) + 4) == '\0') { \
155 *(outLen) = 4; \
156 } else if (*((str) + 5) == '\0') { \
157 *(outLen) = 5; \
158 } else if (*((str) + 6) == '\0') { \
159 *(outLen) = 6; \
160 } else if (*((str) + 7) == '\0') { \
161 *(outLen) = 7; \
162 } else if (*((str) + 8) == '\0') { \
163 /* Optimization with a length of 8 */ \
164 *(outLen) = 8; \
165 } else { \
166 /* The offset is 8 because the performance of 8 byte alignment is high */ \
167 *(outLen) = 8 + strnlen((str) + 8, (maxLen) - 8); \
168 } \
169 } else { \
170 SECUREC_CALC_STR_LEN((str), (maxLen), (outLen)); \
171 } \
172 } SECUREC_WHILE_ZERO
173 #else
174 #define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \
175 const char *strEnd = (const char *)(str); \
176 size_t availableSize = (size_t)(maxLen); \
177 while (availableSize > 0 && *strEnd != '\0') { \
178 --availableSize; \
179 ++strEnd; \
180 } \
181 *(outLen) = (size_t)(strEnd - (str)); \
182 } SECUREC_WHILE_ZERO
183 #define SECUREC_CALC_STR_LEN_OPT SECUREC_CALC_STR_LEN
184 #endif
185
186 #define SECUREC_CALC_WSTR_LEN(str, maxLen, outLen) do { \
187 const wchar_t *strEnd = (const wchar_t *)(str); \
188 *(outLen) = 0; \
189 while (*(outLen) < (maxLen) && *strEnd != L'\0') { \
190 *(outLen) = *(outLen) + 1; \
191 ++strEnd; \
192 } \
193 } SECUREC_WHILE_ZERO
194
195
196 #ifdef SECUREC_FORMAT_OUTPUT_INPUT
197 #if defined(SECUREC_COMPATIBLE_WIN_FORMAT) || defined(__ARMCC_VERSION)
198 typedef __int64 SecInt64;
199 typedef unsigned __int64 SecUnsignedInt64;
200 #if defined(__ARMCC_VERSION)
201 typedef unsigned int SecUnsignedInt32;
202 #else
203 typedef unsigned __int32 SecUnsignedInt32;
204 #endif
205 #else
206 typedef unsigned int SecUnsignedInt32;
207 typedef long long SecInt64;
208 typedef unsigned long long SecUnsignedInt64;
209 #endif
210
211 #ifdef SECUREC_FOR_WCHAR
212 #if defined(SECUREC_VXWORKS_PLATFORM) && !defined(__WINT_TYPE__)
213 typedef wchar_t wint_t;
214 #endif
215 typedef wchar_t SecChar;
216 typedef wchar_t SecUnsignedChar;
217 typedef wint_t SecInt;
218 typedef wint_t SecUnsignedInt;
219 #else /* no SECUREC_FOR_WCHAR */
220 typedef char SecChar;
221 typedef unsigned char SecUnsignedChar;
222 typedef int SecInt;
223 typedef unsigned int SecUnsignedInt;
224 #endif
225 #endif
226
227 /* Determine whether the address is 8-byte aligned
228 * Some systems do not have uintptr_t type, so use NULL to clear tool alarm 507
229 */
230 #define SECUREC_ADDR_ALIGNED_8(addr) (SecIsAddrAligned8((addr), NULL) == 0)
231
232 /* If you define the memory allocation function,
233 * you need to define the function prototype. You can define this macro as a header file.
234 */
235 #if defined(SECUREC_MALLOC_PROTOTYPE)
236 SECUREC_MALLOC_PROTOTYPE
237 #endif
238
239 #ifndef SECUREC_MALLOC
240 #define SECUREC_MALLOC(x) malloc((size_t)(x))
241 #endif
242
243 #ifndef SECUREC_FREE
244 #define SECUREC_FREE(x) free((void *)(x))
245 #endif
246
247 /* struct for performance */
248 typedef struct {
249 unsigned char buf[1]; /* Performance optimization code structure assignment length 1 bytes */
250 } SecStrBuf1;
251 typedef struct {
252 unsigned char buf[2]; /* Performance optimization code structure assignment length 2 bytes */
253 } SecStrBuf2;
254 typedef struct {
255 unsigned char buf[3]; /* Performance optimization code structure assignment length 3 bytes */
256 } SecStrBuf3;
257 typedef struct {
258 unsigned char buf[4]; /* Performance optimization code structure assignment length 4 bytes */
259 } SecStrBuf4;
260 typedef struct {
261 unsigned char buf[5]; /* Performance optimization code structure assignment length 5 bytes */
262 } SecStrBuf5;
263 typedef struct {
264 unsigned char buf[6]; /* Performance optimization code structure assignment length 6 bytes */
265 } SecStrBuf6;
266 typedef struct {
267 unsigned char buf[7]; /* Performance optimization code structure assignment length 7 bytes */
268 } SecStrBuf7;
269 typedef struct {
270 unsigned char buf[8]; /* Performance optimization code structure assignment length 8 bytes */
271 } SecStrBuf8;
272 typedef struct {
273 unsigned char buf[9]; /* Performance optimization code structure assignment length 9 bytes */
274 } SecStrBuf9;
275 typedef struct {
276 unsigned char buf[10]; /* Performance optimization code structure assignment length 10 bytes */
277 } SecStrBuf10;
278 typedef struct {
279 unsigned char buf[11]; /* Performance optimization code structure assignment length 11 bytes */
280 } SecStrBuf11;
281 typedef struct {
282 unsigned char buf[12]; /* Performance optimization code structure assignment length 12 bytes */
283 } SecStrBuf12;
284 typedef struct {
285 unsigned char buf[13]; /* Performance optimization code structure assignment length 13 bytes */
286 } SecStrBuf13;
287 typedef struct {
288 unsigned char buf[14]; /* Performance optimization code structure assignment length 14 bytes */
289 } SecStrBuf14;
290 typedef struct {
291 unsigned char buf[15]; /* Performance optimization code structure assignment length 15 bytes */
292 } SecStrBuf15;
293 typedef struct {
294 unsigned char buf[16]; /* Performance optimization code structure assignment length 16 bytes */
295 } SecStrBuf16;
296 typedef struct {
297 unsigned char buf[17]; /* Performance optimization code structure assignment length 17 bytes */
298 } SecStrBuf17;
299 typedef struct {
300 unsigned char buf[18]; /* Performance optimization code structure assignment length 18 bytes */
301 } SecStrBuf18;
302 typedef struct {
303 unsigned char buf[19]; /* Performance optimization code structure assignment length 19 bytes */
304 } SecStrBuf19;
305 typedef struct {
306 unsigned char buf[20]; /* Performance optimization code structure assignment length 20 bytes */
307 } SecStrBuf20;
308 typedef struct {
309 unsigned char buf[21]; /* Performance optimization code structure assignment length 21 bytes */
310 } SecStrBuf21;
311 typedef struct {
312 unsigned char buf[22]; /* Performance optimization code structure assignment length 22 bytes */
313 } SecStrBuf22;
314 typedef struct {
315 unsigned char buf[23]; /* Performance optimization code structure assignment length 23 bytes */
316 } SecStrBuf23;
317 typedef struct {
318 unsigned char buf[24]; /* Performance optimization code structure assignment length 24 bytes */
319 } SecStrBuf24;
320 typedef struct {
321 unsigned char buf[25]; /* Performance optimization code structure assignment length 25 bytes */
322 } SecStrBuf25;
323 typedef struct {
324 unsigned char buf[26]; /* Performance optimization code structure assignment length 26 bytes */
325 } SecStrBuf26;
326 typedef struct {
327 unsigned char buf[27]; /* Performance optimization code structure assignment length 27 bytes */
328 } SecStrBuf27;
329 typedef struct {
330 unsigned char buf[28]; /* Performance optimization code structure assignment length 28 bytes */
331 } SecStrBuf28;
332 typedef struct {
333 unsigned char buf[29]; /* Performance optimization code structure assignment length 29 bytes */
334 } SecStrBuf29;
335 typedef struct {
336 unsigned char buf[30]; /* Performance optimization code structure assignment length 30 bytes */
337 } SecStrBuf30;
338 typedef struct {
339 unsigned char buf[31]; /* Performance optimization code structure assignment length 31 bytes */
340 } SecStrBuf31;
341 typedef struct {
342 unsigned char buf[32]; /* Performance optimization code structure assignment length 32 bytes */
343 } SecStrBuf32;
344 typedef struct {
345 unsigned char buf[33]; /* Performance optimization code structure assignment length 33 bytes */
346 } SecStrBuf33;
347 typedef struct {
348 unsigned char buf[34]; /* Performance optimization code structure assignment length 34 bytes */
349 } SecStrBuf34;
350 typedef struct {
351 unsigned char buf[35]; /* Performance optimization code structure assignment length 35 bytes */
352 } SecStrBuf35;
353 typedef struct {
354 unsigned char buf[36]; /* Performance optimization code structure assignment length 36 bytes */
355 } SecStrBuf36;
356 typedef struct {
357 unsigned char buf[37]; /* Performance optimization code structure assignment length 37 bytes */
358 } SecStrBuf37;
359 typedef struct {
360 unsigned char buf[38]; /* Performance optimization code structure assignment length 38 bytes */
361 } SecStrBuf38;
362 typedef struct {
363 unsigned char buf[39]; /* Performance optimization code structure assignment length 39 bytes */
364 } SecStrBuf39;
365 typedef struct {
366 unsigned char buf[40]; /* Performance optimization code structure assignment length 40 bytes */
367 } SecStrBuf40;
368 typedef struct {
369 unsigned char buf[41]; /* Performance optimization code structure assignment length 41 bytes */
370 } SecStrBuf41;
371 typedef struct {
372 unsigned char buf[42]; /* Performance optimization code structure assignment length 42 bytes */
373 } SecStrBuf42;
374 typedef struct {
375 unsigned char buf[43]; /* Performance optimization code structure assignment length 43 bytes */
376 } SecStrBuf43;
377 typedef struct {
378 unsigned char buf[44]; /* Performance optimization code structure assignment length 44 bytes */
379 } SecStrBuf44;
380 typedef struct {
381 unsigned char buf[45]; /* Performance optimization code structure assignment length 45 bytes */
382 } SecStrBuf45;
383 typedef struct {
384 unsigned char buf[46]; /* Performance optimization code structure assignment length 46 bytes */
385 } SecStrBuf46;
386 typedef struct {
387 unsigned char buf[47]; /* Performance optimization code structure assignment length 47 bytes */
388 } SecStrBuf47;
389 typedef struct {
390 unsigned char buf[48]; /* Performance optimization code structure assignment length 48 bytes */
391 } SecStrBuf48;
392 typedef struct {
393 unsigned char buf[49]; /* Performance optimization code structure assignment length 49 bytes */
394 } SecStrBuf49;
395 typedef struct {
396 unsigned char buf[50]; /* Performance optimization code structure assignment length 50 bytes */
397 } SecStrBuf50;
398 typedef struct {
399 unsigned char buf[51]; /* Performance optimization code structure assignment length 51 bytes */
400 } SecStrBuf51;
401 typedef struct {
402 unsigned char buf[52]; /* Performance optimization code structure assignment length 52 bytes */
403 } SecStrBuf52;
404 typedef struct {
405 unsigned char buf[53]; /* Performance optimization code structure assignment length 53 bytes */
406 } SecStrBuf53;
407 typedef struct {
408 unsigned char buf[54]; /* Performance optimization code structure assignment length 54 bytes */
409 } SecStrBuf54;
410 typedef struct {
411 unsigned char buf[55]; /* Performance optimization code structure assignment length 55 bytes */
412 } SecStrBuf55;
413 typedef struct {
414 unsigned char buf[56]; /* Performance optimization code structure assignment length 56 bytes */
415 } SecStrBuf56;
416 typedef struct {
417 unsigned char buf[57]; /* Performance optimization code structure assignment length 57 bytes */
418 } SecStrBuf57;
419 typedef struct {
420 unsigned char buf[58]; /* Performance optimization code structure assignment length 58 bytes */
421 } SecStrBuf58;
422 typedef struct {
423 unsigned char buf[59]; /* Performance optimization code structure assignment length 59 bytes */
424 } SecStrBuf59;
425 typedef struct {
426 unsigned char buf[60]; /* Performance optimization code structure assignment length 60 bytes */
427 } SecStrBuf60;
428 typedef struct {
429 unsigned char buf[61]; /* Performance optimization code structure assignment length 61 bytes */
430 } SecStrBuf61;
431 typedef struct {
432 unsigned char buf[62]; /* Performance optimization code structure assignment length 62 bytes */
433 } SecStrBuf62;
434 typedef struct {
435 unsigned char buf[63]; /* Performance optimization code structure assignment length 63 bytes */
436 } SecStrBuf63;
437 typedef struct {
438 unsigned char buf[64]; /* Performance optimization code structure assignment length 64 bytes */
439 } SecStrBuf64;
440
441
442
443
444 /* User can change the error handler by modify the following definition,
445 * such as logging the detail error in file.
446 */
447 #if defined(_DEBUG) || defined(DEBUG)
448 #if defined(SECUREC_ERROR_HANDLER_BY_ASSERT)
449 #define SECUREC_ERROR_INVALID_PARAMTER(msg) assert(msg "invalid argument" == NULL)
450 #define SECUREC_ERROR_INVALID_RANGE(msg) assert(msg "invalid dest buffer size" == NULL)
451 #define SECUREC_ERROR_BUFFER_OVERLAP(msg) assert(msg "buffer overlap" == NULL)
452 #elif defined(SECUREC_ERROR_HANDLER_BY_PRINTF)
453 #if SECUREC_IN_KERNEL
454 #define SECUREC_ERROR_INVALID_PARAMTER(msg) printk("%s invalid argument\n", msg)
455 #define SECUREC_ERROR_INVALID_RANGE(msg) printk("%s invalid dest buffer size\n", msg)
456 #define SECUREC_ERROR_BUFFER_OVERLAP(msg) printk("%s buffer overlap\n", msg)
457 #else
458 #define SECUREC_ERROR_INVALID_PARAMTER(msg) printf("%s invalid argument\n", msg)
459 #define SECUREC_ERROR_INVALID_RANGE(msg) printf("%s invalid dest buffer size\n", msg)
460 #define SECUREC_ERROR_BUFFER_OVERLAP(msg) printf("%s buffer overlap\n", msg)
461 #endif
462 #elif defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG)
463 #define SECUREC_ERROR_INVALID_PARAMTER(msg) LogSecureCRuntimeError(msg " EINVAL\n")
464 #define SECUREC_ERROR_INVALID_RANGE(msg) LogSecureCRuntimeError(msg " ERANGE\n")
465 #define SECUREC_ERROR_BUFFER_OVERLAP(msg) LogSecureCRuntimeError(msg " EOVERLAP\n")
466 #else /* no HANDLER is defined */
467 #define SECUREC_ERROR_INVALID_PARAMTER(msg) ((void)0)
468 #define SECUREC_ERROR_INVALID_RANGE(msg) ((void)0)
469 #define SECUREC_ERROR_BUFFER_OVERLAP(msg) ((void)0)
470 #endif
471 #else /* no DEBUG */
472 #define SECUREC_ERROR_INVALID_PARAMTER(msg) ((void)0)
473 #define SECUREC_ERROR_INVALID_RANGE(msg) ((void)0)
474 #define SECUREC_ERROR_BUFFER_OVERLAP(msg) ((void)0)
475 #endif
476
477 #ifdef __cplusplus
478 extern "C" {
479 #endif
480
481 /* assembly language memory copy and memory set for X86 or MIPS ... */
482 #ifdef SECUREC_USE_ASM
483 extern void *memcpy_opt(void *, const void *, size_t);
484 extern void *memset_opt(void *, int, size_t);
485 #endif
486
487 #if defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG)
488 extern void LogSecureCRuntimeError(const char *errDetail);
489 #endif
490
491 #ifdef SECUREC_INLINE_DO_MEMCPY
SecDoMemcpy(void * dest,const void * src,size_t count)492 static void SecDoMemcpy(void *dest, const void *src, size_t count)
493 {
494 /*
495 * if SECUREC_USE_ASM macro is enabled, it will call assembly language function to improve performance.
496 */
497 #ifdef SECUREC_USE_ASM
498 (void)memcpy_opt(dest, src, count);
499 #else
500 /* large enough, let system API do it */
501 (void)memcpy(dest, src, count);
502 #endif
503 }
504 #endif
505
506 #ifdef SECUREC_INLINE_DO_MEMSET
SecDoMemset(void * dest,int c,size_t count)507 static void SecDoMemset(void *dest, int c, size_t count)
508 {
509 #ifdef SECUREC_USE_ASM
510 (void)memset_opt(dest, c, count);
511 #else
512 (void)memset(dest, c, count);
513 #endif
514 }
515 #endif
516
517 #ifdef SECUREC_INLINE_STR_LEN
518 /* The function compiler will be inlined and not placed in other files */
SecStrMinLen(const char * str,size_t maxLen)519 static size_t SecStrMinLen(const char *str, size_t maxLen)
520 {
521 size_t len;
522 SECUREC_CALC_STR_LEN(str, maxLen, &len);
523 return len;
524 }
525 #endif
526
527 #ifdef SECUREC_INLINE_STR_LEN_OPT
528 /* The function compiler will be inlined and not placed in other files */
SecStrMinLenOpt(const char * str,size_t maxLen)529 static size_t SecStrMinLenOpt(const char *str, size_t maxLen)
530 {
531 size_t len;
532 SECUREC_CALC_STR_LEN_OPT(str, maxLen, &len);
533 return len;
534 }
535 #endif
536
537 #ifdef __cplusplus
538 }
539 #endif /* __cplusplus */
540 #endif
541
542