]>
git.ipfire.org Git - thirdparty/glibc.git/blob - string/bits/string3.h
1 /* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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
20 # error "Never use <bits/string3.h> directly; include <string.h> instead."
23 /* XXX This is temporarily. We should not redefine any of the symbols
24 and instead integrate the error checking into the original
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))
47 static __inline__
void *
48 __attribute__ ((__always_inline__
))
49 __memcpy_ichk (void *__restrict __dest
, const void *__restrict __src
,
52 return __builtin___memcpy_chk (__dest
, __src
, __len
, __bos0 (__dest
));
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))
60 static __inline__
void *
61 __attribute__ ((__always_inline__
))
62 __memmove_ichk (void *__dest
, const void *__src
, size_t __len
)
64 return __builtin___memmove_chk (__dest
, __src
, __len
, __bos0 (__dest
));
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))
73 static __inline__
void *
74 __attribute__ ((__always_inline__
))
75 __mempcpy_ichk (void *__restrict __dest
, const void *__restrict __src
,
78 return __builtin___mempcpy_chk (__dest
, __src
, __len
, __bos0 (__dest
));
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,
90 #define memset(dest, ch, len) \
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)))
96 static __inline__
void *
97 __attribute__ ((__always_inline__
))
98 __memset_ichk (void *__dest
, int __ch
, size_t __len
)
100 return __builtin___memset_chk (__dest
, __ch
, __len
, __bos0 (__dest
));
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)))
115 #define strcpy(dest, src) \
116 ((__bos (dest) != (size_t) -1) \
117 ? __builtin___strcpy_chk (dest, src, __bos (dest)) \
118 : __strcpy_ichk (dest, src))
119 static __inline__
char *
120 __attribute__ ((__always_inline__
))
121 __strcpy_ichk (char *__restrict __dest
, const char *__restrict __src
)
123 return __builtin___strcpy_chk (__dest
, __src
, __bos (__dest
));
128 # define stpcpy(dest, src) \
129 ((__bos (dest) != (size_t) -1) \
130 ? __builtin___stpcpy_chk (dest, src, __bos (dest)) \
131 : __stpcpy_ichk (dest, src))
132 static __inline__
char *
133 __attribute__ ((__always_inline__
))
134 __stpcpy_ichk (char *__restrict __dest
, const char *__restrict __src
)
136 return __builtin___stpcpy_chk (__dest
, __src
, __bos (__dest
));
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))
145 static __inline__
char *
146 __attribute__ ((__always_inline__
))
147 __strncpy_ichk (char *__restrict __dest
, const char *__restrict __src
,
150 return __builtin___strncpy_chk (__dest
, __src
, __len
, __bos (__dest
));
154 #define strcat(dest, src) \
155 ((__bos (dest) != (size_t) -1) \
156 ? __builtin___strcat_chk (dest, src, __bos (dest)) \
157 : __strcat_ichk (dest, src))
158 static __inline__
char *
159 __attribute__ ((__always_inline__
))
160 __strcat_ichk (char *__restrict __dest
, const char *__restrict __src
)
162 return __builtin___strcat_chk (__dest
, __src
, __bos (__dest
));
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))
170 static __inline__
char *
171 __attribute__ ((__always_inline__
))
172 __strncat_ichk (char *__restrict __dest
, const char *__restrict __src
,
175 return __builtin___strncat_chk (__dest
, __src
, __len
, __bos (__dest
));