summaryrefslogtreecommitdiff
path: root/include/wchar.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/wchar.h')
-rw-r--r--include/wchar.h101
1 files changed, 35 insertions, 66 deletions
diff --git a/include/wchar.h b/include/wchar.h
index e2d56e8..33f1fbf 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -5,6 +5,7 @@
5#include_next <wchar.h> 5#include_next <wchar.h>
6 6
7#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 7#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
8#include "fortify-headers.h"
8 9
9#ifdef __cplusplus 10#ifdef __cplusplus
10extern "C" { 11extern "C" {
@@ -25,34 +26,30 @@ extern "C" {
25#undef wmemmove 26#undef wmemmove
26#undef wmemset 27#undef wmemset
27 28
28__typeof__(fgetws) __fgetws_orig __asm__(__USER_LABEL_PREFIX__ "fgetws"); 29fortify_fn(fgetws) wchar_t *fgetws(wchar_t *s, int n, FILE *fp)
29extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
30wchar_t *fgetws(wchar_t *s, int n, FILE *fp)
31{ 30{
32 size_t bos = __builtin_object_size(s, 0); 31 size_t bos = __builtin_object_size(s, 0);
33 32
34 if ((size_t)n > bos / sizeof(wchar_t)) 33 if ((size_t)n > bos / sizeof(wchar_t))
35 __builtin_trap(); 34 __builtin_trap();
36 return __fgetws_orig(s, n, fp); 35 return __orig_fgetws(s, n, fp);
37} 36}
38 37
39#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 38#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
40 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 39 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
41#undef mbsnrtowcs 40#undef mbsnrtowcs
42__typeof__(mbsnrtowcs) __mbsnrtowcs_orig __asm__(__USER_LABEL_PREFIX__ "mbsnrtowcs"); 41fortify_fn(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *d, const char **s, size_t n, size_t wn, mbstate_t *st)
43extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
44size_t mbsnrtowcs(wchar_t *d, const char **s, size_t n, size_t wn, mbstate_t *st)
45{ 42{
46 size_t bos = __builtin_object_size(d, 0); 43 size_t bos = __builtin_object_size(d, 0);
47 size_t r; 44 size_t r;
48 45
49 if (wn > n / sizeof(wchar_t)) { 46 if (wn > n / sizeof(wchar_t)) {
50 bos /= sizeof(wchar_t); 47 bos /= sizeof(wchar_t);
51 r = __mbsnrtowcs_orig(d, s, n, wn > bos ? bos : wn, st); 48 r = __orig_mbsnrtowcs(d, s, n, wn > bos ? bos : wn, st);
52 if (bos < wn && d && *s && r != (size_t)-1) 49 if (bos < wn && d && *s && r != (size_t)-1)
53 __builtin_trap(); 50 __builtin_trap();
54 } else { 51 } else {
55 r = __mbsnrtowcs_orig(d, s, n > bos ? bos : n, wn, st); 52 r = __orig_mbsnrtowcs(d, s, n > bos ? bos : n, wn, st);
56 if (bos < n && d && *s && r != (size_t)-1) 53 if (bos < n && d && *s && r != (size_t)-1)
57 __builtin_trap(); 54 __builtin_trap();
58 } 55 }
@@ -60,67 +57,55 @@ size_t mbsnrtowcs(wchar_t *d, const char **s, size_t n, size_t wn, mbstate_t *st
60} 57}
61#endif 58#endif
62 59
63__typeof__(mbsrtowcs) __mbsrtowcs_orig __asm__(__USER_LABEL_PREFIX__ "mbsrtowcs"); 60fortify_fn(mbsrtowcs) size_t mbsrtowcs(wchar_t *d, const char **s, size_t wn, mbstate_t *st)
64extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
65size_t mbsrtowcs(wchar_t *d, const char **s, size_t wn, mbstate_t *st)
66{ 61{
67 size_t bos = __builtin_object_size(d, 0); 62 size_t bos = __builtin_object_size(d, 0);
68 size_t r; 63 size_t r;
69 64
70 bos /= sizeof(wchar_t); 65 bos /= sizeof(wchar_t);
71 r = __mbsrtowcs_orig(d, s, wn > bos ? bos : wn, st); 66 r = __orig_mbsrtowcs(d, s, wn > bos ? bos : wn, st);
72 if (bos < wn && d && *s && r != (size_t)-1) 67 if (bos < wn && d && *s && r != (size_t)-1)
73 __builtin_trap(); 68 __builtin_trap();
74 return r; 69 return r;
75} 70}
76 71
77__typeof__(mbstowcs) __mbstowcs_orig __asm__(__USER_LABEL_PREFIX__ "mbstowcs"); 72fortify_fn(mbstowcs) size_t mbstowcs(wchar_t *ws, const char *s, size_t wn)
78extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
79size_t mbstowcs(wchar_t *ws, const char *s, size_t wn)
80{ 73{
81 size_t bos = __builtin_object_size(ws, 0); 74 size_t bos = __builtin_object_size(ws, 0);
82 75
83 if (ws && wn > bos / sizeof(wchar_t)) 76 if (ws && wn > bos / sizeof(wchar_t))
84 __builtin_trap(); 77 __builtin_trap();
85 return __mbstowcs_orig(ws, s, wn); 78 return __orig_mbstowcs(ws, s, wn);
86} 79}
87 80
88__typeof__(wcrtomb) __wcrtomb_orig __asm__(__USER_LABEL_PREFIX__ "wcrtomb"); 81fortify_fn(wcrtomb) size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st)
89extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
90size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st)
91{ 82{
92 size_t bos = __builtin_object_size(s, 0); 83 size_t bos = __builtin_object_size(s, 0);
93 84
94 if (s && MB_CUR_MAX > bos) 85 if (s && MB_CUR_MAX > bos)
95 __builtin_trap(); 86 __builtin_trap();
96 return __wcrtomb_orig(s, wc, st); 87 return __orig_wcrtomb(s, wc, st);
97} 88}
98 89
99__typeof__(wcscat) __wcscat_orig __asm__(__USER_LABEL_PREFIX__ "wcscat"); 90fortify_fn(wcscat) wchar_t *wcscat(wchar_t *d, const wchar_t *s)
100extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
101wchar_t *wcscat(wchar_t *d, const wchar_t *s)
102{ 91{
103 size_t bos = __builtin_object_size(d, 0); 92 size_t bos = __builtin_object_size(d, 0);
104 93
105 if (wcslen(s) + wcslen(d) + 1 > bos / sizeof(wchar_t)) 94 if (wcslen(s) + wcslen(d) + 1 > bos / sizeof(wchar_t))
106 __builtin_trap(); 95 __builtin_trap();
107 return __wcscat_orig(d, s); 96 return __orig_wcscat(d, s);
108} 97}
109 98
110__typeof__(wcscpy) __wcscpy_orig __asm__(__USER_LABEL_PREFIX__ "wcscpy"); 99fortify_fn(wcscpy) wchar_t *wcscpy(wchar_t *d, const wchar_t *s)
111extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
112wchar_t *wcscpy(wchar_t *d, const wchar_t *s)
113{ 100{
114 size_t bos = __builtin_object_size(d, 0); 101 size_t bos = __builtin_object_size(d, 0);
115 102
116 if (wcslen(s) + 1 > bos / sizeof(wchar_t)) 103 if (wcslen(s) + 1 > bos / sizeof(wchar_t))
117 __builtin_trap(); 104 __builtin_trap();
118 return __wcscpy_orig(d, s); 105 return __orig_wcscpy(d, s);
119} 106}
120 107
121__typeof__(wcsncat) __wcsncat_orig __asm__(__USER_LABEL_PREFIX__ "wcsncat"); 108fortify_fn(wcsncat) wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n)
122extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
123wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n)
124{ 109{
125 size_t bos = __builtin_object_size(d, 0); 110 size_t bos = __builtin_object_size(d, 0);
126 size_t slen, dlen; 111 size_t slen, dlen;
@@ -133,37 +118,33 @@ wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n)
133 if (slen + dlen + 1 > bos / sizeof(wchar_t)) 118 if (slen + dlen + 1 > bos / sizeof(wchar_t))
134 __builtin_trap(); 119 __builtin_trap();
135 } 120 }
136 return __wcsncat_orig(d, s, n); 121 return __orig_wcsncat(d, s, n);
137} 122}
138 123
139__typeof__(wcsncpy) __wcsncpy_orig __asm__(__USER_LABEL_PREFIX__ "wcsncpy"); 124fortify_fn(wcsncpy) wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n)
140extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
141wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n)
142{ 125{
143 size_t bos = __builtin_object_size(d, 0); 126 size_t bos = __builtin_object_size(d, 0);
144 127
145 if (n > bos / sizeof(wchar_t)) 128 if (n > bos / sizeof(wchar_t))
146 __builtin_trap(); 129 __builtin_trap();
147 return __wcsncpy_orig(d, s, n); 130 return __orig_wcsncpy(d, s, n);
148} 131}
149 132
150#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 133#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
151 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 134 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
152#undef wcsnrtombs 135#undef wcsnrtombs
153__typeof__(wcsnrtombs) __wcsnrtombs_orig __asm__(__USER_LABEL_PREFIX__ "wcsnrtombs"); 136fortify_fn(wcsnrtombs) size_t wcsnrtombs(char *d, const wchar_t **s, size_t wn, size_t n, mbstate_t *st)
154extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
155size_t wcsnrtombs(char *d, const wchar_t **s, size_t wn, size_t n, mbstate_t *st)
156{ 137{
157 size_t bos = __builtin_object_size(d, 0); 138 size_t bos = __builtin_object_size(d, 0);
158 size_t r; 139 size_t r;
159 140
160 if (wn > n / sizeof(wchar_t)) { 141 if (wn > n / sizeof(wchar_t)) {
161 bos /= sizeof(wchar_t); 142 bos /= sizeof(wchar_t);
162 r = __wcsnrtombs_orig(d, s, wn > bos ? bos : wn, n, st); 143 r = __orig_wcsnrtombs(d, s, wn > bos ? bos : wn, n, st);
163 if (bos < wn && d && *s && r != (size_t)-1) 144 if (bos < wn && d && *s && r != (size_t)-1)
164 __builtin_trap(); 145 __builtin_trap();
165 } else { 146 } else {
166 r = __wcsnrtombs_orig(d, s, wn, n > bos ? bos : n, st); 147 r = __orig_wcsnrtombs(d, s, wn, n > bos ? bos : n, st);
167 if (bos < n && d && *s && r != (size_t)-1) 148 if (bos < n && d && *s && r != (size_t)-1)
168 __builtin_trap(); 149 __builtin_trap();
169 } 150 }
@@ -171,72 +152,60 @@ size_t wcsnrtombs(char *d, const wchar_t **s, size_t wn, size_t n, mbstate_t *st
171} 152}
172#endif 153#endif
173 154
174__typeof__(wcsrtombs) __wcsrtombs_orig __asm__(__USER_LABEL_PREFIX__ "wcsrtombs"); 155fortify_fn(wcsrtombs) size_t wcsrtombs(char *d, const wchar_t **s, size_t n, mbstate_t *st)
175extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
176size_t wcsrtombs(char *d, const wchar_t **s, size_t n, mbstate_t *st)
177{ 156{
178 size_t bos = __builtin_object_size(d, 0); 157 size_t bos = __builtin_object_size(d, 0);
179 size_t r; 158 size_t r;
180 159
181 r = __wcsrtombs_orig(d, s, n > bos ? bos : n, st); 160 r = __orig_wcsrtombs(d, s, n > bos ? bos : n, st);
182 if (bos < n && d && *s && r != (size_t)-1) 161 if (bos < n && d && *s && r != (size_t)-1)
183 __builtin_trap(); 162 __builtin_trap();
184 return r; 163 return r;
185} 164}
186 165
187__typeof__(wcstombs) __wcstombs_orig __asm__(__USER_LABEL_PREFIX__ "wcstombs"); 166fortify_fn(wcstombs) size_t wcstombs(char *s, const wchar_t *ws, size_t n)
188extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
189size_t wcstombs(char *s, const wchar_t *ws, size_t n)
190{ 167{
191 size_t bos = __builtin_object_size(s, 0); 168 size_t bos = __builtin_object_size(s, 0);
192 169
193 if (s && n > bos) 170 if (s && n > bos)
194 __builtin_trap(); 171 __builtin_trap();
195 return __wcstombs_orig(s, ws, n); 172 return __orig_wcstombs(s, ws, n);
196} 173}
197 174
198__typeof__(wctomb) __wctomb_orig __asm__(__USER_LABEL_PREFIX__ "wctomb"); 175fortify_fn(wctomb) int wctomb(char *s, wchar_t wc)
199extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
200int wctomb(char *s, wchar_t wc)
201{ 176{
202 size_t bos = __builtin_object_size(s, 0); 177 size_t bos = __builtin_object_size(s, 0);
203 178
204 if (s && MB_CUR_MAX > bos) 179 if (s && MB_CUR_MAX > bos)
205 __builtin_trap(); 180 __builtin_trap();
206 return __wctomb_orig(s, wc); 181 return __orig_wctomb(s, wc);
207} 182}
208 183
209__typeof__(wmemcpy) __wmemcpy_orig __asm__(__USER_LABEL_PREFIX__ "wmemcpy"); 184fortify_fn(wmemcpy) wchar_t *wmemcpy(wchar_t *d, const wchar_t *s, size_t n)
210extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
211wchar_t *wmemcpy(wchar_t *d, const wchar_t *s, size_t n)
212{ 185{
213 size_t bos = __builtin_object_size(d, 0); 186 size_t bos = __builtin_object_size(d, 0);
214 187
215 if (n > bos / sizeof(wchar_t)) 188 if (n > bos / sizeof(wchar_t))
216 __builtin_trap(); 189 __builtin_trap();
217 return __wmemcpy_orig(d, s, n); 190 return __orig_wmemcpy(d, s, n);
218} 191}
219 192
220__typeof__(wmemmove) __wmemmove_orig __asm__(__USER_LABEL_PREFIX__ "wmemmove"); 193fortify_fn(wmemmove) wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n)
221extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
222wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n)
223{ 194{
224 size_t bos = __builtin_object_size(d, 0); 195 size_t bos = __builtin_object_size(d, 0);
225 196
226 if (n > bos / sizeof(wchar_t)) 197 if (n > bos / sizeof(wchar_t))
227 __builtin_trap(); 198 __builtin_trap();
228 return __wmemmove_orig(d, s, n); 199 return __orig_wmemmove(d, s, n);
229} 200}
230 201
231__typeof__(wmemset) __wmemset_orig __asm__(__USER_LABEL_PREFIX__ "wmemset"); 202fortify_fn(wmemset) wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n)
232extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
233wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n)
234{ 203{
235 size_t bos = __builtin_object_size(s, 0); 204 size_t bos = __builtin_object_size(s, 0);
236 205
237 if (n > bos / sizeof(wchar_t)) 206 if (n > bos / sizeof(wchar_t))
238 __builtin_trap(); 207 __builtin_trap();
239 return __wmemset_orig(s, c, n); 208 return __orig_wmemset(s, c, n);
240} 209}
241 210
242#ifdef __cplusplus 211#ifdef __cplusplus