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