1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 17 #define __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 18 19 #include "securectype.h" 20 #include <cstdarg> 21 22 #ifndef SECUREC_HAVE_ERRNO_H 23 #if SECUREC_IN_KERNEL 24 #define SECUREC_HAVE_ERRNO_H 0 25 #else 26 #define SECUREC_HAVE_ERRNO_H 1 27 #endif 28 #endif 29 30 /* EINVAL ERANGE may defined in errno.h */ 31 #if SECUREC_HAVE_ERRNO_H 32 #include <cerrno> 33 #endif 34 35 /* define error code */ 36 #if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \ 37 (defined(__STDC_WANT_LIB_EXT1__) && (__STDC_WANT_LIB_EXT1__ == 0)) 38 #ifndef SECUREC_DEFINED_ERRNO_TYPE 39 #define SECUREC_DEFINED_ERRNO_TYPE 40 /* just check whether macrodefinition exists. */ 41 #ifndef errno_t 42 typedef int errno_t; 43 #endif 44 #endif 45 #endif 46 47 /* success */ 48 #ifndef EOK 49 #define EOK 0 50 #endif 51 52 #ifndef EINVAL 53 /* The src buffer is not correct and destination buffer cant not be reset */ 54 #define EINVAL 22 55 #endif 56 57 #ifndef EINVAL_AND_RESET 58 /* Once the error is detected, the dest buffer must be reseted! */ 59 #define EINVAL_AND_RESET (22 | 128) 60 #endif 61 62 #ifndef ERANGE 63 /* The destination buffer is not long enough and destination buffer can not be reset */ 64 #define ERANGE 34 65 #endif 66 67 #ifndef ERANGE_AND_RESET 68 /* Once the error is detected, the dest buffer must be reseted! */ 69 #define ERANGE_AND_RESET (34 | 128) 70 #endif 71 72 #ifndef EOVERLAP_AND_RESET 73 /* Once the buffer overlap is detected, the dest buffer must be reseted! */ 74 #define EOVERLAP_AND_RESET (54 | 128) 75 #endif 76 77 /* if you need export the function of this library in Win32 dll, use __declspec(dllexport) */ 78 #ifndef SECUREC_API 79 #if defined(SECUREC_DLL_EXPORT) 80 #define SECUREC_API __declspec(dllexport) 81 #elif defined(SECUREC_DLL_IMPORT) 82 #define SECUREC_API __declspec(dllimport) 83 #else 84 /* Standardized function declaration . If a security function is declared in the your code, 85 * it may cause a compilation alarm,Please delete the security function you declared 86 * Adding extern under windows will cause the system to have inline functions to expand, 87 * so do not add the extern in default 88 */ 89 #if defined(_MSC_VER) 90 #define SECUREC_API 91 #else 92 #define SECUREC_API extern 93 #endif 94 #endif 95 #endif 96 97 #ifdef __cplusplus 98 extern "C" { 99 #endif 100 /* 101 * Description: The GetHwSecureCVersion function get SecureC Version string and version number. 102 * Parameter: verNumber - to store version number 103 * Return: version string 104 */ 105 SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber); 106 107 #if SECUREC_ENABLE_MEMSET 108 /* 109 * Description: The memset_s function copies the value of c (converted to an unsigned char) into each of 110 * the first count characters of the object pointed to by dest. 111 * Parameter: dest - destination address 112 * Parameter: destMax -The maximum length of destination buffer 113 * Parameter: c - the value to be copied 114 * Parameter: count -copies fisrt count characters of dest 115 * Return: EOK if there was no runtime-constraint violation 116 */ 117 SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count); 118 #endif 119 120 #ifndef SECUREC_ONLY_DECLARE_MEMSET 121 #define SECUREC_ONLY_DECLARE_MEMSET 0 122 #endif 123 124 #if SECUREC_ONLY_DECLARE_MEMSET == 0 125 126 #if SECUREC_ENABLE_MEMMOVE 127 /* 128 * Description: The memmove_s function copies n characters from the object pointed to by src 129 * into the object pointed to by dest. 130 * Parameter: dest - destination address 131 * Parameter: destMax -The maximum length of destination buffer 132 * Parameter: src -source address 133 * Parameter: count -copies count wide characters from the src 134 * Return: EOK if there was no runtime-constraint violation 135 */ 136 SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count); 137 #endif 138 139 #if SECUREC_ENABLE_MEMCPY 140 /* 141 * Description: The memcpy_s function copies n characters from the object pointed to 142 * by src into the object pointed to by dest. 143 * Parameter: dest - destination address 144 * Parameter: destMax -The maximum length of destination buffer 145 * Parameter: src -source address 146 * Parameter: count -copies count characters from the src 147 * Return: EOK if there was no runtime-constraint violation 148 */ 149 SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count); 150 #endif 151 152 #if SECUREC_ENABLE_STRCPY 153 /* 154 * Description: The strcpy_s function copies the string pointed to by strSrc (including 155 * the terminating null character) into the array pointed to by strDest 156 * Parameter: strDest - destination address 157 * Parameter: destMax -The maximum length of destination buffer(including the terminating null character) 158 * Parameter: strSrc -source address 159 * Return: EOK if there was no runtime-constraint violation 160 */ 161 SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc); 162 #endif 163 164 #if SECUREC_ENABLE_STRNCPY 165 /* 166 * Description: The strncpy_s function copies not more than n successive characters (not including 167 * the terminating null character) 168 * from the array pointed to by strSrc to the array pointed to by strDest 169 * Parameter: strDest - destination address 170 * Parameter: destMax -The maximum length of destination buffer(including the terminating null character) 171 * Parameter: strSrc -source address 172 * Parameter: count -copies count characters from the src 173 * Return: EOK if there was no runtime-constraint violation 174 */ 175 SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count); 176 #endif 177 178 #if SECUREC_ENABLE_STRCAT 179 /* 180 * Description: The strcat_s function appends a copy of the string pointed to by strSrc (including 181 * the terminating null character) 182 * 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 the Parameter: 236 * 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 the Parameter: 252 * 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 == 0 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 385 #if SECUREC_ENABLE_WCHAR_FUNC 386 #if SECUREC_ENABLE_MEMCPY 387 /* 388 * Description: The wmemcpy_s function copies n successive wide characters from the object pointed to 389 * by src into the object pointed to by dest. 390 * Parameter: dest - destination address 391 * Parameter: destMax -The maximum length of destination buffer 392 * Parameter: src -source address 393 * Parameter: count -copies count wide characters from the src 394 * Return: EOK if there was no runtime-constraint violation 395 */ 396 SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); 397 #endif 398 399 #if SECUREC_ENABLE_MEMMOVE 400 /* 401 * Description: The wmemmove_s function copies n successive wide characters from the object 402 * pointed to by src into the object pointed to by dest. 403 * Parameter: dest - destination address 404 * Parameter: destMax -The maximum length of destination buffer 405 * Parameter: src -source address 406 * Parameter: count -copies count wide characters from the src 407 * Return: EOK if there was no runtime-constraint violation 408 */ 409 SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); 410 #endif 411 412 #if SECUREC_ENABLE_STRCPY 413 /* 414 * Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating 415 * null wide character) into the array pointed to by strDest 416 * Parameter: strDest - destination address 417 * Parameter: destMax -The maximum length of destination buffer 418 * Parameter: strSrc -source address 419 * Return: EOK if there was no runtime-constraint violation 420 */ 421 SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); 422 #endif 423 424 #if SECUREC_ENABLE_STRNCPY 425 /* 426 * Description: The wcsncpy_s function copies not more than n successive wide characters (not including the 427 * terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest 428 * Parameter: strDest - destination address 429 * Parameter: destMax -The maximum length of destination buffer(including the terminating wide character) 430 * Parameter: strSrc -source address 431 * Parameter: count -copies count wide characters from the src 432 * Return: EOK if there was no runtime-constraint violation 433 */ 434 SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); 435 #endif 436 437 #if SECUREC_ENABLE_STRCAT 438 /* 439 * Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the 440 * terminating null wide character) to the end of the wide string pointed to by strDest 441 * Parameter: strDest - destination address 442 * Parameter: destMax -The maximum length of destination buffer(including the terminating wide character) 443 * Parameter: strSrc -source address 444 * Return: EOK if there was no runtime-constraint violation 445 */ 446 SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); 447 #endif 448 449 #if SECUREC_ENABLE_STRNCAT 450 /* 451 * Description: The wcsncat_s function appends not more than n successive wide characters (not including the 452 * terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to 453 * by strDest. 454 * Parameter: strDest - destination address 455 * Parameter: destMax -The maximum length of destination buffer(including the terminating wide character) 456 * Parameter: strSrc -source address 457 * Parameter: count -copies count wide characters from the src 458 * Return: EOK if there was no runtime-constraint violation 459 */ 460 SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); 461 #endif 462 463 #if SECUREC_ENABLE_STRTOK 464 /* 465 * Description: The wcstok_s function is the wide-character equivalent of the strtok_s function 466 * Parameter: strToken - the string to be delimited 467 * Parameter: strDelimit -specifies a set of characters that delimit the tokens in the parsed string 468 * Parameter: context -is a pointer to a char * variable that is used internally by strtok_s function 469 * Return: a pointer to the first character of a token, or a null pointer if there is no token 470 * or there is a runtime-constraint violation. 471 */ 472 SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context); 473 #endif 474 475 #if SECUREC_ENABLE_VSPRINTF 476 /* 477 * Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function 478 * Parameter: strDest - produce output according to a format ,write to the character string strDest 479 * Parameter: destMax - The maximum length of destination buffer(including the terminating null ) 480 * Parameter: format - fromat string 481 * Parameter: argList - instead of a variable number of arguments 482 * Return: the number of characters printed(not including the terminating null wide characte), 483 * If an error occurred Return: -1. 484 */ 485 SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList); 486 #endif 487 488 #if SECUREC_ENABLE_SPRINTF 489 490 /* 491 * Description: The swprintf_s function is the wide-character equivalent of the sprintf_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 - fromat string 495 * Return: the number of characters printed(not including the terminating null wide characte), 496 * If an error occurred Return: -1. 497 */ 498 SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...); 499 #endif 500 501 #if SECUREC_ENABLE_FSCANF 502 /* 503 * Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function 504 * Parameter: stream - stdio file stream 505 * Parameter: format - fromat string 506 * Return: the number of input items assigned, If an error occurred Return: -1. 507 */ 508 SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...); 509 #endif 510 511 #if SECUREC_ENABLE_VFSCANF 512 /* 513 * Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function 514 * Parameter: stream - stdio file stream 515 * Parameter: format - fromat string 516 * Parameter: argList - instead of a variable number of arguments 517 * Return: the number of input items assigned, If an error occurred Return: -1. 518 */ 519 SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList); 520 #endif 521 522 #if SECUREC_ENABLE_SCANF 523 /* 524 * Description: The wscanf_s function is the wide-character equivalent of the scanf_s function 525 * Parameter: format - fromat string 526 * Return: the number of input items assigned, If an error occurred Return: -1. 527 */ 528 SECUREC_API int wscanf_s(const wchar_t *format, ...); 529 #endif 530 531 #if SECUREC_ENABLE_VSCANF 532 /* 533 * Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function 534 * Parameter: format - fromat string 535 * Parameter: argList - instead of a variable number of arguments 536 * Return: the number of input items assigned, If an error occurred Return: -1. 537 */ 538 SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList); 539 #endif 540 541 #if SECUREC_ENABLE_SSCANF 542 /* 543 * Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function 544 * Parameter: buffer - read character from buffer 545 * Parameter: format - fromat string 546 * Return: the number of input items assigned, If an error occurred Return: -1. 547 */ 548 SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...); 549 #endif 550 551 #if SECUREC_ENABLE_VSSCANF 552 /* 553 * Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function 554 * Parameter: buffer - read character from buffer 555 * Parameter: format - fromat string 556 * Parameter: argList - instead of a variable number of arguments 557 * Return: the number of input items assigned, If an error occurred Return: -1. 558 */ 559 SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList); 560 #endif 561 #endif /* SECUREC_ENABLE_WCHAR_FUNC */ 562 #endif 563 564 /* those functions are used by macro ,must declare hare , also for without function declaration warning */ 565 extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count); 566 extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc); 567 568 #if SECUREC_WITH_PERFORMANCE_ADDONS 569 /* those functions are used by macro */ 570 extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count); 571 extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count); 572 extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count); 573 extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count); 574 575 /* strcpy_sp is a macro, NOT a function in performance optimization mode. */ 576 #define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ 577 __builtin_constant_p((src))) ? \ 578 SECUREC_STRCPY_SM((dest), (destMax), (src)) : \ 579 strcpy_s((dest), (destMax), (src))) 580 581 /* strncpy_sp is a macro, NOT a function in performance optimization mode. */ 582 #define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ 583 __builtin_constant_p((destMax)) && \ 584 __builtin_constant_p((src))) ? \ 585 SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \ 586 strncpy_s((dest), (destMax), (src), (count))) 587 588 /* strcat_sp is a macro, NOT a function in performance optimization mode. */ 589 #define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ 590 __builtin_constant_p((src))) ? \ 591 SECUREC_STRCAT_SM((dest), (destMax), (src)) : \ 592 strcat_s((dest), (destMax), (src))) 593 594 /* strncat_sp is a macro, NOT a function in performance optimization mode. */ 595 #define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ 596 __builtin_constant_p((destMax)) && \ 597 __builtin_constant_p((src))) ? \ 598 SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \ 599 strncat_s((dest), (destMax), (src), (count))) 600 601 /* memcpy_sp is a macro, NOT a function in performance optimization mode. */ 602 #define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \ 603 (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \ 604 (__builtin_constant_p((destMax)) ? \ 605 (((size_t)(destMax) > 0 && \ 606 (((unsigned long long)(destMax) & \ 607 (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ 608 memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \ 609 memcpy_sOptAsm((dest), (destMax), (src), (count)))) 610 611 /* memset_sp is a macro, NOT a function in performance optimization mode. */ 612 #define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \ 613 (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \ 614 (__builtin_constant_p((destMax)) ? \ 615 (((size_t)(destMax) > 0 && \ 616 (((unsigned long long)(destMax) & \ 617 (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ 618 memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \ 619 memset_sOptAsm((dest), (destMax), (c), (count)))) 620 #else 621 #define strcpy_sp strcpy_s 622 #define strncpy_sp strncpy_s 623 #define strcat_sp strcat_s 624 #define strncat_sp strncat_s 625 #define memcpy_sp memcpy_s 626 #define memset_sp memset_s 627 #endif 628 629 #ifdef __cplusplus 630 } 631 #endif /* __cplusplus */ 632 #endif /* __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 */ 633 634