]>
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, strcat
43 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
45 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
50 #define memcpy(dest, src, len) \
51 ((__darwin_obsz0 (dest) != (size_t) -1) \
52 ? __builtin___memcpy_chk (dest, src, len, __darwin_obsz0 (dest)) \
53 : __inline_memcpy_chk (dest, src, len))
55 static __inline
void *
56 __inline_memcpy_chk (void *__dest
, const void *__src
, size_t __len
)
58 return __builtin___memcpy_chk (__dest
, __src
, __len
, __darwin_obsz0(__dest
));
61 #define memmove(dest, src, len) \
62 ((__darwin_obsz0 (dest) != (size_t) -1) \
63 ? __builtin___memmove_chk (dest, src, len, __darwin_obsz0 (dest)) \
64 : __inline_memmove_chk (dest, src, len))
66 static __inline
void *
67 __inline_memmove_chk (void *__dest
, const void *__src
, size_t __len
)
69 return __builtin___memmove_chk (__dest
, __src
, __len
, __darwin_obsz0(__dest
));
72 #define memset(dest, val, len) \
73 ((__darwin_obsz0 (dest) != (size_t) -1) \
74 ? __builtin___memset_chk (dest, val, len, __darwin_obsz0 (dest)) \
75 : __inline_memset_chk (dest, val, len))
77 static __inline
void *
78 __inline_memset_chk (void *__dest
, int __val
, size_t __len
)
80 return __builtin___memset_chk (__dest
, __val
, __len
, __darwin_obsz0(__dest
));
83 #define strcpy(dest, src) \
84 ((__darwin_obsz0 (dest) != (size_t) -1) \
85 ? __builtin___strcpy_chk (dest, src, __darwin_obsz (dest)) \
86 : __inline_strcpy_chk (dest, src))
88 static __inline
char *
89 __inline_strcpy_chk (char *__restrict __dest
, const char *__restrict __src
)
91 return __builtin___strcpy_chk (__dest
, __src
, __darwin_obsz(__dest
));
94 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
95 #define stpcpy(dest, src) \
96 ((__darwin_obsz0 (dest) != (size_t) -1) \
97 ? __builtin___stpcpy_chk (dest, src, __darwin_obsz (dest)) \
98 : __inline_stpcpy_chk (dest, src))
100 static __inline
char *
101 __inline_stpcpy_chk (char *__dest
, const char *__src
)
103 return __builtin___stpcpy_chk (__dest
, __src
, __darwin_obsz(__dest
));
105 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
107 #define strncpy(dest, src, len) \
108 ((__darwin_obsz0 (dest) != (size_t) -1) \
109 ? __builtin___strncpy_chk (dest, src, len, __darwin_obsz (dest)) \
110 : __inline_strncpy_chk (dest, src, len))
112 static __inline
char *
113 __inline_strncpy_chk (char *__restrict __dest
, const char *__restrict __src
,
116 return __builtin___strncpy_chk (__dest
, __src
, __len
, __darwin_obsz(__dest
));
119 #define strcat(dest, src) \
120 ((__darwin_obsz0 (dest) != (size_t) -1) \
121 ? __builtin___strcat_chk (dest, src, __darwin_obsz (dest)) \
122 : __inline_strcat_chk (dest, src))
124 static __inline
char *
125 __inline_strcat_chk (char *__restrict __dest
, const char *__restrict __src
)
127 return __builtin___strcat_chk (__dest
, __src
, __darwin_obsz(__dest
));
130 #define strncat(dest, src, len) \
131 ((__darwin_obsz0 (dest) != (size_t) -1) \
132 ? __builtin___strncat_chk (dest, src, len, __darwin_obsz (dest)) \
133 : __inline_strncat_chk (dest, src, len))
135 static __inline
char *
136 __inline_strncat_chk (char *__restrict __dest
, const char *__restrict __src
,
139 return __builtin___strncat_chk (__dest
, __src
, __len
, __darwin_obsz(__dest
));