]>
git.saurik.com Git - apple/libc.git/blob - include/secure/_string.h
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 # error "Never use <secure/_string.h> directly; include <string.h> instead."
28 #ifndef _SECURE__STRING_H_
29 #define _SECURE__STRING_H_
31 #include <sys/cdefs.h>
32 #include <secure/_common.h>
34 #if _USE_FORTIFY_LEVEL > 0
36 /* memcpy, mempcpy, memmove, memset, strcpy, stpcpy, strncpy, stpncpy,
37 strcat, and strncat */
43 #if __DARWIN_C_LEVEL >= 200809L
49 #if ! (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 32000)
53 #define memcpy(dest, src, len) \
54 ((__darwin_obsz0 (dest) != (size_t) -1) \
55 ? __builtin___memcpy_chk (dest, src, len, __darwin_obsz0 (dest)) \
56 : __inline_memcpy_chk (dest, src, len))
58 static __inline
void *
59 __inline_memcpy_chk (void *__dest
, const void *__src
, size_t __len
)
61 return __builtin___memcpy_chk (__dest
, __src
, __len
, __darwin_obsz0(__dest
));
64 #define memmove(dest, src, len) \
65 ((__darwin_obsz0 (dest) != (size_t) -1) \
66 ? __builtin___memmove_chk (dest, src, len, __darwin_obsz0 (dest)) \
67 : __inline_memmove_chk (dest, src, len))
69 static __inline
void *
70 __inline_memmove_chk (void *__dest
, const void *__src
, size_t __len
)
72 return __builtin___memmove_chk (__dest
, __src
, __len
, __darwin_obsz0(__dest
));
75 #define memset(dest, val, len) \
76 ((__darwin_obsz0 (dest) != (size_t) -1) \
77 ? __builtin___memset_chk (dest, val, len, __darwin_obsz0 (dest)) \
78 : __inline_memset_chk (dest, val, len))
80 static __inline
void *
81 __inline_memset_chk (void *__dest
, int __val
, size_t __len
)
83 return __builtin___memset_chk (__dest
, __val
, __len
, __darwin_obsz0(__dest
));
86 #define strcpy(dest, src) \
87 ((__darwin_obsz0 (dest) != (size_t) -1) \
88 ? __builtin___strcpy_chk (dest, src, __darwin_obsz (dest)) \
89 : __inline_strcpy_chk (dest, src))
91 static __inline
char *
92 __inline_strcpy_chk (char *__restrict __dest
, const char *__restrict __src
)
94 return __builtin___strcpy_chk (__dest
, __src
, __darwin_obsz(__dest
));
97 #if __DARWIN_C_LEVEL >= 200809L
98 #define stpcpy(dest, src) \
99 ((__darwin_obsz0 (dest) != (size_t) -1) \
100 ? __builtin___stpcpy_chk (dest, src, __darwin_obsz (dest)) \
101 : __inline_stpcpy_chk (dest, src))
103 static __inline
char *
104 __inline_stpcpy_chk (char *__dest
, const char *__src
)
106 return __builtin___stpcpy_chk (__dest
, __src
, __darwin_obsz(__dest
));
109 #define stpncpy(dest, src, len) \
110 ((__darwin_obsz0 (dest) != (size_t) -1) \
111 ? __builtin___stpncpy_chk (dest, src, len, __darwin_obsz (dest)) \
112 : __inline_stpncpy_chk (dest, src, len))
114 static __inline
char *
115 __inline_stpncpy_chk (char *__restrict __dest
, const char *__restrict __src
,
118 return __builtin___stpncpy_chk (__dest
, __src
, __len
, __darwin_obsz(__dest
));
122 #define strncpy(dest, src, len) \
123 ((__darwin_obsz0 (dest) != (size_t) -1) \
124 ? __builtin___strncpy_chk (dest, src, len, __darwin_obsz (dest)) \
125 : __inline_strncpy_chk (dest, src, len))
127 static __inline
char *
128 __inline_strncpy_chk (char *__restrict __dest
, const char *__restrict __src
,
131 return __builtin___strncpy_chk (__dest
, __src
, __len
, __darwin_obsz(__dest
));
134 #define strcat(dest, src) \
135 ((__darwin_obsz0 (dest) != (size_t) -1) \
136 ? __builtin___strcat_chk (dest, src, __darwin_obsz (dest)) \
137 : __inline_strcat_chk (dest, src))
139 static __inline
char *
140 __inline_strcat_chk (char *__restrict __dest
, const char *__restrict __src
)
142 return __builtin___strcat_chk (__dest
, __src
, __darwin_obsz(__dest
));
145 #if ! (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 32000)
146 #define strncat(dest, src, len) \
147 ((__darwin_obsz0 (dest) != (size_t) -1) \
148 ? __builtin___strncat_chk (dest, src, len, __darwin_obsz (dest)) \
149 : __inline_strncat_chk (dest, src, len))
151 static __inline
char *
152 __inline_strncat_chk (char *__restrict __dest
, const char *__restrict __src
,
155 return __builtin___strncat_chk (__dest
, __src
, __len
, __darwin_obsz(__dest
));