]>
git.saurik.com Git - apple/libc.git/blob - include/secure/_string.h
c1ff94b1040f0ca42db7047c60c9cbe4938742d6
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 <Availability.h>
32 #include <sys/cdefs.h>
33 #include <secure/_common.h>
35 #if _USE_FORTIFY_LEVEL > 0
38 #define _undef__has_builtin
39 #define __has_builtin(x) 0
42 /* <rdar://problem/12622659> */
43 #if defined(__clang__) && \
44 ((defined(__apple_build_version__) && __apple_build_version__ >= 4260006) || \
45 (!defined(__apple_build_version__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 3))))
46 #define __HAS_FIXED_CHK_PROTOTYPES 1
48 #define __HAS_FIXED_CHK_PROTOTYPES 0
51 /* memccpy, memcpy, mempcpy, memmove, memset, strcpy, strlcpy, stpcpy,
52 strncpy, stpncpy, strcat, strlcat, and strncat */
54 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
55 #if __has_builtin(__builtin___memccpy_chk) && __HAS_FIXED_CHK_PROTOTYPES
57 #define memccpy(dest, src, c, len) \
58 __builtin___memccpy_chk (dest, src, c, len, __darwin_obsz0 (dest))
62 #if __has_builtin(__builtin___memcpy_chk) || defined(__GNUC__)
64 #define memcpy(dest, src, len) \
65 __builtin___memcpy_chk (dest, src, len, __darwin_obsz0 (dest))
68 #if __has_builtin(__builtin___memmove_chk) || defined(__GNUC__)
70 #define memmove(dest, src, len) \
71 __builtin___memmove_chk (dest, src, len, __darwin_obsz0 (dest))
74 #if __has_builtin(__builtin___memset_chk) || defined(__GNUC__)
76 #define memset(dest, val, len) \
77 __builtin___memset_chk (dest, val, len, __darwin_obsz0 (dest))
80 #if __has_builtin(__builtin___strcpy_chk) || defined(__GNUC__)
82 #define strcpy(dest, src) \
83 __builtin___strcpy_chk (dest, src, __darwin_obsz (dest))
86 #if __DARWIN_C_LEVEL >= 200809L
87 #if __has_builtin(__builtin___stpcpy_chk) || defined(__GNUC__)
89 #define stpcpy(dest, src) \
90 __builtin___stpcpy_chk (dest, src, __darwin_obsz (dest))
93 #if __has_builtin(__builtin___stpncpy_chk) || __APPLE_CC__ >= 5666 || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
95 #define stpncpy(dest, src, len) \
96 __builtin___stpncpy_chk (dest, src, len, __darwin_obsz (dest))
98 #endif /* _DARWIN_C_LEVEL >= 200809L */
100 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
101 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
102 #if __has_builtin(__builtin___strlcpy_chk) && __HAS_FIXED_CHK_PROTOTYPES
104 #define strlcpy(dest, src, len) \
105 __builtin___strlcpy_chk (dest, src, len, __darwin_obsz (dest))
108 #if __has_builtin(__builtin___strlcat_chk) && __HAS_FIXED_CHK_PROTOTYPES
110 #define strlcat(dest, src, len) \
111 __builtin___strlcat_chk (dest, src, len, __darwin_obsz (dest))
113 #endif /* __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 */
114 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
116 #if __has_builtin(__builtin___strncpy_chk) || defined(__GNUC__)
118 #define strncpy(dest, src, len) \
119 __builtin___strncpy_chk (dest, src, len, __darwin_obsz (dest))
122 #if __has_builtin(__builtin___strcat_chk) || defined(__GNUC__)
124 #define strcat(dest, src) \
125 __builtin___strcat_chk (dest, src, __darwin_obsz (dest))
128 #if ! (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 32000)
129 #if __has_builtin(__builtin___strncat_chk) || defined(__GNUC__)
131 #define strncat(dest, src, len) \
132 __builtin___strncat_chk (dest, src, len, __darwin_obsz (dest))
136 #ifdef _undef__has_builtin
137 #undef _undef__has_builtin
141 #undef __HAS_FIXED_CHK_PROTOTYPES
143 #endif /* _USE_FORTIFY_LEVEL > 0 */
144 #endif /* _SECURE__STRING_H_ */