]>
Commit | Line | Data |
---|---|---|
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 <secure/_common.h> | |
32 | ||
33 | #if _USE_FORTIFY_LEVEL > 0 | |
34 | ||
35 | /* memcpy, mempcpy, memmove, memset, strcpy, stpcpy, strncpy, strcat | |
36 | and strncat */ | |
37 | ||
38 | #undef memcpy | |
39 | #undef memmove | |
40 | #undef memset | |
41 | #undef strcpy | |
42 | #undef stpcpy | |
43 | #undef strncpy | |
44 | #undef strcat | |
45 | #undef strncat | |
46 | ||
47 | #define memcpy(dest, src, len) \ | |
48 | ((__darwin_obsz0 (dest) != (size_t) -1) \ | |
49 | ? __builtin___memcpy_chk (dest, src, len, __darwin_obsz0 (dest)) \ | |
50 | : __inline_memcpy_chk (dest, src, len)) | |
51 | ||
52 | static inline void * | |
53 | __inline_memcpy_chk (void *__dest, const void *__src, size_t __len) | |
54 | { | |
55 | return __builtin___memcpy_chk (__dest, __src, __len, __darwin_obsz0(__dest)); | |
56 | } | |
57 | ||
58 | #define memmove(dest, src, len) \ | |
59 | ((__darwin_obsz0 (dest) != (size_t) -1) \ | |
60 | ? __builtin___memmove_chk (dest, src, len, __darwin_obsz0 (dest)) \ | |
61 | : __inline_memmove_chk (dest, src, len)) | |
62 | ||
63 | static inline void * | |
64 | __inline_memmove_chk (void *__dest, const void *__src, size_t __len) | |
65 | { | |
66 | return __builtin___memmove_chk (__dest, __src, __len, __darwin_obsz0(__dest)); | |
67 | } | |
68 | ||
69 | #define memset(dest, val, len) \ | |
70 | ((__darwin_obsz0 (dest) != (size_t) -1) \ | |
71 | ? __builtin___memset_chk (dest, val, len, __darwin_obsz0 (dest)) \ | |
72 | : __inline_memset_chk (dest, val, len)) | |
73 | ||
74 | static inline void * | |
75 | __inline_memset_chk (void *__dest, int __val, size_t __len) | |
76 | { | |
77 | return __builtin___memset_chk (__dest, __val, __len, __darwin_obsz0(__dest)); | |
78 | } | |
79 | ||
80 | #define strcpy(dest, src) \ | |
81 | ((__darwin_obsz0 (dest) != (size_t) -1) \ | |
82 | ? __builtin___strcpy_chk (dest, src, __darwin_obsz (dest)) \ | |
83 | : __inline_strcpy_chk (dest, src)) | |
84 | ||
85 | static inline char * | |
86 | __inline_strcpy_chk (char *__restrict __dest, const char *__restrict __src) | |
87 | { | |
88 | return __builtin___strcpy_chk (__dest, __src, __darwin_obsz(__dest)); | |
89 | } | |
90 | ||
91 | #define stpcpy(dest, src) \ | |
92 | ((__darwin_obsz0 (dest) != (size_t) -1) \ | |
93 | ? __builtin___stpcpy_chk (dest, src, __darwin_obsz (dest)) \ | |
94 | : __inline_stpcpy_chk (dest, src)) | |
95 | ||
96 | static inline char * | |
97 | __inline_stpcpy_chk (char *__dest, const char *__src) | |
98 | { | |
99 | return __builtin___stpcpy_chk (__dest, __src, __darwin_obsz(__dest)); | |
100 | } | |
101 | ||
102 | #define strncpy(dest, src, len) \ | |
103 | ((__darwin_obsz0 (dest) != (size_t) -1) \ | |
104 | ? __builtin___strncpy_chk (dest, src, len, __darwin_obsz (dest)) \ | |
105 | : __inline_strncpy_chk (dest, src, len)) | |
106 | ||
107 | static inline char * | |
108 | __inline_strncpy_chk (char *__restrict __dest, const char *__restrict __src, | |
109 | size_t __len) | |
110 | { | |
111 | return __builtin___strncpy_chk (__dest, __src, __len, __darwin_obsz(__dest)); | |
112 | } | |
113 | ||
114 | #define strcat(dest, src) \ | |
115 | ((__darwin_obsz0 (dest) != (size_t) -1) \ | |
116 | ? __builtin___strcat_chk (dest, src, __darwin_obsz (dest)) \ | |
117 | : __inline_strcat_chk (dest, src)) | |
118 | ||
119 | static inline char * | |
120 | __inline_strcat_chk (char *__restrict __dest, const char *__restrict __src) | |
121 | { | |
122 | return __builtin___strcat_chk (__dest, __src, __darwin_obsz(__dest)); | |
123 | } | |
124 | ||
125 | #define strncat(dest, src, len) \ | |
126 | ((__darwin_obsz0 (dest) != (size_t) -1) \ | |
127 | ? __builtin___strcat_chk (dest, src, __darwin_obsz (dest)) \ | |
128 | : __inline_strncat_chk (dest, src, len)) | |
129 | ||
130 | static inline char * | |
131 | __inline_strncat_chk (char *__restrict __dest, const char *__restrict __src, | |
132 | size_t __len) | |
133 | { | |
134 | return __builtin___strncat_chk (__dest, __src, __len, __darwin_obsz(__dest)); | |
135 | } | |
136 | ||
137 | #endif | |
138 | #endif |