* soft-fp/soft-fp.h (CMPtype): Define to "int" if undefined.
[glibc.git] / string / bits / string3.h
blobf68ce5899f1661d863714e459336f6e625cb8e92
1 /* Copyright (C) 2004, 2005, 2007 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
17 02111-1307 USA. */
19 #ifndef _STRING_H
20 # error "Never use <bits/string3.h> directly; include <string.h> instead."
21 #endif
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
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 __always_inline void *
48 __NTH (__memcpy_ichk (void *__restrict __dest, __const void *__restrict __src,
49 size_t __len))
51 return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
55 #define memmove(dest, src, len) \
56 ((__bos0 (dest) != (size_t) -1) \
57 ? __builtin___memmove_chk (dest, src, len, __bos0 (dest)) \
58 : __memmove_ichk (dest, src, len))
59 static __always_inline void *
60 __NTH (__memmove_ichk (void *__dest, __const void *__src, size_t __len))
62 return __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
66 #ifdef __USE_GNU
67 # define mempcpy(dest, src, len) \
68 ((__bos0 (dest) != (size_t) -1) \
69 ? __builtin___mempcpy_chk (dest, src, len, __bos0 (dest)) \
70 : __mempcpy_ichk (dest, src, len))
71 static __always_inline void *
72 __NTH (__mempcpy_ichk (void *__restrict __dest,
73 __const void *__restrict __src, size_t __len))
75 return __builtin___mempcpy_chk (__dest, __src, __len, __bos0 (__dest));
77 #endif
80 /* The first two tests here help to catch a somewhat common problem
81 where the second and third parameter are transposed. This is
82 especially problematic if the intended fill value is zero. In this
83 case no work is done at all. We detect these problems by referring
84 non-existing functions. */
85 __warndecl (__warn_memset_zero_len,
86 "memset used with constant zero length parameter; this could be due to transposed parameters");
87 #define memset(dest, ch, len) \
88 (__builtin_constant_p (len) && (len) == 0 \
89 ? (__warn_memset_zero_len (), (void) (ch), (void) (len), (void *) (dest)) \
90 : ((__bos0 (dest) != (size_t) -1) \
91 ? __builtin___memset_chk (dest, ch, len, __bos0 (dest)) \
92 : __memset_ichk (dest, ch, len)))
93 static __always_inline void *
94 __NTH (__memset_ichk (void *__dest, int __ch, size_t __len))
96 return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
99 #ifdef __USE_BSD
100 # define bcopy(src, dest, len) ((void) \
101 ((__bos0 (dest) != (size_t) -1) \
102 ? __builtin___memmove_chk (dest, src, len, __bos0 (dest)) \
103 : __memmove_ichk (dest, src, len)))
104 # define bzero(dest, len) ((void) \
105 ((__bos0 (dest) != (size_t) -1) \
106 ? __builtin___memset_chk (dest, '\0', len, __bos0 (dest)) \
107 : __memset_ichk (dest, '\0', len)))
108 #endif
111 #define strcpy(dest, src) \
112 ((__bos (dest) != (size_t) -1) \
113 ? __builtin___strcpy_chk (dest, src, __bos (dest)) \
114 : __strcpy_ichk (dest, src))
115 static __always_inline char *
116 __NTH (__strcpy_ichk (char *__restrict __dest, __const char *__restrict __src))
118 return __builtin___strcpy_chk (__dest, __src, __bos (__dest));
122 #ifdef __USE_GNU
123 # define stpcpy(dest, src) \
124 ((__bos (dest) != (size_t) -1) \
125 ? __builtin___stpcpy_chk (dest, src, __bos (dest)) \
126 : __stpcpy_ichk (dest, src))
127 static __always_inline char *
128 __NTH (__stpcpy_ichk (char *__restrict __dest, __const char *__restrict __src))
130 return __builtin___stpcpy_chk (__dest, __src, __bos (__dest));
132 #endif
135 #define strncpy(dest, src, len) \
136 ((__bos (dest) != (size_t) -1) \
137 ? __builtin___strncpy_chk (dest, src, len, __bos (dest)) \
138 : __strncpy_ichk (dest, src, len))
139 static __always_inline char *
140 __NTH (__strncpy_ichk (char *__restrict __dest, __const char *__restrict __src,
141 size_t __len))
143 return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
147 // XXX We have no corresponding builtin yet.
148 extern char *__stpncpy_chk (char *__dest, __const char *__src, size_t __n,
149 size_t __destlen) __THROW;
150 extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest,
151 __const char *__src,
152 size_t __n), stpncpy);
154 __extern_always_inline char *
155 __NTH (stpncpy (char *__dest, __const char *__src, size_t __n))
157 if (__bos (__dest) != (size_t) -1
158 && (!__builtin_constant_p (__n) || __n <= __bos (__dest)))
159 return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
160 return __stpncpy_alias (__dest, __src, __n);
164 #define strcat(dest, src) \
165 ((__bos (dest) != (size_t) -1) \
166 ? __builtin___strcat_chk (dest, src, __bos (dest)) \
167 : __strcat_ichk (dest, src))
168 static __always_inline char *
169 __NTH (__strcat_ichk (char *__restrict __dest, __const char *__restrict __src))
171 return __builtin___strcat_chk (__dest, __src, __bos (__dest));
175 #define strncat(dest, src, len) \
176 ((__bos (dest) != (size_t) -1) \
177 ? __builtin___strncat_chk (dest, src, len, __bos (dest)) \
178 : __strncat_ichk (dest, src, len))
179 static __always_inline char *
180 __NTH (__strncat_ichk (char *__restrict __dest, __const char *__restrict __src,
181 size_t __len))
183 return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));