xref: /xnu-8796.141.3/osfmk/libsa/string.h (revision 1b191cb58250d0705d8a51287127505aa4bc0789)
1*1b191cb5SApple OSS Distributions /*
2*1b191cb5SApple OSS Distributions  * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
3*1b191cb5SApple OSS Distributions  *
4*1b191cb5SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*1b191cb5SApple OSS Distributions  *
6*1b191cb5SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*1b191cb5SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*1b191cb5SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*1b191cb5SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*1b191cb5SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*1b191cb5SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*1b191cb5SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*1b191cb5SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*1b191cb5SApple OSS Distributions  *
15*1b191cb5SApple OSS Distributions  * Please obtain a copy of the License at
16*1b191cb5SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*1b191cb5SApple OSS Distributions  *
18*1b191cb5SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*1b191cb5SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*1b191cb5SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*1b191cb5SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*1b191cb5SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*1b191cb5SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*1b191cb5SApple OSS Distributions  * limitations under the License.
25*1b191cb5SApple OSS Distributions  *
26*1b191cb5SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*1b191cb5SApple OSS Distributions  */
28*1b191cb5SApple OSS Distributions /*
29*1b191cb5SApple OSS Distributions  * NOTICE: This file was modified by McAfee Research in 2004 to introduce
30*1b191cb5SApple OSS Distributions  * support for mandatory and extensible security protections.  This notice
31*1b191cb5SApple OSS Distributions  * is included in support of clause 2.2 (b) of the Apple Public License,
32*1b191cb5SApple OSS Distributions  * Version 2.0.
33*1b191cb5SApple OSS Distributions  */
34*1b191cb5SApple OSS Distributions /*
35*1b191cb5SApple OSS Distributions  * HISTORY
36*1b191cb5SApple OSS Distributions  * @OSF_COPYRIGHT@
37*1b191cb5SApple OSS Distributions  */
38*1b191cb5SApple OSS Distributions #ifndef _STRING_H_
39*1b191cb5SApple OSS Distributions #define _STRING_H_      1
40*1b191cb5SApple OSS Distributions 
41*1b191cb5SApple OSS Distributions #ifdef MACH_KERNEL_PRIVATE
42*1b191cb5SApple OSS Distributions #include <types.h>
43*1b191cb5SApple OSS Distributions #else
44*1b191cb5SApple OSS Distributions #include <sys/types.h>
45*1b191cb5SApple OSS Distributions #endif
46*1b191cb5SApple OSS Distributions #include <sys/cdefs.h>
47*1b191cb5SApple OSS Distributions 
48*1b191cb5SApple OSS Distributions __BEGIN_DECLS
49*1b191cb5SApple OSS Distributions 
50*1b191cb5SApple OSS Distributions #ifndef NULL
51*1b191cb5SApple OSS Distributions #if defined (__cplusplus)
52*1b191cb5SApple OSS Distributions #if __cplusplus >= 201103L
53*1b191cb5SApple OSS Distributions #define NULL nullptr
54*1b191cb5SApple OSS Distributions #else
55*1b191cb5SApple OSS Distributions #define NULL 0
56*1b191cb5SApple OSS Distributions #endif
57*1b191cb5SApple OSS Distributions #else
58*1b191cb5SApple OSS Distributions #define NULL ((void *)0)
59*1b191cb5SApple OSS Distributions #endif
60*1b191cb5SApple OSS Distributions #endif
61*1b191cb5SApple OSS Distributions 
62*1b191cb5SApple OSS Distributions /*
63*1b191cb5SApple OSS Distributions  * Memory functions
64*1b191cb5SApple OSS Distributions  *
65*1b191cb5SApple OSS Distributions  *   int bcmp(const void *s1, const void *s2, size_t n);
66*1b191cb5SApple OSS Distributions  *   int memcmp(const void *s1, const void *s2, size_t n);
67*1b191cb5SApple OSS Distributions  *   int timingsafe_bcmp(const void *b1, const void *b2, size_t n);
68*1b191cb5SApple OSS Distributions  *
69*1b191cb5SApple OSS Distributions  *   void bzero(void *dst, size_t n);
70*1b191cb5SApple OSS Distributions  *   void *memset(void *s, int c, size_t n);
71*1b191cb5SApple OSS Distributions  *   int memset_s(void *s __sized_by(smax), size_t smax, int c, size_t n);
72*1b191cb5SApple OSS Distributions  *
73*1b191cb5SApple OSS Distributions  *   void bcopy(const void *src, void *dst, size_t n);
74*1b191cb5SApple OSS Distributions  *   void *memcpy(void *dst, const void *src, size_t n);
75*1b191cb5SApple OSS Distributions  *   void *memove(void *dst, const void *src, size_t n);
76*1b191cb5SApple OSS Distributions  *
77*1b191cb5SApple OSS Distributions  *
78*1b191cb5SApple OSS Distributions  * String functions
79*1b191cb5SApple OSS Distributions  *
80*1b191cb5SApple OSS Distributions  *   size_t strlen(const char *s);
81*1b191cb5SApple OSS Distributions  *   size_t strnlen(const char *s, size_t n);
82*1b191cb5SApple OSS Distributions  *
83*1b191cb5SApple OSS Distributions  *   int strcmp(const char *s1, const char *s2);
84*1b191cb5SApple OSS Distributions  *   int strncmp(const char *s1, const char *s2, size_t n);
85*1b191cb5SApple OSS Distributions  *   int strprefix(const char *s1, const char *s2) __stateful_pure;
86*1b191cb5SApple OSS Distributions  *   int strcasecmp(const char *s1, const char *s2);
87*1b191cb5SApple OSS Distributions  *   int strncasecmp(const char *s1, const char *s2, size_t n);
88*1b191cb5SApple OSS Distributions  *
89*1b191cb5SApple OSS Distributions  *   char *strchr(const char *s, int c);
90*1b191cb5SApple OSS Distributions  *   char *strrchr(const char *s, int c);
91*1b191cb5SApple OSS Distributions  *   char *strnstr(const char *s, const char *find, size_t slen);
92*1b191cb5SApple OSS Distributions  *
93*1b191cb5SApple OSS Distributions  *   size_t strlcpy(char *dst, const char *src, size_t n);
94*1b191cb5SApple OSS Distributions  *   size_t strlcat(char *dst, const char *src, size_t n);
95*1b191cb5SApple OSS Distributions  */
96*1b191cb5SApple OSS Distributions 
97*1b191cb5SApple OSS Distributions 
98*1b191cb5SApple OSS Distributions /*
99*1b191cb5SApple OSS Distributions  * _FORTIFY_SOURCE > 0 will enable checked memory/string functions.
100*1b191cb5SApple OSS Distributions  *
101*1b191cb5SApple OSS Distributions  * _FORTIFY_SOURCE_STRICT will enable stricter checking (optional)
102*1b191cb5SApple OSS Distributions  * for memcpy/memmove/bcopy and will check that copies do not go
103*1b191cb5SApple OSS Distributions  * past the end of a struct member.
104*1b191cb5SApple OSS Distributions  */
105*1b191cb5SApple OSS Distributions #if KASAN
106*1b191cb5SApple OSS Distributions #  define XNU_USE_CHK_BUILTIN(n)        0
107*1b191cb5SApple OSS Distributions #  define XNU_USE_STRING_BUILTIN(n)     0
108*1b191cb5SApple OSS Distributions #elif defined (_FORTIFY_SOURCE) && _FORTIFY_SOURCE == 0
109*1b191cb5SApple OSS Distributions #  define XNU_USE_CHK_BUILTIN(n)        0
110*1b191cb5SApple OSS Distributions #  define XNU_USE_STRING_BUILTIN(n)     __has_builtin(__builtin_##n)
111*1b191cb5SApple OSS Distributions #elif __has_ptrcheck
112*1b191cb5SApple OSS Distributions #  define XNU_USE_CHK_BUILTIN(n)        0
113*1b191cb5SApple OSS Distributions #  define XNU_USE_STRING_BUILTIN(n)     __has_builtin(__builtin_##n)
114*1b191cb5SApple OSS Distributions #elif defined(__cplusplus) && __has_include(<__xnu_libcxx_sentinel.h>)
115*1b191cb5SApple OSS Distributions #  define XNU_USE_CHK_BUILTIN(n)        0
116*1b191cb5SApple OSS Distributions #  define XNU_USE_STRING_BUILTIN(n)     0
117*1b191cb5SApple OSS Distributions #elif XNU_KERNEL_PRIVATE || defined(_FORTIFY_SOURCE_STRICT)
118*1b191cb5SApple OSS Distributions #  define XNU_USE_CHK_BUILTIN(n)        __has_builtin(__builtin___##n##_chk)
119*1b191cb5SApple OSS Distributions #  define XNU_USE_STRING_BUILTIN(n)     __has_builtin(__builtin_##n)
120*1b191cb5SApple OSS Distributions #  define __xnu_bos_default(ptr)        __xnu_bos_strict(ptr)
121*1b191cb5SApple OSS Distributions #else
122*1b191cb5SApple OSS Distributions #  define XNU_USE_CHK_BUILTIN(n)        __has_builtin(__builtin___##n##_chk)
123*1b191cb5SApple OSS Distributions #  define XNU_USE_STRING_BUILTIN(n)     __has_builtin(__builtin_##n)
124*1b191cb5SApple OSS Distributions #  define __xnu_bos_default(ptr)        __xnu_bos_loose(ptr)
125*1b191cb5SApple OSS Distributions #endif
126*1b191cb5SApple OSS Distributions 
127*1b191cb5SApple OSS Distributions #if __has_builtin(__builtin_dynamic_object_size)
128*1b191cb5SApple OSS Distributions #  define __xnu_bos_loose(ptr)          __builtin_dynamic_object_size(ptr, 0)
129*1b191cb5SApple OSS Distributions #  define __xnu_bos_strict(ptr)         __builtin_dynamic_object_size(ptr, 1)
130*1b191cb5SApple OSS Distributions #else
131*1b191cb5SApple OSS Distributions #  define __xnu_bos_loose(ptr)          __builtin_object_size(ptr, 0)
132*1b191cb5SApple OSS Distributions #  define __xnu_bos_strict(ptr)         __builtin_object_size(ptr, 1)
133*1b191cb5SApple OSS Distributions #endif
134*1b191cb5SApple OSS Distributions 
135*1b191cb5SApple OSS Distributions 
136*1b191cb5SApple OSS Distributions #pragma mark memory functions
137*1b191cb5SApple OSS Distributions 
138*1b191cb5SApple OSS Distributions extern int bcmp(const void *s1 __sized_by(n), const void *s2 __sized_by(n), size_t n) __stateful_pure;
139*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(bcmp)
140*1b191cb5SApple OSS Distributions #define bcmp(s1, s2, n)                 __builtin_bcmp(s1, s2, n)
141*1b191cb5SApple OSS Distributions #endif
142*1b191cb5SApple OSS Distributions 
143*1b191cb5SApple OSS Distributions 
144*1b191cb5SApple OSS Distributions extern int memcmp(const void *s1 __sized_by(n), const void *s2 __sized_by(n), size_t n) __stateful_pure;
145*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(memcmp)
146*1b191cb5SApple OSS Distributions #define memcmp(s1, s2, n)               __builtin_memcmp(s1, s2, n)
147*1b191cb5SApple OSS Distributions #endif
148*1b191cb5SApple OSS Distributions 
149*1b191cb5SApple OSS Distributions 
150*1b191cb5SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
151*1b191cb5SApple OSS Distributions /*
152*1b191cb5SApple OSS Distributions  * memcmp_zero_ptr_aligned() checks string s of n bytes contains all zeros.
153*1b191cb5SApple OSS Distributions  * Address and size of the string s must be pointer-aligned.
154*1b191cb5SApple OSS Distributions  * Return 0 if true, 1 otherwise. Also return 0 if n is 0.
155*1b191cb5SApple OSS Distributions  */
156*1b191cb5SApple OSS Distributions extern unsigned long memcmp_zero_ptr_aligned(const void *s __sized_by(n), size_t n) __stateful_pure;
157*1b191cb5SApple OSS Distributions #endif
158*1b191cb5SApple OSS Distributions 
159*1b191cb5SApple OSS Distributions 
160*1b191cb5SApple OSS Distributions extern int timingsafe_bcmp(const void *b1 __sized_by(n), const void *b2 __sized_by(n), size_t n);
161*1b191cb5SApple OSS Distributions 
162*1b191cb5SApple OSS Distributions 
163*1b191cb5SApple OSS Distributions extern void bzero(void *s __sized_by(n), size_t n);
164*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(bzero)
165*1b191cb5SApple OSS Distributions #define bzero(s, n)                     __builtin_bzero(s, n)
166*1b191cb5SApple OSS Distributions #endif
167*1b191cb5SApple OSS Distributions 
168*1b191cb5SApple OSS Distributions 
169*1b191cb5SApple OSS Distributions extern void *memset(void *s __sized_by(n), int c, size_t n);
170*1b191cb5SApple OSS Distributions #if XNU_USE_CHK_BUILTIN(memset) && XNU_KERNEL_PRIVATE /* rdar://103270898&103281379 */
171*1b191cb5SApple OSS Distributions #define memset(s, c, n)                 __builtin___memset_chk(s, c, n, __xnu_bos_default(s))
172*1b191cb5SApple OSS Distributions #elif XNU_USE_STRING_BUILTIN(memset) && XNU_KERNEL_PRIVATE
173*1b191cb5SApple OSS Distributions #define memset(s, c, n)                 __builtin_memset(s, c, n)
174*1b191cb5SApple OSS Distributions #endif
175*1b191cb5SApple OSS Distributions 
176*1b191cb5SApple OSS Distributions 
177*1b191cb5SApple OSS Distributions extern int memset_s(void *s __sized_by(smax), size_t smax, int c, size_t n);
178*1b191cb5SApple OSS Distributions 
179*1b191cb5SApple OSS Distributions 
180*1b191cb5SApple OSS Distributions extern void *memcpy(void *dst __sized_by(n), const void *src __sized_by(n), size_t n);
181*1b191cb5SApple OSS Distributions #if XNU_USE_CHK_BUILTIN(memcpy)
182*1b191cb5SApple OSS Distributions #define memcpy(dst, src, n)             __builtin___memcpy_chk(dst, src, n, __xnu_bos_default(dst))
183*1b191cb5SApple OSS Distributions #define __nochk_memcpy(dst, src, n)     __builtin___memcpy_chk(dst, src, n, __xnu_bos_loose(dst))
184*1b191cb5SApple OSS Distributions #elif XNU_USE_STRING_BUILTIN(memcpy)
185*1b191cb5SApple OSS Distributions #define memcpy(dst, src, n)             __builtin_memcpy(dst, src, n)
186*1b191cb5SApple OSS Distributions #define __nochk_memcpy(dst, src, n)     memcpy(dst, src, n)
187*1b191cb5SApple OSS Distributions #else
188*1b191cb5SApple OSS Distributions #define __nochk_memcpy(dst, src, n)     memcpy(dst, src, n)
189*1b191cb5SApple OSS Distributions #endif
190*1b191cb5SApple OSS Distributions 
191*1b191cb5SApple OSS Distributions 
192*1b191cb5SApple OSS Distributions extern void *memmove(void *dst __sized_by(n), const void *src __sized_by(n), size_t n);
193*1b191cb5SApple OSS Distributions extern void bcopy(const void *src __sized_by(n), void *dst __sized_by(n), size_t n);
194*1b191cb5SApple OSS Distributions #if XNU_USE_CHK_BUILTIN(memmove)
195*1b191cb5SApple OSS Distributions #define memmove(dst, src, n)            __builtin___memmove_chk(dst, src, n, __xnu_bos_default(dst))
196*1b191cb5SApple OSS Distributions #define bcopy(src, dst, n)              __builtin___memmove_chk(dst, src, n, __xnu_bos_default(dst))
197*1b191cb5SApple OSS Distributions #define __nochk_memmove(dst, src, n)    __builtin___memmove_chk(dst, src, n, __xnu_bos_loose(dst))
198*1b191cb5SApple OSS Distributions #define __nochk_bcopy(src, dst, n)      __builtin___memmove_chk(dst, src, n, __xnu_bos_loose(dst))
199*1b191cb5SApple OSS Distributions #elif XNU_USE_STRING_BUILTIN(memmove)
200*1b191cb5SApple OSS Distributions #define memmove(dst, src, n)            __builtin_memmove(dst, src, n)
201*1b191cb5SApple OSS Distributions #define bcopy(src, dst, n)              __builtin_memmove(dst, src, n)
202*1b191cb5SApple OSS Distributions #define __nochk_memmove(dst, src, n)    memmove(dst, src, n)
203*1b191cb5SApple OSS Distributions #define __nochk_bcopy(src, dst, n)      bcopy(src, dst, n)
204*1b191cb5SApple OSS Distributions #else
205*1b191cb5SApple OSS Distributions #define __nochk_memmove(dst, src, n)    memmove(dst, src, n)
206*1b191cb5SApple OSS Distributions #define __nochk_bcopy(src, dst, n)      bcopy(src, dst, n)
207*1b191cb5SApple OSS Distributions #endif /* !XNU_USE_CHK_BUILTIN(memmove) */
208*1b191cb5SApple OSS Distributions 
209*1b191cb5SApple OSS Distributions 
210*1b191cb5SApple OSS Distributions #pragma mark string functions
211*1b191cb5SApple OSS Distributions 
212*1b191cb5SApple OSS Distributions extern size_t strlen(const char *__null_terminated s) __stateful_pure;
213*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(strlen)
214*1b191cb5SApple OSS Distributions #define strlen(s)                       __builtin_strlen(s)
215*1b191cb5SApple OSS Distributions #endif
216*1b191cb5SApple OSS Distributions 
217*1b191cb5SApple OSS Distributions 
218*1b191cb5SApple OSS Distributions extern size_t strnlen(const char *__null_terminated s, size_t n) __stateful_pure;
219*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(strnlen)
220*1b191cb5SApple OSS Distributions #define strnlen(s, n)                   __builtin_strnlen(s, n)
221*1b191cb5SApple OSS Distributions #endif
222*1b191cb5SApple OSS Distributions 
223*1b191cb5SApple OSS Distributions 
224*1b191cb5SApple OSS Distributions extern int strcmp(const char *__null_terminated s1, const char *__null_terminated s2) __stateful_pure;
225*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(strcmp)
226*1b191cb5SApple OSS Distributions #define strcmp(s1, s2)                  __builtin_strcmp(s1, s2)
227*1b191cb5SApple OSS Distributions #endif
228*1b191cb5SApple OSS Distributions 
229*1b191cb5SApple OSS Distributions 
230*1b191cb5SApple OSS Distributions extern int strncmp(const char *__null_terminated s1, const char *__null_terminated s2, size_t n) __stateful_pure;
231*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(strncmp)
232*1b191cb5SApple OSS Distributions #define strncmp(s1, s2, n)              __builtin_strncmp(s1, s2, n)
233*1b191cb5SApple OSS Distributions #endif
234*1b191cb5SApple OSS Distributions 
235*1b191cb5SApple OSS Distributions 
236*1b191cb5SApple OSS Distributions extern int strprefix(const char *__null_terminated s1, const char *__null_terminated s2) __stateful_pure;
237*1b191cb5SApple OSS Distributions 
238*1b191cb5SApple OSS Distributions 
239*1b191cb5SApple OSS Distributions extern int strcasecmp(const char *__null_terminated s1, const char *__null_terminated s2) __stateful_pure;
240*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(strcasecmp)
241*1b191cb5SApple OSS Distributions #define strcasecmp(s1, s2)              __builtin_strcasecmp(s1, s2)
242*1b191cb5SApple OSS Distributions #endif
243*1b191cb5SApple OSS Distributions 
244*1b191cb5SApple OSS Distributions 
245*1b191cb5SApple OSS Distributions extern int strncasecmp(const char *__null_terminated s1, const char *__null_terminated s2, size_t n) __stateful_pure;
246*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(strncasecmp)
247*1b191cb5SApple OSS Distributions #define strncasecmp(s1, s2, n)          __builtin_strncasecmp(s1, s2, n)
248*1b191cb5SApple OSS Distributions #endif
249*1b191cb5SApple OSS Distributions 
250*1b191cb5SApple OSS Distributions 
251*1b191cb5SApple OSS Distributions extern char *__null_terminated strchr(const char *__null_terminated s, int c) __stateful_pure;
252*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(strchr) && !__has_ptrcheck /* rdar://103265304 */
253*1b191cb5SApple OSS Distributions #define strchr(s, c)                    __builtin_strchr(s, c)
254*1b191cb5SApple OSS Distributions #endif
255*1b191cb5SApple OSS Distributions 
256*1b191cb5SApple OSS Distributions 
257*1b191cb5SApple OSS Distributions #if XNU_KERNEL_PRIVATE /* rdar://103276672 */
258*1b191cb5SApple OSS Distributions extern char *__null_terminated strrchr(const char *__null_terminated s, int c) __stateful_pure;
259*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(strrchr) && !__has_ptrcheck /* rdar://103265304 */
260*1b191cb5SApple OSS Distributions #define strrchr(s, c)                   __builtin_strrchr(s, c)
261*1b191cb5SApple OSS Distributions #endif
262*1b191cb5SApple OSS Distributions #endif
263*1b191cb5SApple OSS Distributions 
264*1b191cb5SApple OSS Distributions 
265*1b191cb5SApple OSS Distributions extern char *__null_terminated strnstr(const char *__null_terminated s, const char *__null_terminated find, size_t slen) __stateful_pure;
266*1b191cb5SApple OSS Distributions #if XNU_USE_STRING_BUILTIN(strnstr) && !__has_ptrcheck /* rdar://103265304 */
267*1b191cb5SApple OSS Distributions #define strnstr(s, find, slen)          __builtin_strnstr(s, find, slen)
268*1b191cb5SApple OSS Distributions #endif
269*1b191cb5SApple OSS Distributions 
270*1b191cb5SApple OSS Distributions 
271*1b191cb5SApple OSS Distributions extern size_t strlcpy(char *__sized_by(n) dst, const char *__null_terminated src, size_t n);
272*1b191cb5SApple OSS Distributions #if XNU_USE_CHK_BUILTIN(strlcpy)
273*1b191cb5SApple OSS Distributions #define strlcpy(dst, src, n)            __builtin___strlcpy_chk(dst, src, n, __xnu_bos_strict(dst))
274*1b191cb5SApple OSS Distributions #elif XNU_USE_STRING_BUILTIN(strlcpy)
275*1b191cb5SApple OSS Distributions #define strlcpy(dst, src, n)            __builtin_strlcpy(dst, src, n)
276*1b191cb5SApple OSS Distributions #endif
277*1b191cb5SApple OSS Distributions 
278*1b191cb5SApple OSS Distributions 
279*1b191cb5SApple OSS Distributions extern size_t strlcat(char *__sized_by(n) dst, const char *__null_terminated src, size_t n);
280*1b191cb5SApple OSS Distributions #if XNU_USE_CHK_BUILTIN(strlcat)
281*1b191cb5SApple OSS Distributions #define strlcat(dst, src, n)            __builtin___strlcat_chk(dst, src, n, __xnu_bos_strict(dst))
282*1b191cb5SApple OSS Distributions #elif XNU_USE_STRING_BUILTIN(strlcat)
283*1b191cb5SApple OSS Distributions #define strlcat(dst, src, n)            __builtin_strlcat(dst, src, n)
284*1b191cb5SApple OSS Distributions #endif
285*1b191cb5SApple OSS Distributions 
286*1b191cb5SApple OSS Distributions 
287*1b191cb5SApple OSS Distributions #pragma mark deprecated functions
288*1b191cb5SApple OSS Distributions #if !__has_ptrcheck
289*1b191cb5SApple OSS Distributions 
290*1b191cb5SApple OSS Distributions /*
291*1b191cb5SApple OSS Distributions  * char *strncat(char *dst, const char *src, size_t n);
292*1b191cb5SApple OSS Distributions  * char *strncpy(char *dst, const char *src, size_t n);
293*1b191cb5SApple OSS Distributions  *
294*1b191cb5SApple OSS Distributions  * char *strcat(char *dst, const char *src);
295*1b191cb5SApple OSS Distributions  * char *strcpy(char *, const char *);
296*1b191cb5SApple OSS Distributions  *
297*1b191cb5SApple OSS Distributions  * char *STRDUP(const char *, int);
298*1b191cb5SApple OSS Distributions  */
299*1b191cb5SApple OSS Distributions 
300*1b191cb5SApple OSS Distributions __deprecated_msg("use strlcat")
301*1b191cb5SApple OSS Distributions __kpi_deprecated_arm64_macos_unavailable
302*1b191cb5SApple OSS Distributions extern char *strncat(char *dst, const char *src, size_t n);
303*1b191cb5SApple OSS Distributions #if XNU_USE_CHK_BUILTIN(strncat)
304*1b191cb5SApple OSS Distributions #define strncat(dst, src, n)            __builtin___strncat_chk(dst, src, n, __xnu_bos_strict(dst))
305*1b191cb5SApple OSS Distributions #endif
306*1b191cb5SApple OSS Distributions 
307*1b191cb5SApple OSS Distributions 
308*1b191cb5SApple OSS Distributions __deprecated_msg("use strlcpy")
309*1b191cb5SApple OSS Distributions __kpi_deprecated_arm64_macos_unavailable
310*1b191cb5SApple OSS Distributions extern char *strncpy(char *dst, const char *src, size_t n);
311*1b191cb5SApple OSS Distributions #if XNU_USE_CHK_BUILTIN(strncpy)
312*1b191cb5SApple OSS Distributions #define strncpy(dst, src, n)            __builtin___strncpy_chk(dst, src, n, __xnu_bos_strict(dst))
313*1b191cb5SApple OSS Distributions #endif
314*1b191cb5SApple OSS Distributions 
315*1b191cb5SApple OSS Distributions __deprecated_msg("use strlcpy")
316*1b191cb5SApple OSS Distributions __kpi_deprecated_arm64_macos_unavailable
317*1b191cb5SApple OSS Distributions extern char *strcpy(char *, const char *);
318*1b191cb5SApple OSS Distributions #if XNU_USE_CHK_BUILTIN(strcpy)
319*1b191cb5SApple OSS Distributions /* rdar://103287225 */
320*1b191cb5SApple OSS Distributions #define strcpy(dst, src, len)           __builtin___strcpy_chk(dst, src, __xnu_bos_strict(dst))
321*1b191cb5SApple OSS Distributions #endif
322*1b191cb5SApple OSS Distributions 
323*1b191cb5SApple OSS Distributions __deprecated_msg("use strlcat")
324*1b191cb5SApple OSS Distributions __kpi_deprecated_arm64_macos_unavailable
325*1b191cb5SApple OSS Distributions extern char *strcat(char *dst, const char *src);
326*1b191cb5SApple OSS Distributions #if XNU_USE_CHK_BUILTIN(strcat)
327*1b191cb5SApple OSS Distributions #define strcat(dst, src)                __builtin___strcat_chk(dst, src, __xnu_bos_strict(dst))
328*1b191cb5SApple OSS Distributions #endif
329*1b191cb5SApple OSS Distributions 
330*1b191cb5SApple OSS Distributions #if XNU_PLATFORM_MacOSX
331*1b191cb5SApple OSS Distributions #ifndef KERNEL_PRIVATE
332*1b191cb5SApple OSS Distributions extern char *STRDUP(const char *, int);
333*1b191cb5SApple OSS Distributions #endif
334*1b191cb5SApple OSS Distributions #endif /* XNU_PLATFORM_MacOSX */
335*1b191cb5SApple OSS Distributions 
336*1b191cb5SApple OSS Distributions #endif /* !__has_ptrcheck */
337*1b191cb5SApple OSS Distributions 
338*1b191cb5SApple OSS Distributions #if __has_include(<san/memintrinsics.h>)
339*1b191cb5SApple OSS Distributions #include <san/memintrinsics.h>
340*1b191cb5SApple OSS Distributions #endif
341*1b191cb5SApple OSS Distributions 
342*1b191cb5SApple OSS Distributions __END_DECLS
343*1b191cb5SApple OSS Distributions 
344*1b191cb5SApple OSS Distributions #endif  /* _STRING_H_ */
345