• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27
18 #define __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27
19 
20 #include "securectype.h"
21 #include <stdarg.h>
22 
23 #ifndef SECUREC_HAVE_ERRNO_H
24 #if SECUREC_IN_KERNEL
25 #define SECUREC_HAVE_ERRNO_H 0
26 #else
27 #define SECUREC_HAVE_ERRNO_H 1
28 #endif
29 #endif
30 
31 /* EINVAL ERANGE may defined in errno.h */
32 #if SECUREC_HAVE_ERRNO_H
33 #include <errno.h>
34 #endif
35 
36 /* define error code */
37 #if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \
38     (defined(__STDC_WANT_LIB_EXT1__) && (__STDC_WANT_LIB_EXT1__ == 0))
39 #ifndef SECUREC_DEFINED_ERRNO_TYPE
40 #define SECUREC_DEFINED_ERRNO_TYPE
41 /* just check whether macrodefinition exists. */
42 #ifndef errno_t
43 typedef int errno_t;
44 #endif
45 #endif
46 #endif
47 
48 /* success */
49 #ifndef EOK
50 #define EOK 0
51 #endif
52 
53 #ifndef EINVAL
54 /* The src buffer is not correct and destination buffer cant not be reset */
55 #define EINVAL 22
56 #endif
57 
58 #ifndef EINVAL_AND_RESET
59 /* Once the error is detected, the dest buffer must be reseted! */
60 #define EINVAL_AND_RESET (22 | 128)
61 #endif
62 
63 #ifndef ERANGE
64 /* The destination buffer is not long enough and destination buffer can not be reset */
65 #define ERANGE 34
66 #endif
67 
68 #ifndef ERANGE_AND_RESET
69 /* Once the error is detected, the dest buffer must be reseted! */
70 #define ERANGE_AND_RESET  (34 | 128)
71 #endif
72 
73 #ifndef EOVERLAP_AND_RESET
74 /* Once the buffer overlap is detected, the dest buffer must be reseted! */
75 #define EOVERLAP_AND_RESET (54 | 128)
76 #endif
77 
78 /* if you need export the function of this library in Win32 dll, use __declspec(dllexport) */
79 #ifndef SECUREC_API
80 #if defined(SECUREC_DLL_EXPORT)
81 #define SECUREC_API __declspec(dllexport)
82 #elif defined(SECUREC_DLL_IMPORT)
83 #define SECUREC_API __declspec(dllimport)
84 #else
85 /* Standardized function declaration . If a security function is declared in the your code,
86  * it may cause a compilation alarm,Please delete the security function you declared
87  * Adding extern under windows will cause the system to have inline functions to expand,
88  * so do not add the extern in default
89  */
90 #if defined(_MSC_VER)
91 #define SECUREC_API
92 #else
93 #define SECUREC_API extern
94 #endif
95 #endif
96 #endif
97 
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101     /*
102      * Description: The GetHwSecureCVersion function get SecureC Version string and version number.
103      * Parameter: verNumber - to store version number
104      * Return:   version string
105      */
106     SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber);
107 
108 #if SECUREC_ENABLE_MEMSET
109     /*
110      * Description: The memset_s function copies the value of c (converted to an unsigned char) into each of
111      * the first count characters of the object pointed to by dest.
112      * Parameter: dest - destination  address
113      * Parameter: destMax -The maximum length of destination buffer
114      * Parameter: c - the value to be copied
115      * Parameter: count -copies fisrt count characters of  dest
116      * Return:    EOK if there was no runtime-constraint violation
117      */
118     SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count);
119 #endif
120 
121 #ifndef SECUREC_ONLY_DECLARE_MEMSET
122 #define SECUREC_ONLY_DECLARE_MEMSET     0
123 #endif
124 
125 #if SECUREC_ONLY_DECLARE_MEMSET == 0
126 
127 #if SECUREC_ENABLE_MEMMOVE
128     /*
129      * Description: The memmove_s function copies n characters from the object pointed to by src
130      * into the object pointed to by dest.
131      * Parameter: dest - destination  address
132      * Parameter: destMax -The maximum length of destination buffer
133      * Parameter: src -source  address
134      * Parameter: count -copies count wide characters from the  src
135      * Return:    EOK if there was no runtime-constraint violation
136      */
137     SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count);
138 #endif
139 
140 #if SECUREC_ENABLE_MEMCPY
141     /*
142      * Description: The memcpy_s function copies n characters from the object pointed to
143      * by src into the object pointed to by dest.
144      * Parameter: dest - destination  address
145      * Parameter: destMax -The maximum length of destination buffer
146      * Parameter: src -source  address
147      * Parameter: count -copies count  characters from the  src
148      * Return:    EOK if there was no runtime-constraint violation
149      */
150     SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count);
151 #endif
152 
153 #if SECUREC_ENABLE_STRCPY
154     /*
155      * Description: The strcpy_s function copies the string pointed to by strSrc (including
156      * the terminating null character) into the array pointed to by strDest
157      * Parameter: strDest - destination  address
158      * Parameter: destMax -The maximum length of destination buffer(including the terminating null character)
159      * Parameter: strSrc -source  address
160      * Return:    EOK if there was no runtime-constraint violation
161      */
162     SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc);
163 #endif
164 
165 #if SECUREC_ENABLE_STRNCPY
166     /*
167      * Description: The strncpy_s function copies not more than n successive characters (not including
168      * the terminating null character)
169      *                     from the array pointed to by strSrc to the array pointed to by strDest
170      * Parameter: strDest - destination  address
171      * Parameter: destMax -The maximum length of destination buffer(including the terminating null character)
172      * Parameter: strSrc -source  address
173      * Parameter: count -copies count  characters from the  src
174      * Return:    EOK if there was no runtime-constraint violation
175      */
176     SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
177 #endif
178 
179 #if SECUREC_ENABLE_STRCAT
180     /*
181      * Description: The strcat_s function appends a copy of the  string pointed to by strSrc (including
182      * the terminating null  character)
183      *                     to the end of the  string pointed to by strDest
184      * Parameter: strDest - destination  address
185      * Parameter: destMax -The maximum length of destination buffer(including the terminating null wide character)
186      * Parameter: strSrc -source  address
187      * Return:    EOK if there was no runtime-constraint violation
188      */
189     SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc);
190 #endif
191 
192 #if SECUREC_ENABLE_STRNCAT
193     /*
194      * Description: The strncat_s function appends not more than n successive  characters (not including
195      * the terminating null  character)
196      *                       from the array pointed to by strSrc to the end of the  string pointed to by strDest.
197      * Parameter: strDest - destination  address
198      * Parameter: destMax -The maximum length of destination buffer(including the terminating null character)
199      * Parameter: strSrc -source  address
200      * Parameter: count -copies count  characters from the  src
201      * Return:    EOK if there was no runtime-constraint violation
202      */
203     SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
204 #endif
205 
206 #if SECUREC_ENABLE_VSPRINTF
207     /*
208      * Description:  The vsprintf_s function is equivalent to the vsprintf function except for the Parameter: destMax
209      * and the explicit runtime-constraints violation
210      * Parameter: strDest -  produce output according to a format ,write to the character string strDest
211      * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte)
212      * Parameter: format - fromat string
213      * Parameter: argList - instead of  a variable  number of arguments
214      * Return:    the number of characters printed(not including the terminating null byte ('\0')),
215      * If an error occurred Return: -1.
216      */
217     SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format,
218                                va_list argList) SECUREC_ATTRIBUTE(3, 0);
219 #endif
220 
221 #if SECUREC_ENABLE_SPRINTF
222     /*
223      * Description:  The sprintf_s function is equivalent to the sprintf function except for the Parameter: destMax
224      * and the explicit runtime-constraints violation
225      * Parameter: strDest -  produce output according to a format ,write to the character string strDest
226      * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte ('\0'))
227      * Parameter: format - fromat string
228      * Return:    the number of characters printed(not including the terminating null byte ('\0')),
229      * If an error occurred Return: -1.
230      */
231     SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
232 #endif
233 
234 #if SECUREC_ENABLE_VSNPRINTF
235     /*
236      * Description:  The vsnprintf_s function is equivalent to the vsnprintf function except for the Parameter:
237      * destMax/count and the explicit runtime-constraints violation
238      * Parameter: strDest -  produce output according to a format ,write to the character string strDest
239      * Parameter: destMax - The maximum length of destination buffer(including the terminating null  byte ('\0'))
240      * Parameter: count - do not write more than count bytes to strDest(not including the terminating null  byte ('\0'))
241      * Parameter: format - fromat string
242      * Parameter: argList - instead of  a variable  number of arguments
243      * Return:    the number of characters printed(not including the terminating null byte ('\0')),
244      * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
245      */
246     SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
247                                 va_list argList) SECUREC_ATTRIBUTE(4, 0);
248 #endif
249 
250 #if SECUREC_ENABLE_SNPRINTF
251     /*
252      * Description:  The snprintf_s function is equivalent to the snprintf function except for the Parameter:
253      * destMax/count and the explicit runtime-constraints violation
254      * Parameter: strDest -  produce output according to a format ,write to the character string strDest
255      * Parameter: destMax - The maximum length of destination buffer(including the terminating null  byte ('\0'))
256      * Parameter: count - do not write more than count bytes to strDest(not including the terminating null  byte ('\0'))
257      * Parameter: format - fromat string
258      * Return:    the number of characters printed(not including the terminating null byte ('\0')),
259      * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
260      */
261     SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
262                                ...) SECUREC_ATTRIBUTE(4, 5);
263 #endif
264 
265 #if SECUREC_SNPRINTF_TRUNCATED
266     /*
267      * Description:  The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except
268      * no count Parameter:  and Return: value
269      * Parameter: strDest -  produce output according to a format ,write to the character string strDest
270      * Parameter: destMax - The maximum length of destination buffer(including the terminating null  byte ('\0'))
271      * Parameter: format - fromat string
272      * Parameter: argList - instead of  a variable  number of arguments
273      * Return:    the number of characters printed(not including the terminating null byte ('\0')),
274      * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
275      */
276     SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
277                                           va_list argList) SECUREC_ATTRIBUTE(3, 0);
278 
279     /*
280      * Description:  The snprintf_truncated_s function is equivalent to the snprintf_2 function except
281      * no count Parameter:  and Return: value
282      * Parameter: strDest -  produce output according to a format ,write to the character string strDest
283      * Parameter: destMax - The maximum length of destination buffer(including the terminating null  byte ('\0'))
284      * Parameter: format - fromat string
285      * Return:    the number of characters printed(not including the terminating null byte ('\0')),
286      * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
287      */
288     SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax,
289                                          const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
290 #endif
291 
292 #if SECUREC_ENABLE_SCANF
293     /*
294      * Description:  The scanf_s function is equivalent to fscanf_s with the argument stdin
295      * interposed before the arguments to scanf_s
296      * Parameter: format - fromat string
297      * Return:   the number of input items assigned, If an error occurred Return: -1.
298      */
299     SECUREC_API int scanf_s(const char *format, ...);
300 #endif
301 
302 #if SECUREC_ENABLE_VSCANF
303     /*
304      * Description:  The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList
305      * Parameter: format - fromat string
306      * Parameter: argList - instead of  a variable  number of arguments
307      * Return:    the number of input items assigned, If an error occurred Return: -1.
308      */
309     SECUREC_API int vscanf_s(const char *format, va_list argList);
310 #endif
311 
312 #if SECUREC_ENABLE_SSCANF
313     /*
314      * Description:  The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a
315      * string (specified by the argument buffer) rather than from a stream
316      * Parameter: buffer -  read character from  buffer
317      * Parameter: format - fromat string
318      * Return:    the number of input items assigned, If an error occurred Return: -1.
319      */
320     SECUREC_API int sscanf_s(const char *buffer, const char *format, ...);
321 #endif
322 
323 #if SECUREC_ENABLE_VSSCANF
324     /*
325      * Description:  The vsscanf_s function is equivalent to sscanf_s, with the variable argument list
326      * replaced by argList
327      * Parameter: buffer -  read character from  buffer
328      * Parameter: format - fromat string
329      * Parameter: argList - instead of  a variable  number of arguments
330      * Return:    the number of input items assigned, If an error occurred Return: -1.
331      */
332     SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList);
333 #endif
334 
335 #if SECUREC_ENABLE_FSCANF
336     /*
337      * Description:  The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers
338      * apply to a pair of arguments (unless assignment suppression is indicated by a*)
339      * Parameter: stream - stdio file stream
340      * Parameter: format - fromat string
341      * Return:    the number of input items assigned, If an error occurred Return: -1.
342      */
343     SECUREC_API int fscanf_s(FILE *stream, const char *format, ...);
344 #endif
345 
346 #if SECUREC_ENABLE_VFSCANF
347     /*
348      * Description:  The vfscanf_s function is equivalent to fscanf_s, with the variable argument list
349      * replaced by argList
350      * Parameter: stream - stdio file stream
351      * Parameter: format - fromat string
352      * Parameter: argList - instead of  a variable  number of arguments
353      * Return:    the number of input items assigned, If an error occurred Return: -1.
354      */
355     SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList);
356 #endif
357 
358 #if SECUREC_ENABLE_STRTOK
359     /*
360      * Description:  The strtok_s function parses a string into a sequence of strToken,
361      * replace all characters in strToken string that match to strDelimit set with 0.
362      * On the first call to strtok_s the string to be parsed should be specified in strToken.
363      * In each subsequent call that should parse the same string, strToken should be NULL
364      * Parameter: strToken - the string to be delimited
365      * Parameter: strDelimit -specifies a set of characters that delimit the tokens in the parsed string
366      * Parameter: context -is a pointer to a char * variable that is used internally by strtok_s function
367      * Return:  On the first call returns the address of the first non \0 character, otherwise NULL is returned.
368      * In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
369      * return NULL if the *context string length is equal 0, otherwise return *context.
370      */
371     SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context);
372 #endif
373 
374 #if SECUREC_ENABLE_GETS && SECUREC_IN_KERNEL == 0
375     /*
376      * Description: The gets_s function reads at most one less than the number of characters specified
377      * by destMax from the stream pointed to by stdin, into the array pointed to by buffer
378      * Parameter: buffer - destination  address
379      * Parameter: destMax -The maximum length of destination buffer(including the terminating null character)
380      * Return:    buffer if there was no runtime-constraint violation,If an error occurred Return: NULL.
381      */
382     SECUREC_API char *gets_s(char *buffer, size_t destMax);
383 #endif
384 
385 
386 #if SECUREC_ENABLE_WCHAR_FUNC
387 #if SECUREC_ENABLE_MEMCPY
388     /*
389      * Description: The wmemcpy_s function copies n successive wide characters from the object pointed to
390      * by src into the object pointed to by dest.
391      * Parameter: dest - destination  address
392      * Parameter: destMax -The maximum length of destination buffer
393      * Parameter: src -source  address
394      * Parameter: count -copies count wide characters from the  src
395      * Return:    EOK if there was no runtime-constraint violation
396      */
397     SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
398 #endif
399 
400 #if SECUREC_ENABLE_MEMMOVE
401     /*
402      * Description: The wmemmove_s function copies n successive wide characters from the object
403      * pointed to by src into the object pointed to by dest.
404      * Parameter: dest - destination  address
405      * Parameter: destMax -The maximum length of destination buffer
406      * Parameter: src -source  address
407      * Parameter: count -copies count wide characters from the  src
408      * Return:    EOK if there was no runtime-constraint violation
409      */
410     SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
411 #endif
412 
413 #if SECUREC_ENABLE_STRCPY
414     /*
415      * Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating
416      * null wide character) into the array pointed to by strDest
417      * Parameter: strDest - destination  address
418      * Parameter: destMax -The maximum length of destination buffer
419      * Parameter: strSrc -source  address
420      * Return:    EOK if there was no runtime-constraint violation
421      */
422     SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
423 #endif
424 
425 #if SECUREC_ENABLE_STRNCPY
426     /*
427      * Description: The wcsncpy_s function copies not more than n successive wide characters (not including the
428      * terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest
429      * Parameter: strDest - destination  address
430      * Parameter: destMax -The maximum length of destination buffer(including the terminating wide character)
431      * Parameter: strSrc -source  address
432      * Parameter: count -copies count wide characters from the  src
433      * Return:    EOK if there was no runtime-constraint violation
434      */
435     SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
436 #endif
437 
438 #if SECUREC_ENABLE_STRCAT
439     /*
440      * Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the
441      * terminating null wide character) to the end of the wide string pointed to by strDest
442      * Parameter: strDest - destination  address
443      * Parameter: destMax -The maximum length of destination buffer(including the terminating wide character)
444      * Parameter: strSrc -source  address
445      * Return:    EOK if there was no runtime-constraint violation
446      */
447     SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
448 #endif
449 
450 #if SECUREC_ENABLE_STRNCAT
451     /*
452      * Description: The wcsncat_s function appends not more than n successive wide characters (not including the
453      * terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to
454      * by strDest.
455      * Parameter: strDest - destination  address
456      * Parameter: destMax -The maximum length of destination buffer(including the terminating wide character)
457      * Parameter: strSrc -source  address
458      * Parameter: count -copies count wide characters from the  src
459      * Return:    EOK if there was no runtime-constraint violation
460      */
461     SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
462 #endif
463 
464 #if SECUREC_ENABLE_STRTOK
465     /*
466      * Description:  The  wcstok_s  function  is  the  wide-character  equivalent  of the strtok_s function
467      * Parameter: strToken - the string to be delimited
468      * Parameter: strDelimit -specifies a set of characters that delimit the tokens in the parsed string
469      * Parameter: context -is a pointer to a char * variable that is used internally by strtok_s function
470      * Return:    a pointer to the first character of a token, or a null pointer if there is no token
471      * or there is a runtime-constraint violation.
472      */
473     SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context);
474 #endif
475 
476 #if SECUREC_ENABLE_VSPRINTF
477     /*
478      * Description:  The  vswprintf_s  function  is  the  wide-character  equivalent  of the vsprintf_s function
479      * Parameter: strDest -  produce output according to a format ,write to the character string strDest
480      * Parameter: destMax - The maximum length of destination buffer(including the terminating null )
481      * Parameter: format - fromat string
482      * Parameter: argList - instead of  a variable  number of arguments
483      * Return:    the number of characters printed(not including the terminating null wide characte),
484      * If an error occurred Return: -1.
485      */
486     SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList);
487 #endif
488 
489 #if SECUREC_ENABLE_SPRINTF
490 
491     /*
492      * Description:  The  swprintf_s  function  is  the  wide-character  equivalent  of the sprintf_s function
493      * Parameter: strDest -  produce output according to a format ,write to the character string strDest
494      * Parameter: destMax - The maximum length of destination buffer(including the terminating null )
495      * Parameter: format - fromat string
496      * Return:    the number of characters printed(not including the terminating null wide characte),
497      * If an error occurred Return: -1.
498      */
499     SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...);
500 #endif
501 
502 #if SECUREC_ENABLE_FSCANF
503     /*
504      * Description:  The  fwscanf_s  function  is  the  wide-character  equivalent  of the fscanf_s function
505      * Parameter: stream - stdio file stream
506      * Parameter: format - fromat string
507      * Return:    the number of input items assigned, If an error occurred Return: -1.
508      */
509     SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...);
510 #endif
511 
512 #if SECUREC_ENABLE_VFSCANF
513     /*
514      * Description:  The  vfwscanf_s  function  is  the  wide-character  equivalent  of the vfscanf_s function
515      * Parameter: stream - stdio file stream
516      * Parameter: format - fromat string
517      * Parameter: argList - instead of  a variable  number of arguments
518      * Return:    the number of input items assigned, If an error occurred Return: -1.
519      */
520     SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList);
521 #endif
522 
523 #if SECUREC_ENABLE_SCANF
524     /*
525      * Description:  The  wscanf_s  function  is  the  wide-character  equivalent  of the scanf_s function
526      * Parameter: format - fromat string
527      * Return:    the number of input items assigned, If an error occurred Return: -1.
528      */
529     SECUREC_API int wscanf_s(const wchar_t *format, ...);
530 #endif
531 
532 #if SECUREC_ENABLE_VSCANF
533     /*
534      * Description:  The  vwscanf_s  function  is  the  wide-character  equivalent  of the vscanf_s function
535      * Parameter: format - fromat string
536      * Parameter: argList - instead of  a variable  number of arguments
537      * Return:    the number of input items assigned, If an error occurred Return: -1.
538      */
539     SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList);
540 #endif
541 
542 #if SECUREC_ENABLE_SSCANF
543     /*
544      * Description:  The  swscanf_s  function  is  the  wide-character  equivalent  of the sscanf_s function
545      * Parameter: buffer -  read character from  buffer
546      * Parameter: format - fromat string
547      * Return:    the number of input items assigned, If an error occurred Return: -1.
548      */
549     SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...);
550 #endif
551 
552 #if SECUREC_ENABLE_VSSCANF
553     /*
554      * Description:  The  vswscanf_s  function  is  the  wide-character  equivalent  of the vsscanf_s function
555      * Parameter: buffer -  read character from  buffer
556      * Parameter: format - fromat string
557      * Parameter: argList - instead of  a variable  number of arguments
558      * Return:    the number of input items assigned, If an error occurred Return: -1.
559      */
560     SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList);
561 #endif
562 #endif /* SECUREC_ENABLE_WCHAR_FUNC */
563 #endif
564 
565     /* those functions are used by macro ,must declare hare , also for  without function declaration warning */
566     extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count);
567     extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc);
568 
569 #if SECUREC_WITH_PERFORMANCE_ADDONS
570     /* those functions are used by macro */
571     extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count);
572     extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count);
573     extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count);
574     extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count);
575 
576 /* strcpy_sp is a macro, NOT a function in performance optimization mode. */
577 #define strcpy_sp(dest, destMax, src)  ((__builtin_constant_p((destMax)) && \
578     __builtin_constant_p((src))) ?  \
579     SECUREC_STRCPY_SM((dest), (destMax), (src)) : \
580     strcpy_s((dest), (destMax), (src)))
581 
582 /* strncpy_sp is a macro, NOT a function in performance optimization mode. */
583 #define strncpy_sp(dest, destMax, src, count)  ((__builtin_constant_p((count)) && \
584     __builtin_constant_p((destMax)) && \
585     __builtin_constant_p((src))) ?  \
586     SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \
587     strncpy_s((dest), (destMax), (src), (count)))
588 
589 /* strcat_sp is a macro, NOT a function in performance optimization mode. */
590 #define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
591     __builtin_constant_p((src))) ?  \
592     SECUREC_STRCAT_SM((dest), (destMax), (src)) : \
593     strcat_s((dest), (destMax), (src)))
594 
595 /* strncat_sp is a macro, NOT a function in performance optimization mode. */
596 #define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) &&  \
597     __builtin_constant_p((destMax)) && \
598     __builtin_constant_p((src))) ?  \
599     SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \
600     strncat_s((dest), (destMax), (src), (count)))
601 
602 /* memcpy_sp is a macro, NOT a function in performance optimization mode. */
603 #define memcpy_sp(dest, destMax, src, count)  (__builtin_constant_p((count)) ? \
604     (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \
605     (__builtin_constant_p((destMax)) ? \
606     (((size_t)(destMax) > 0 && \
607     (((unsigned long long)(destMax) & \
608     (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
609     memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \
610     memcpy_sOptAsm((dest), (destMax), (src), (count))))
611 
612 /* memset_sp is a macro, NOT a function in performance optimization mode. */
613 #define memset_sp(dest, destMax, c, count)  (__builtin_constant_p((count)) ? \
614     (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \
615     (__builtin_constant_p((destMax)) ? \
616     (((size_t)(destMax) > 0 && \
617     (((unsigned long long)(destMax) & \
618     (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
619     memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \
620     memset_sOptAsm((dest), (destMax), (c), (count))))
621 #else
622 #define strcpy_sp   strcpy_s
623 #define strncpy_sp  strncpy_s
624 #define strcat_sp   strcat_s
625 #define strncat_sp  strncat_s
626 #define memcpy_sp   memcpy_s
627 #define memset_sp   memset_s
628 #endif
629 
630 #ifdef __cplusplus
631 }
632 #endif /* __cplusplus */
633 #endif /* __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 */
634 
635