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