1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Broadcom Secure Standard Library. 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Copyright (C) 2020, Broadcom. 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * Unless you and Broadcom execute a separate written software license 7*4882a593Smuzhiyun * agreement governing use of this software, this software is licensed to you 8*4882a593Smuzhiyun * under the terms of the GNU General Public License version 2 (the "GPL"), 9*4882a593Smuzhiyun * available at http://www.broadcom.com/licenses/GPLv2.php, with the 10*4882a593Smuzhiyun * following added to such license: 11*4882a593Smuzhiyun * 12*4882a593Smuzhiyun * As a special exception, the copyright holders of this software give you 13*4882a593Smuzhiyun * permission to link this software with independent modules, and to copy and 14*4882a593Smuzhiyun * distribute the resulting executable under terms of your choice, provided that 15*4882a593Smuzhiyun * you also meet, for each linked independent module, the terms and conditions of 16*4882a593Smuzhiyun * the license of that module. An independent module is a module which is not 17*4882a593Smuzhiyun * derived from this software. The special exception does not apply to any 18*4882a593Smuzhiyun * modifications of the software. 19*4882a593Smuzhiyun * 20*4882a593Smuzhiyun * 21*4882a593Smuzhiyun * <<Broadcom-WL-IPTag/Dual:>> 22*4882a593Smuzhiyun */ 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun #ifndef _bcmstdlib_s_h_ 25*4882a593Smuzhiyun #define _bcmstdlib_s_h_ 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun #ifndef BWL_NO_INTERNAL_STDLIB_S_SUPPORT 28*4882a593Smuzhiyun #if !defined(__STDC_WANT_SECURE_LIB__) && \ 29*4882a593Smuzhiyun !(defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) 30*4882a593Smuzhiyun extern int memmove_s(void *dest, size_t destsz, const void *src, size_t n); 31*4882a593Smuzhiyun extern int memcpy_s(void *dest, size_t destsz, const void *src, size_t n); 32*4882a593Smuzhiyun extern int memset_s(void *dest, size_t destsz, int c, size_t n); 33*4882a593Smuzhiyun #endif /* !__STDC_WANT_SECURE_LIB__ && !(__STDC_LIB_EXT1__ && __STDC_WANT_LIB_EXT1__) */ 34*4882a593Smuzhiyun #if !defined(FREEBSD) && !defined(MACOSX) && !defined(BCM_USE_PLATFORM_STRLCPY) 35*4882a593Smuzhiyun extern size_t strlcpy(char *dest, const char *src, size_t size); 36*4882a593Smuzhiyun #endif /* !defined(FREEBSD) && !defined(MACOSX) && !defined(BCM_USE_PLATFORM_STRLCPY) */ 37*4882a593Smuzhiyun extern size_t strlcat_s(char *dest, const char *src, size_t size); 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun /* Remap xxx_s() APIs to use compiler builtin functions for C standard library functions. 40*4882a593Smuzhiyun * The intent is to identify buffer overflow at compile-time for the safe stdlib APIs when 41*4882a593Smuzhiyun * the user-specified destination buffer-size is incorrect. 42*4882a593Smuzhiyun * 43*4882a593Smuzhiyun * This is only intended as a compile-time test, and should be used by compile-only targets. 44*4882a593Smuzhiyun */ 45*4882a593Smuzhiyun #if defined(BCM_STDLIB_S_BUILTINS_TEST) 46*4882a593Smuzhiyun #define memmove_s(dest, destsz, src, n) ((void)(destsz), (int)__builtin_memmove((dest), (src), (n))) 47*4882a593Smuzhiyun #define memcpy_s(dest, destsz, src, n) ((void)(destsz), (int)__builtin_memcpy((dest), (src), (n))) 48*4882a593Smuzhiyun #define memset_s(dest, destsz, c, n) ((void)(destsz), (int)__builtin_memset((dest), (c), (n))) 49*4882a593Smuzhiyun #define strlcpy(dest, src, size) ((void)(size), (size_t)__builtin_strcpy((dest), (src))) 50*4882a593Smuzhiyun #define strlcat_s(dest, src, size) ((void)(size), (size_t)__builtin_strcat((dest), (src))) 51*4882a593Smuzhiyun #endif /* BCM_STDLIB_S_BUILTINS_TEST */ 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun #endif /* !BWL_NO_INTERNAL_STDLIB_S_SUPPORT */ 54*4882a593Smuzhiyun #endif /* _bcmstdlib_s_h_ */ 55