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