]> git.saurik.com Git - apple/libc.git/blob - include/secure/_string.h
cba7db475a36b8e7707eca1cc7fb11cdfafa7426
[apple/libc.git] / include / secure / _string.h
1 /*
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _STRING_H_
25 # error "Never use <secure/_string.h> directly; include <string.h> instead."
26 #endif
27
28 #ifndef _SECURE__STRING_H_
29 #define _SECURE__STRING_H_
30
31 #include <sys/cdefs.h>
32 #include <secure/_common.h>
33
34 #if _USE_FORTIFY_LEVEL > 0
35
36 /* memcpy, mempcpy, memmove, memset, strcpy, stpcpy, strncpy, stpncpy,
37 strcat, and strncat */
38
39 #undef memcpy
40 #undef memmove
41 #undef memset
42 #undef strcpy
43 #if __DARWIN_C_LEVEL >= 200809L
44 #undef stpcpy
45 #undef stpncpy
46 #endif
47 #undef strncpy
48 #undef strcat
49 #if ! (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 32000)
50 #undef strncat
51 #endif
52
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))
57
58 static __inline void *
59 __inline_memcpy_chk (void *__dest, const void *__src, size_t __len)
60 {
61 return __builtin___memcpy_chk (__dest, __src, __len, __darwin_obsz0(__dest));
62 }
63
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))
68
69 static __inline void *
70 __inline_memmove_chk (void *__dest, const void *__src, size_t __len)
71 {
72 return __builtin___memmove_chk (__dest, __src, __len, __darwin_obsz0(__dest));
73 }
74
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))
79
80 static __inline void *
81 __inline_memset_chk (void *__dest, int __val, size_t __len)
82 {
83 return __builtin___memset_chk (__dest, __val, __len, __darwin_obsz0(__dest));
84 }
85
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))
90
91 static __inline char *
92 __inline_strcpy_chk (char *__restrict __dest, const char *__restrict __src)
93 {
94 return __builtin___strcpy_chk (__dest, __src, __darwin_obsz(__dest));
95 }
96
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))
102
103 static __inline char *
104 __inline_stpcpy_chk (char *__dest, const char *__src)
105 {
106 return __builtin___stpcpy_chk (__dest, __src, __darwin_obsz(__dest));
107 }
108
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))
113
114 static __inline char *
115 __inline_stpncpy_chk (char *__restrict __dest, const char *__restrict __src,
116 size_t __len)
117 {
118 return __builtin___stpncpy_chk (__dest, __src, __len, __darwin_obsz(__dest));
119 }
120 #endif
121
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))
126
127 static __inline char *
128 __inline_strncpy_chk (char *__restrict __dest, const char *__restrict __src,
129 size_t __len)
130 {
131 return __builtin___strncpy_chk (__dest, __src, __len, __darwin_obsz(__dest));
132 }
133
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))
138
139 static __inline char *
140 __inline_strcat_chk (char *__restrict __dest, const char *__restrict __src)
141 {
142 return __builtin___strcat_chk (__dest, __src, __darwin_obsz(__dest));
143 }
144
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))
150
151 static __inline char *
152 __inline_strncat_chk (char *__restrict __dest, const char *__restrict __src,
153 size_t __len)
154 {
155 return __builtin___strncat_chk (__dest, __src, __len, __darwin_obsz(__dest));
156 }
157 #endif
158
159 #endif
160 #endif