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