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