]>
Commit | Line | Data |
---|---|---|
77008252 | 1 | /* Checking macros for string functions. |
a945c346 | 2 | Copyright (C) 2004-2024 Free Software Foundation, Inc. |
77008252 JJ |
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 | |
748086b7 | 8 | Software Foundation; either version 3, or (at your option) any later |
77008252 JJ |
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 | ||
748086b7 JJ |
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. | |
28 | ||
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/>. */ | |
77008252 | 33 | |
77008252 JJ |
34 | |
35 | #ifndef _SSP_STRING_H | |
36 | #define _SSP_STRING_H 1 | |
37 | ||
38 | #include <ssp.h> | |
39 | #include_next <string.h> | |
40 | ||
41 | #if __SSP_FORTIFY_LEVEL > 0 | |
42 | ||
43 | #undef memcpy | |
44 | #undef memmove | |
45 | #undef memset | |
46 | #undef strcat | |
47 | #undef strcpy | |
48 | #undef strncat | |
49 | #undef strncpy | |
50 | #undef mempcpy | |
51 | #undef stpcpy | |
52 | #undef bcopy | |
53 | #undef bzero | |
54 | ||
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, | |
61 | size_t __len) | |
62 | { | |
63 | return __builtin___memcpy_chk (__dest, __src, __len, __ssp_bos0 (__dest)); | |
64 | } | |
65 | ||
66 | ||
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) | |
73 | { | |
74 | return __builtin___memmove_chk (__dest, __src, __len, __ssp_bos0 (__dest)); | |
75 | } | |
76 | ||
77 | ||
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, | |
84 | size_t __len) | |
85 | { | |
86 | return __builtin___mempcpy_chk (__dest, __src, __len, __ssp_bos0 (__dest)); | |
87 | } | |
88 | ||
89 | ||
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) | |
96 | { | |
97 | return __builtin___memset_chk (__dest, __ch, __len, __ssp_bos0 (__dest)); | |
98 | } | |
99 | ||
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))) | |
108 | ||
109 | ||
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) | |
116 | { | |
117 | return __builtin___strcpy_chk (__dest, __src, __ssp_bos (__dest)); | |
118 | } | |
119 | ||
120 | ||
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) | |
127 | { | |
128 | return __builtin___stpcpy_chk (__dest, __src, __ssp_bos (__dest)); | |
129 | } | |
130 | ||
131 | ||
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, | |
138 | size_t __len) | |
139 | { | |
140 | return __builtin___strncpy_chk (__dest, __src, __len, __ssp_bos (__dest)); | |
141 | } | |
142 | ||
143 | ||
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) | |
150 | { | |
151 | return __builtin___strcat_chk (__dest, __src, __ssp_bos (__dest)); | |
152 | } | |
153 | ||
154 | ||
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, | |
161 | size_t __len) | |
162 | { | |
163 | return __builtin___strncat_chk (__dest, __src, __len, __ssp_bos (__dest)); | |
164 | } | |
165 | ||
166 | #endif /* __SSP_FORTIFY_LEVEL > 0 */ | |
167 | #endif /* _SSP_STRING_H */ |