]>
Commit | Line | Data |
---|---|---|
553cc5f9 | 1 | /* Copyright (C) 2004, 2005 Free Software Foundation, Inc. |
b5cc329c UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
15 | License along with the GNU C Library; if not, write to the Free | |
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
17 | 02111-1307 USA. */ | |
18 | ||
19 | #ifndef _STRING_H | |
20 | # error "Never use <bits/string3.h> directly; include <string.h> instead." | |
21 | #endif | |
22 | ||
23 | /* XXX This is temporarily. We should not redefine any of the symbols | |
24 | and instead integrate the error checking into the original | |
25 | definitions. */ | |
26 | #undef memcpy | |
27 | #undef memmove | |
28 | #undef memset | |
29 | #undef strcat | |
30 | #undef strcpy | |
31 | #undef strncat | |
32 | #undef strncpy | |
33 | #ifdef __USE_GNU | |
34 | # undef mempcpy | |
35 | # undef stpcpy | |
36 | #endif | |
37 | #ifdef __USE_BSD | |
38 | # undef bcopy | |
39 | # undef bzero | |
40 | #endif | |
41 | ||
42 | ||
43 | #define memcpy(dest, src, len) \ | |
44 | ((__bos0 (dest) != (size_t) -1) \ | |
45 | ? __builtin___memcpy_chk (dest, src, len, __bos0 (dest)) \ | |
46 | : __memcpy_ichk (dest, src, len)) | |
a334319f UD |
47 | static __inline__ void * |
48 | __attribute__ ((__always_inline__)) | |
49 | __memcpy_ichk (void *__restrict __dest, const void *__restrict __src, | |
50 | size_t __len) | |
b5cc329c UD |
51 | { |
52 | return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); | |
53 | } | |
54 | ||
55 | ||
56 | #define memmove(dest, src, len) \ | |
57 | ((__bos0 (dest) != (size_t) -1) \ | |
58 | ? __builtin___memmove_chk (dest, src, len, __bos0 (dest)) \ | |
59 | : __memmove_ichk (dest, src, len)) | |
a334319f UD |
60 | static __inline__ void * |
61 | __attribute__ ((__always_inline__)) | |
62 | __memmove_ichk (void *__dest, const void *__src, size_t __len) | |
b5cc329c UD |
63 | { |
64 | return __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest)); | |
65 | } | |
66 | ||
67 | ||
68 | #ifdef __USE_GNU | |
69 | # define mempcpy(dest, src, len) \ | |
70 | ((__bos0 (dest) != (size_t) -1) \ | |
71 | ? __builtin___mempcpy_chk (dest, src, len, __bos0 (dest)) \ | |
72 | : __mempcpy_ichk (dest, src, len)) | |
a334319f UD |
73 | static __inline__ void * |
74 | __attribute__ ((__always_inline__)) | |
75 | __mempcpy_ichk (void *__restrict __dest, const void *__restrict __src, | |
76 | size_t __len) | |
b5cc329c UD |
77 | { |
78 | return __builtin___mempcpy_chk (__dest, __src, __len, __bos0 (__dest)); | |
79 | } | |
80 | #endif | |
81 | ||
82 | ||
553cc5f9 UD |
83 | /* The first two tests here help to catch a somewhat common problem |
84 | where the second and third parameter are transposed. This is | |
85 | especially problematic if the intended fill value is zero. In this | |
86 | case no work is done at all. We detect these problems by referring | |
87 | non-existing functions. */ | |
88 | extern char *__memset_zero_constant_len_parameter (void *, int, size_t, | |
89 | size_t); | |
b5cc329c | 90 | #define memset(dest, ch, len) \ |
553cc5f9 UD |
91 | (__builtin_constant_p (len) && (len) == 0 \ |
92 | ? __memset_zero_constant_len_parameter (dest, ch, len, 0) \ | |
93 | : ((__bos0 (dest) != (size_t) -1) \ | |
94 | ? __builtin___memset_chk (dest, ch, len, __bos0 (dest)) \ | |
95 | : __memset_ichk (dest, ch, len))) | |
a334319f UD |
96 | static __inline__ void * |
97 | __attribute__ ((__always_inline__)) | |
98 | __memset_ichk (void *__dest, int __ch, size_t __len) | |
b5cc329c UD |
99 | { |
100 | return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest)); | |
101 | } | |
102 | ||
103 | #ifdef __USE_BSD | |
104 | # define bcopy(src, dest, len) ((void) \ | |
105 | ((__bos0 (dest) != (size_t) -1) \ | |
106 | ? __builtin___memmove_chk (dest, src, len, __bos0 (dest)) \ | |
107 | : __memmove_ichk (dest, src, len))) | |
108 | # define bzero(dest, len) ((void) \ | |
109 | ((__bos0 (dest) != (size_t) -1) \ | |
110 | ? __builtin___memset_chk (dest, '\0', len, __bos0 (dest)) \ | |
111 | : __memset_ichk (dest, '\0', len))) | |
112 | #endif | |
113 | ||
114 | ||
115 | #define strcpy(dest, src) \ | |
116 | ((__bos (dest) != (size_t) -1) \ | |
117 | ? __builtin___strcpy_chk (dest, src, __bos (dest)) \ | |
118 | : __strcpy_ichk (dest, src)) | |
a334319f UD |
119 | static __inline__ char * |
120 | __attribute__ ((__always_inline__)) | |
121 | __strcpy_ichk (char *__restrict __dest, const char *__restrict __src) | |
b5cc329c UD |
122 | { |
123 | return __builtin___strcpy_chk (__dest, __src, __bos (__dest)); | |
124 | } | |
125 | ||
126 | ||
127 | #ifdef __USE_GNU | |
128 | # define stpcpy(dest, src) \ | |
129 | ((__bos (dest) != (size_t) -1) \ | |
130 | ? __builtin___stpcpy_chk (dest, src, __bos (dest)) \ | |
131 | : __stpcpy_ichk (dest, src)) | |
a334319f UD |
132 | static __inline__ char * |
133 | __attribute__ ((__always_inline__)) | |
134 | __stpcpy_ichk (char *__restrict __dest, const char *__restrict __src) | |
b5cc329c UD |
135 | { |
136 | return __builtin___stpcpy_chk (__dest, __src, __bos (__dest)); | |
137 | } | |
138 | #endif | |
139 | ||
140 | ||
141 | #define strncpy(dest, src, len) \ | |
142 | ((__bos (dest) != (size_t) -1) \ | |
143 | ? __builtin___strncpy_chk (dest, src, len, __bos (dest)) \ | |
144 | : __strncpy_ichk (dest, src, len)) | |
a334319f UD |
145 | static __inline__ char * |
146 | __attribute__ ((__always_inline__)) | |
147 | __strncpy_ichk (char *__restrict __dest, const char *__restrict __src, | |
148 | size_t __len) | |
b5cc329c UD |
149 | { |
150 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | |
151 | } | |
152 | ||
153 | ||
154 | #define strcat(dest, src) \ | |
155 | ((__bos (dest) != (size_t) -1) \ | |
156 | ? __builtin___strcat_chk (dest, src, __bos (dest)) \ | |
157 | : __strcat_ichk (dest, src)) | |
a334319f UD |
158 | static __inline__ char * |
159 | __attribute__ ((__always_inline__)) | |
160 | __strcat_ichk (char *__restrict __dest, const char *__restrict __src) | |
b5cc329c UD |
161 | { |
162 | return __builtin___strcat_chk (__dest, __src, __bos (__dest)); | |
163 | } | |
164 | ||
165 | ||
166 | #define strncat(dest, src, len) \ | |
167 | ((__bos (dest) != (size_t) -1) \ | |
168 | ? __builtin___strncat_chk (dest, src, len, __bos (dest)) \ | |
169 | : __strncat_ichk (dest, src, len)) | |
a334319f UD |
170 | static __inline__ char * |
171 | __attribute__ ((__always_inline__)) | |
172 | __strncat_ichk (char *__restrict __dest, const char *__restrict __src, | |
173 | size_t __len) | |
b5cc329c UD |
174 | { |
175 | return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest)); | |
176 | } |