1 /* Checking macros for string functions.
2 Copyright (C) 2004-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
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 3, or (at your option) any later
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
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
25 Under Section 7 of GPL version 3, you are granted additional
26 permissions described in the GCC Runtime Library Exception, version
27 3.1, as published by the Free Software Foundation.
29 You should have received a copy of the GNU General Public License and
30 a copy of the GCC Runtime Library Exception along with this program;
31 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
32 <http://www.gnu.org/licenses/>. */
36 #define _SSP_STRING_H 1
39 #include_next <string.h>
41 #if __SSP_FORTIFY_LEVEL > 0
55 #define memcpy(dest, src, len) \
56 ((__ssp_bos0 (dest) != (size_t) -1) \
57 ? __builtin___memcpy_chk (dest, src, len, __ssp_bos0 (dest)) \
58 : __memcpy_ichk (dest, src, len))
59 static inline __attribute__((__always_inline__
)) void *
60 __memcpy_ichk (void *__restrict__ __dest
, const void *__restrict__ __src
,
63 return __builtin___memcpy_chk (__dest
, __src
, __len
, __ssp_bos0 (__dest
));
67 #define memmove(dest, src, len) \
68 ((__ssp_bos0 (dest) != (size_t) -1) \
69 ? __builtin___memmove_chk (dest, src, len, __ssp_bos0 (dest)) \
70 : __memmove_ichk (dest, src, len))
71 static inline __attribute__((__always_inline__
)) void *
72 __memmove_ichk (void *__dest
, const void *__src
, size_t __len
)
74 return __builtin___memmove_chk (__dest
, __src
, __len
, __ssp_bos0 (__dest
));
78 #define mempcpy(dest, src, len) \
79 ((__ssp_bos0 (dest) != (size_t) -1) \
80 ? __builtin___mempcpy_chk (dest, src, len, __ssp_bos0 (dest)) \
81 : __mempcpy_ichk (dest, src, len))
82 static inline __attribute__((__always_inline__
)) void *
83 __mempcpy_ichk (void *__restrict__ __dest
, const void *__restrict__ __src
,
86 return __builtin___mempcpy_chk (__dest
, __src
, __len
, __ssp_bos0 (__dest
));
90 #define memset(dest, ch, len) \
91 ((__ssp_bos0 (dest) != (size_t) -1) \
92 ? __builtin___memset_chk (dest, ch, len, __ssp_bos0 (dest)) \
93 : __memset_ichk (dest, ch, len))
94 static inline __attribute__((__always_inline__
)) void *
95 __memset_ichk (void *__dest
, int __ch
, size_t __len
)
97 return __builtin___memset_chk (__dest
, __ch
, __len
, __ssp_bos0 (__dest
));
100 #define bcopy(src, dest, len) ((void) \
101 ((__ssp_bos0 (dest) != (size_t) -1) \
102 ? __builtin___memmove_chk (dest, src, len, __ssp_bos0 (dest)) \
103 : __memmove_ichk (dest, src, len)))
104 #define bzero(dest, len) ((void) \
105 ((__ssp_bos0 (dest) != (size_t) -1) \
106 ? __builtin___memset_chk (dest, '\0', len, __ssp_bos0 (dest)) \
107 : __memset_ichk (dest, '\0', len)))
110 #define strcpy(dest, src) \
111 ((__ssp_bos (dest) != (size_t) -1) \
112 ? __builtin___strcpy_chk (dest, src, __ssp_bos (dest)) \
113 : __strcpy_ichk (dest, src))
114 static inline __attribute__((__always_inline__
)) char *
115 __strcpy_ichk (char *__restrict__ __dest
, const char *__restrict__ __src
)
117 return __builtin___strcpy_chk (__dest
, __src
, __ssp_bos (__dest
));
121 #define stpcpy(dest, src) \
122 ((__ssp_bos (dest) != (size_t) -1) \
123 ? __builtin___stpcpy_chk (dest, src, __ssp_bos (dest)) \
124 : __stpcpy_ichk (dest, src))
125 static inline __attribute__((__always_inline__
)) char *
126 __stpcpy_ichk (char *__restrict__ __dest
, const char *__restrict__ __src
)
128 return __builtin___stpcpy_chk (__dest
, __src
, __ssp_bos (__dest
));
132 #define strncpy(dest, src, len) \
133 ((__ssp_bos (dest) != (size_t) -1) \
134 ? __builtin___strncpy_chk (dest, src, len, __ssp_bos (dest)) \
135 : __strncpy_ichk (dest, src, len))
136 static inline __attribute__((__always_inline__
)) char *
137 __strncpy_ichk (char *__restrict__ __dest
, const char *__restrict__ __src
,
140 return __builtin___strncpy_chk (__dest
, __src
, __len
, __ssp_bos (__dest
));
144 #define strcat(dest, src) \
145 ((__ssp_bos (dest) != (size_t) -1) \
146 ? __builtin___strcat_chk (dest, src, __ssp_bos (dest)) \
147 : __strcat_ichk (dest, src))
148 static inline __attribute__((__always_inline__
)) char *
149 __strcat_ichk (char *__restrict__ __dest
, const char *__restrict__ __src
)
151 return __builtin___strcat_chk (__dest
, __src
, __ssp_bos (__dest
));
155 #define strncat(dest, src, len) \
156 ((__ssp_bos (dest) != (size_t) -1) \
157 ? __builtin___strncat_chk (dest, src, len, __ssp_bos (dest)) \
158 : __strncat_ichk (dest, src, len))
159 static inline __attribute__((__always_inline__
)) char *
160 __strncat_ichk (char *__restrict__ __dest
, const char *__restrict__ __src
,
163 return __builtin___strncat_chk (__dest
, __src
, __len
, __ssp_bos (__dest
));
166 #endif /* __SSP_FORTIFY_LEVEL > 0 */
167 #endif /* _SSP_STRING_H */