OSDN Git Service

d214785a05c179b0b3f6beb5a5a0d79ff6aec5b1
[pf3gnuchains/gcc-fork.git] / libssp / ssp / string.h
1 /* Checking macros for string functions.
2    Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file.  (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
18 executable.)
19
20 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with GCC; see the file COPYING.  If not, write to the Free
27 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 02111-1307, USA.  */
29
30 /* As a special exception, if you link this library with files compiled with
31    GCC to produce an executable, this does not cause the resulting executable
32    to be covered by the GNU General Public License. This exception does not
33    however invalidate any other reasons why the executable file might be
34    covered by the GNU General Public License.  */
35
36 #ifndef _SSP_STRING_H
37 #define _SSP_STRING_H 1
38
39 #include <ssp.h>
40 #include_next <string.h>
41
42 #if __SSP_FORTIFY_LEVEL > 0
43
44 #undef memcpy
45 #undef memmove
46 #undef memset
47 #undef strcat
48 #undef strcpy
49 #undef strncat
50 #undef strncpy
51 #undef mempcpy
52 #undef stpcpy
53 #undef bcopy
54 #undef bzero
55
56 #define memcpy(dest, src, len) \
57   ((__ssp_bos0 (dest) != (size_t) -1)                                   \
58    ? __builtin___memcpy_chk (dest, src, len, __ssp_bos0 (dest))         \
59    : __memcpy_ichk (dest, src, len))
60 static inline __attribute__((__always_inline__)) void *
61 __memcpy_ichk (void *__restrict__ __dest, const void *__restrict__ __src,
62                size_t __len)
63 {
64   return __builtin___memcpy_chk (__dest, __src, __len, __ssp_bos0 (__dest));
65 }
66
67
68 #define memmove(dest, src, len) \
69   ((__ssp_bos0 (dest) != (size_t) -1)                                   \
70    ? __builtin___memmove_chk (dest, src, len, __ssp_bos0 (dest))                \
71    : __memmove_ichk (dest, src, len))
72 static inline __attribute__((__always_inline__)) void *
73 __memmove_ichk (void *__dest, const void *__src, size_t __len)
74 {
75   return __builtin___memmove_chk (__dest, __src, __len, __ssp_bos0 (__dest));
76 }
77
78
79 #define mempcpy(dest, src, len) \
80   ((__ssp_bos0 (dest) != (size_t) -1)                                   \
81    ? __builtin___mempcpy_chk (dest, src, len, __ssp_bos0 (dest))        \
82    : __mempcpy_ichk (dest, src, len))
83 static inline __attribute__((__always_inline__)) void *
84 __mempcpy_ichk (void *__restrict__ __dest, const void *__restrict__ __src,
85                 size_t __len)
86 {
87   return __builtin___mempcpy_chk (__dest, __src, __len, __ssp_bos0 (__dest));
88 }
89
90
91 #define memset(dest, ch, len) \
92   ((__ssp_bos0 (dest) != (size_t) -1)                                   \
93    ? __builtin___memset_chk (dest, ch, len, __ssp_bos0 (dest))          \
94    : __memset_ichk (dest, ch, len))
95 static inline __attribute__((__always_inline__)) void *
96 __memset_ichk (void *__dest, int __ch, size_t __len)
97 {
98   return __builtin___memset_chk (__dest, __ch, __len, __ssp_bos0 (__dest));
99 }
100
101 #define bcopy(src, dest, len) ((void) \
102  ((__ssp_bos0 (dest) != (size_t) -1)                                    \
103    ? __builtin___memmove_chk (dest, src, len, __ssp_bos0 (dest))        \
104    : __memmove_ichk (dest, src, len)))
105 #define bzero(dest, len) ((void) \
106   ((__ssp_bos0 (dest) != (size_t) -1)                                   \
107    ? __builtin___memset_chk (dest, '\0', len, __ssp_bos0 (dest))        \
108    : __memset_ichk (dest, '\0', len)))
109
110
111 #define strcpy(dest, src) \
112   ((__ssp_bos (dest) != (size_t) -1)                                    \
113    ? __builtin___strcpy_chk (dest, src, __ssp_bos (dest))               \
114    : __strcpy_ichk (dest, src))
115 static inline __attribute__((__always_inline__)) char *
116 __strcpy_ichk (char *__restrict__ __dest, const char *__restrict__ __src)
117 {
118   return __builtin___strcpy_chk (__dest, __src, __ssp_bos (__dest));
119 }
120
121
122 #define stpcpy(dest, src) \
123   ((__ssp_bos (dest) != (size_t) -1)                                    \
124    ? __builtin___stpcpy_chk (dest, src, __ssp_bos (dest))               \
125    : __stpcpy_ichk (dest, src))
126 static inline __attribute__((__always_inline__)) char *
127 __stpcpy_ichk (char *__restrict__ __dest, const char *__restrict__ __src)
128 {
129   return __builtin___stpcpy_chk (__dest, __src, __ssp_bos (__dest));
130 }
131
132
133 #define strncpy(dest, src, len) \
134   ((__ssp_bos (dest) != (size_t) -1)                                    \
135    ? __builtin___strncpy_chk (dest, src, len, __ssp_bos (dest))         \
136    : __strncpy_ichk (dest, src, len))
137 static inline __attribute__((__always_inline__)) char *
138 __strncpy_ichk (char *__restrict__ __dest, const char *__restrict__ __src,
139                 size_t __len)
140 {
141   return __builtin___strncpy_chk (__dest, __src, __len, __ssp_bos (__dest));
142 }
143
144
145 #define strcat(dest, src) \
146   ((__ssp_bos (dest) != (size_t) -1)                                    \
147    ? __builtin___strcat_chk (dest, src, __ssp_bos (dest))               \
148    : __strcat_ichk (dest, src))
149 static inline __attribute__((__always_inline__)) char *
150 __strcat_ichk (char *__restrict__ __dest, const char *__restrict__ __src)
151 {
152   return __builtin___strcat_chk (__dest, __src, __ssp_bos (__dest));
153 }
154
155
156 #define strncat(dest, src, len) \
157   ((__ssp_bos (dest) != (size_t) -1)                                    \
158    ? __builtin___strncat_chk (dest, src, len, __ssp_bos (dest))         \
159    : __strncat_ichk (dest, src, len))
160 static inline __attribute__((__always_inline__)) char *
161 __strncat_ichk (char *__restrict__ __dest, const char *__restrict__ __src,
162                 size_t __len)
163 {
164   return __builtin___strncat_chk (__dest, __src, __len, __ssp_bos (__dest));
165 }
166
167 #endif /* __SSP_FORTIFY_LEVEL > 0 */
168 #endif /* _SSP_STRING_H */