summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/poll.h6
-rw-r--r--include/stdio.h26
-rw-r--r--include/stdlib.h15
-rw-r--r--include/string.h6
-rw-r--r--include/strings.h4
-rw-r--r--include/unistd.h39
-rw-r--r--include/wchar.h48
7 files changed, 144 insertions, 0 deletions
diff --git a/include/poll.h b/include/poll.h
index 8e8de6c..8831f95 100644
--- a/include/poll.h
+++ b/include/poll.h
@@ -31,6 +31,9 @@ extern "C" {
31 31
32#undef poll 32#undef poll
33 33
34#if __has_builtin(__builtin_poll)
35__diagnose_as_builtin(__builtin_poll, 1, 2, 3)
36#endif
34_FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __s) 37_FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __s)
35{ 38{
36 size_t __b = __bos(__f, 0); 39 size_t __b = __bos(__f, 0);
@@ -42,6 +45,9 @@ _FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __
42 45
43#if defined(_GNU_SOURCE) && !_REDIR_TIME64 46#if defined(_GNU_SOURCE) && !_REDIR_TIME64
44#undef ppoll 47#undef ppoll
48#if __has_builtin(__builtin_ppoll)
49__diagnose_as_builtin(__builtin_ppoll, 1, 2, 3, 4)
50#endif
45_FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, 51_FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n,
46 const struct timespec *__s, const sigset_t *__m) 52 const struct timespec *__s, const sigset_t *__m)
47{ 53{
diff --git a/include/stdio.h b/include/stdio.h
index 000a72d..582be4f 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -40,12 +40,18 @@ extern "C" {
40#undef vsprintf 40#undef vsprintf
41 41
42__access(read_only, 2) 42__access(read_only, 2)
43#if __has_builtin(__builtin_fdopen)
44__diagnose_as_builtin(__builtin_fdopen, 1, 2)
45#endif
43_FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m) 46_FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m)
44{ 47{
45 return __orig_fdopen(__f, __m); 48 return __orig_fdopen(__f, __m);
46} 49}
47 50
48__access(write_only, 1, 2) 51__access(write_only, 1, 2)
52#if __has_builtin(__builtin_fgets)
53__diagnose_as_builtin(__builtin_fgets, 1, 2, 3)
54#endif
49_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) 55_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
50{ 56{
51 size_t __b = __bos(__s, 0); 57 size_t __b = __bos(__s, 0);
@@ -56,6 +62,9 @@ _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
56} 62}
57 63
58__malloc(malloc (fclose, 1)) 64__malloc(malloc (fclose, 1))
65#if __has_builtin(__builtin_fmemopen)
66__diagnose_as_builtin(__builtin_fmemopen, 1, 2, 3)
67#endif
59_FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m) 68_FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m)
60{ 69{
61 return __orig_fmemopen(__b, __s, __m); 70 return __orig_fmemopen(__b, __s, __m);
@@ -64,12 +73,18 @@ _FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const
64__access(read_only, 1) 73__access(read_only, 1)
65__access(read_only, 2) 74__access(read_only, 2)
66__malloc(malloc (fclose, 1)) 75__malloc(malloc (fclose, 1))
76#if __has_builtin(__builtin_fopen)
77__diagnose_as_builtin(__builtin_fopen, 1, 2)
78#endif
67_FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTIFY_POS0 __m) 79_FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTIFY_POS0 __m)
68{ 80{
69 return __orig_fopen(__p, __m); 81 return __orig_fopen(__p, __m);
70} 82}
71 83
72__access(write_only, 1) 84__access(write_only, 1)
85#if __has_builtin(__builtin_fread)
86__diagnose_as_builtin(__builtin_fread, 1, 2, 3, 4)
87#endif
73_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, 88_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
74 size_t __m, FILE *__f) 89 size_t __m, FILE *__f)
75{ 90{
@@ -83,6 +98,9 @@ _FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
83} 98}
84 99
85__access(read_only, 1) 100__access(read_only, 1)
101#if __has_builtin(__builtin_fwrite)
102__diagnose_as_builtin(__builtin_fwrite, 1, 2, 3, 4)
103#endif
86_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, 104_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
87 size_t __m, FILE *__f) 105 size_t __m, FILE *__f)
88{ 106{
@@ -98,6 +116,9 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
98__access(read_only, 1) 116__access(read_only, 1)
99__access(read_only, 2) 117__access(read_only, 2)
100__malloc(malloc (pclose, 1)) 118__malloc(malloc (pclose, 1))
119#if __has_builtin(__builtin_popen)
120__diagnose_as_builtin(__builtin_popen, 1, 2)
121#endif
101_FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t) 122_FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t)
102{ 123{
103 return __orig_popen(__c, __t); 124 return __orig_popen(__c, __t);
@@ -106,6 +127,9 @@ _FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTI
106#ifndef __clang__ /* FIXME */ 127#ifndef __clang__ /* FIXME */
107#undef tmpfile 128#undef tmpfile
108__malloc(malloc (fclose, 1)) 129__malloc(malloc (fclose, 1))
130#if __has_builtin(__builtin_tmpfile)
131__diagnose_as_builtin(__builtin_tmpfile)
132#endif
109_FORTIFY_FN(tmpfile) FILE *tmpfile(void) 133_FORTIFY_FN(tmpfile) FILE *tmpfile(void)
110{ 134{
111 return __orig_tmpfile(); 135 return __orig_tmpfile();
@@ -162,6 +186,8 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
162 * have the __chk variants, we'd need to implement a body with intermediate 186 * have the __chk variants, we'd need to implement a body with intermediate
163 * variables within the macro, which means more non-portable mess 187 * variables within the macro, which means more non-portable mess
164 * 3) not implementing these under clang, which is what we do for now 188 * 3) not implementing these under clang, which is what we do for now
189 *
190 * TODO: add __diagnose_as_builtin
165 */ 191 */
166 192
167#undef snprintf 193#undef snprintf
diff --git a/include/stdlib.h b/include/stdlib.h
index 734f0e6..d3cd863 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -43,6 +43,9 @@ extern "C" {
43__malloc(malloc (free, 1)) 43__malloc(malloc (free, 1))
44__alloc_size(1) 44__alloc_size(1)
45__warn_unused_result 45__warn_unused_result
46#if __has_builtin(__builtin_malloc)
47__diagnose_as_builtin(__builtin_malloc, 1)
48#endif
46_FORTIFY_FN(malloc) void *malloc(size_t __s) 49_FORTIFY_FN(malloc) void *malloc(size_t __s)
47{ 50{
48 return __orig_malloc(__s); 51 return __orig_malloc(__s);
@@ -50,6 +53,9 @@ _FORTIFY_FN(malloc) void *malloc(size_t __s)
50 53
51__alloc_size(2) 54__alloc_size(2)
52__warn_unused_result 55__warn_unused_result
56#if __has_builtin(__builtin_realloc)
57__diagnose_as_builtin(__builtin_realloc, 1, 2)
58#endif
53_FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s) 59_FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s)
54{ 60{
55 return __orig_realloc(__p, __s); 61 return __orig_realloc(__p, __s);
@@ -57,6 +63,9 @@ _FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s)
57 63
58__alloc_size(1, 2) 64__alloc_size(1, 2)
59__warn_unused_result 65__warn_unused_result
66#if __has_builtin(__builtin_calloc)
67__diagnose_as_builtin(__builtin_calloc, 1, 2)
68#endif
60_FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s) 69_FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s)
61{ 70{
62 return __orig_calloc(__n, __s); 71 return __orig_calloc(__n, __s);
@@ -66,6 +75,9 @@ _FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s)
66#undef reallocarray 75#undef reallocarray
67__alloc_size (2, 3) 76__alloc_size (2, 3)
68__warn_unused_result 77__warn_unused_result
78#if __has_builtin(__builtin_reallocarray)
79__diagnose_as_builtin(__builtin_reallocarray, 1, 2, 3)
80#endif
69_FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s) 81_FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s)
70{ 82{
71 return __orig_reallocarray(__p, __n, __s); 83 return __orig_reallocarray(__p, __n, __s);
@@ -76,6 +88,9 @@ _FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s)
76#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__) 88#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__)
77#undef realpath 89#undef realpath
78__warning_if(__p == NULL, "'realpath' called with path set to `NULL`; did you invert the arguments?") 90__warning_if(__p == NULL, "'realpath' called with path set to `NULL`; did you invert the arguments?")
91#if __has_builtin(__builtin_realpath)
92__diagnose_as_builtin(__builtin_realpath, 1, 2)
93#endif
79_FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) 94_FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r)
80{ 95{
81#ifndef PATH_MAX 96#ifndef PATH_MAX
diff --git a/include/string.h b/include/string.h
index 2735b55..8a440e4 100644
--- a/include/string.h
+++ b/include/string.h
@@ -257,6 +257,9 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
257#undef strlcpy 257#undef strlcpy
258__access (read_write, 1) 258__access (read_write, 1)
259__access (read_only, 2, 3) 259__access (read_only, 2, 3)
260#if __has_builtin(__builtin_strlcat)
261__diagnose_as_builtin(__builtin_strlcat, 1, 2, 3)
262#endif
260_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d, 263_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
261 const char *__s, size_t __n) 264 const char *__s, size_t __n)
262{ 265{
@@ -269,6 +272,9 @@ _FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
269 272
270__access (write_only, 1) 273__access (write_only, 1)
271__access (read_only, 2, 3) 274__access (read_only, 2, 3)
275#if __has_builtin(__builtin_strlcpy)
276__diagnose_as_builtin(__builtin_strlcpy, 1, 2, 3)
277#endif
272_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d, 278_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d,
273 const char *__s, size_t __n) 279 const char *__s, size_t __n)
274{ 280{
diff --git a/include/strings.h b/include/strings.h
index 8b99ccd..c91715d 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -33,6 +33,10 @@ extern "C" {
33#undef bzero 33#undef bzero
34__access(write_only, 2, 3) 34__access(write_only, 2, 3)
35__access(read_only, 1, 3) 35__access(read_only, 1, 3)
36#if __has_builtin(__builtin_bcopy) && !defined(__clang__)
37// parameter 1 of function '__orig_bcopy' has type 'const void *', but parameter 1 of function '__builtin_bcopy' has type 'void *'
38__diagnose_as_builtin(__builtin_bcopy, 1, 2, 3)
39#endif
36_FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s, 40_FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s,
37 void * _FORTIFY_POS0 __d, size_t __n) 41 void * _FORTIFY_POS0 __d, size_t __n)
38{ 42{
diff --git a/include/unistd.h b/include/unistd.h
index 57f0d0c..38c7c9b 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -42,6 +42,9 @@ extern "C" {
42#undef write 42#undef write
43 43
44__access(write_only, 2, 3) 44__access(write_only, 2, 3)
45#if __has_builtin(__builtin_confstr)
46__diagnose_as_builtin(__builtin_confstr, 1, 2, 3)
47#endif
45_FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l) 48_FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l)
46{ 49{
47 size_t __b = __bos(__s, 0); 50 size_t __b = __bos(__s, 0);
@@ -53,6 +56,9 @@ _FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __
53} 56}
54 57
55__access(write_only, 1, 2) 58__access(write_only, 1, 2)
59#if __has_builtin(__builtin_getcwd)
60__diagnose_as_builtin(__builtin_getcwd, 1, 2)
61#endif
56_FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l) 62_FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l)
57{ 63{
58 size_t __b = __bos(__s, 0); 64 size_t __b = __bos(__s, 0);
@@ -65,6 +71,9 @@ _FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l)
65#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 71#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
66#undef getdomainname 72#undef getdomainname
67__access(write_only, 1, 2) 73__access(write_only, 1, 2)
74#if __has_builtin(__builtin_getdomainname)
75__diagnose_as_builtin(__builtin_getdomainname, 1, 2)
76#endif
68_FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l) 77_FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l)
69{ 78{
70 size_t __b = __bos(__s, 0); 79 size_t __b = __bos(__s, 0);
@@ -75,6 +84,9 @@ _FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __
75} 84}
76#endif 85#endif
77 86
87#if __has_builtin(__builtin_getgroups)
88__diagnose_as_builtin(__builtin_getgroups, 1, 2)
89#endif
78_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s) 90_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s)
79{ 91{
80 size_t __b = __bos(__s, 0); 92 size_t __b = __bos(__s, 0);
@@ -85,6 +97,9 @@ _FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s)
85} 97}
86 98
87__access(write_only, 1, 2) 99__access(write_only, 1, 2)
100#if __has_builtin(__builtin_gethostname)
101__diagnose_as_builtin(__builtin_gethostname, 1, 2)
102#endif
88_FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l) 103_FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l)
89{ 104{
90 size_t __b = __bos(__s, 0); 105 size_t __b = __bos(__s, 0);
@@ -95,6 +110,9 @@ _FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l)
95} 110}
96 111
97__access(write_only, 1, 2) 112__access(write_only, 1, 2)
113#if __has_builtin(__builtin_getlogin_r)
114__diagnose_as_builtin(__builtin_getlogin_r, 1, 2)
115#endif
98_FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l) 116_FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l)
99{ 117{
100 size_t __b = __bos(__s, 0); 118 size_t __b = __bos(__s, 0);
@@ -104,6 +122,9 @@ _FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l)
104 return __orig_getlogin_r(__s, __l); 122 return __orig_getlogin_r(__s, __l);
105} 123}
106 124
125#if __has_builtin(__builtin_pread)
126__diagnose_as_builtin(__builtin_pread, 1, 2, 3, 4)
127#endif
107_FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s, 128_FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s,
108 size_t __n, off_t __o) 129 size_t __n, off_t __o)
109{ 130{
@@ -115,6 +136,9 @@ _FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s,
115} 136}
116 137
117__access(write_only, 2, 3) 138__access(write_only, 2, 3)
139#if __has_builtin(__builtin_read)
140__diagnose_as_builtin(__builtin_read, 1, 2, 3)
141#endif
118_FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n) 142_FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n)
119{ 143{
120 size_t __b = __bos(__s, 0); 144 size_t __b = __bos(__s, 0);
@@ -125,6 +149,9 @@ _FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n)
125} 149}
126 150
127__access(write_only, 2, 3) 151__access(write_only, 2, 3)
152#if __has_builtin(__builtin_readlink)
153__diagnose_as_builtin(__builtin_readlink, 1, 2, 3)
154#endif
128_FORTIFY_FN(readlink) ssize_t readlink(const char *__p, 155_FORTIFY_FN(readlink) ssize_t readlink(const char *__p,
129 char * _FORTIFY_POS0 __s, size_t __n) 156 char * _FORTIFY_POS0 __s, size_t __n)
130{ 157{
@@ -136,6 +163,9 @@ _FORTIFY_FN(readlink) ssize_t readlink(const char *__p,
136} 163}
137 164
138__access(write_only, 3, 4) 165__access(write_only, 3, 4)
166#if __has_builtin(__builtin_readlinkat)
167__diagnose_as_builtin(__builtin_readlinkat, 1, 2, 3, 4)
168#endif
139_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, 169_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p,
140 char * _FORTIFY_POS0 __s, size_t __n) 170 char * _FORTIFY_POS0 __s, size_t __n)
141{ 171{
@@ -147,6 +177,9 @@ _FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p,
147} 177}
148 178
149__access(write_only, 2, 3) 179__access(write_only, 2, 3)
180#if __has_builtin(__builtin_ttyname_r)
181__diagnose_as_builtin(__builtin_ttyname_r, 1, 2, 3)
182#endif
150_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s, 183_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s,
151 size_t __n) 184 size_t __n)
152{ 185{
@@ -158,6 +191,9 @@ _FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s,
158} 191}
159 192
160__access(read_only, 2, 3) 193__access(read_only, 2, 3)
194#if __has_builtin(__builtin_write)
195__diagnose_as_builtin(__builtin_write, 1, 2, 3)
196#endif
161_FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s, 197_FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s,
162 size_t __n) 198 size_t __n)
163{ 199{
@@ -168,6 +204,9 @@ _FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s,
168 return __orig_write(__f, __s, __n); 204 return __orig_write(__f, __s, __n);
169} 205}
170 206
207#if __has_builtin(__builtin_pwrite)
208__diagnose_as_builtin(__builtin_pwrite, 1, 2, 3, 4)
209#endif
171_FORTIFY_FN(pwrite) ssize_t pwrite(int __f, const void * _FORTIFY_POS0 __s, 210_FORTIFY_FN(pwrite) ssize_t pwrite(int __f, const void * _FORTIFY_POS0 __s,
172 size_t __n, off_t __o) 211 size_t __n, off_t __o)
173{ 212{
diff --git a/include/wchar.h b/include/wchar.h
index dc73fab..e696ddf 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -56,6 +56,9 @@ extern "C" {
56#undef wmemmove 56#undef wmemmove
57#undef wmemset 57#undef wmemset
58 58
59#if __has_builtin(__builtin_fgetws)
60__diagnose_as_builtin(__builtin_fgetws, 1, 2, 3)
61#endif
59_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s, 62_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s,
60 int __n, FILE *__f) 63 int __n, FILE *__f)
61{ 64{
@@ -69,6 +72,9 @@ _FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s,
69#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 72#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
70 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 73 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
71#undef mbsnrtowcs 74#undef mbsnrtowcs
75#if __has_builtin(__builtin_mbsnrtowcs)
76__diagnose_as_builtin(__builtin_mbsnrtowcs, 1, 2, 3, 4, 5)
77#endif
72_FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t * _FORTIFY_POS0 __d, 78_FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t * _FORTIFY_POS0 __d,
73 const char **__s, size_t __n, 79 const char **__s, size_t __n,
74 size_t __wn, mbstate_t *__st) 80 size_t __wn, mbstate_t *__st)
@@ -90,6 +96,9 @@ _FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t * _FORTIFY_POS0 __d,
90} 96}
91#endif 97#endif
92 98
99#if __has_builtin(__builtin_mbsrtowcs)
100__diagnose_as_builtin(__builtin_mbsrtowcs, 1, 2, 3, 4)
101#endif
93_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t * _FORTIFY_POS0 __d, 102_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t * _FORTIFY_POS0 __d,
94 const char **__s, size_t __wn, 103 const char **__s, size_t __wn,
95 mbstate_t *__st) 104 mbstate_t *__st)
@@ -104,6 +113,9 @@ _FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t * _FORTIFY_POS0 __d,
104 return __r; 113 return __r;
105} 114}
106 115
116#if __has_builtin(__builtin_mbstowcs)
117__diagnose_as_builtin(__builtin_mbstowcs, 1, 2, 3)
118#endif
107_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws, 119_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws,
108 const char *__s, size_t __wn) 120 const char *__s, size_t __wn)
109{ 121{
@@ -116,6 +128,9 @@ _FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws,
116 128
117/* FIXME clang */ 129/* FIXME clang */
118#ifndef __clang__ 130#ifndef __clang__
131#if __has_builtin(__builtin_wcrtomb)
132__diagnose_as_builtin(__builtin_wcrtomb, 1, 2, 3)
133#endif
119_FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st) 134_FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st)
120{ 135{
121 if (__s && MB_LEN_MAX > __bos(__s, 2)) { 136 if (__s && MB_LEN_MAX > __bos(__s, 2)) {
@@ -134,6 +149,9 @@ _FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st)
134} 149}
135#endif 150#endif
136 151
152#if __has_builtin(__builtin_wcscat)
153__diagnose_as_builtin(__builtin_wcscat, 1, 2)
154#endif
137_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d, 155_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d,
138 const wchar_t *__s) 156 const wchar_t *__s)
139{ 157{
@@ -144,6 +162,9 @@ _FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d,
144 return __orig_wcscat(__d, __s); 162 return __orig_wcscat(__d, __s);
145} 163}
146 164
165#if __has_builtin(__builtin_wcscpy)
166__diagnose_as_builtin(__builtin_wcscpy, 1, 2)
167#endif
147_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t * _FORTIFY_POS0 __d, 168_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t * _FORTIFY_POS0 __d,
148 const wchar_t *__s) 169 const wchar_t *__s)
149{ 170{
@@ -154,6 +175,9 @@ _FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t * _FORTIFY_POS0 __d,
154 return __orig_wcscpy(__d, __s); 175 return __orig_wcscpy(__d, __s);
155} 176}
156 177
178#if __has_builtin(__builtin_wcsncat)
179__diagnose_as_builtin(__builtin_wcsncat, 1, 2, 3)
180#endif
157_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d, 181_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d,
158 const wchar_t *__s, size_t __n) 182 const wchar_t *__s, size_t __n)
159{ 183{
@@ -171,6 +195,9 @@ _FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d,
171 return __orig_wcsncat(__d, __s, __n); 195 return __orig_wcsncat(__d, __s, __n);
172} 196}
173 197
198#if __has_builtin(__builtin_wcsncpy)
199__diagnose_as_builtin(__builtin_wcsncpy, 1, 2, 3)
200#endif
174_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t * _FORTIFY_POS0 __d, 201_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t * _FORTIFY_POS0 __d,
175 const wchar_t *__s, size_t __n) 202 const wchar_t *__s, size_t __n)
176{ 203{
@@ -184,6 +211,9 @@ _FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t * _FORTIFY_POS0 __d,
184#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 211#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
185 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 212 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
186#undef wcsnrtombs 213#undef wcsnrtombs
214#if __has_builtin(__builtin_wcsnrtombs)
215__diagnose_as_builtin(__builtin_wcsnrtombs, 1, 2, 3, 4, 5)
216#endif
187_FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char * _FORTIFY_POS0 __d, 217_FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char * _FORTIFY_POS0 __d,
188 const wchar_t **__s, size_t __wn, 218 const wchar_t **__s, size_t __wn,
189 size_t __n, mbstate_t *__st) 219 size_t __n, mbstate_t *__st)
@@ -205,6 +235,9 @@ _FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char * _FORTIFY_POS0 __d,
205} 235}
206#endif 236#endif
207 237
238#if __has_builtin(__builtin_wcsrtombs)
239__diagnose_as_builtin(__builtin_wcsrtombs, 1, 2, 3, 4)
240#endif
208_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d, 241_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d,
209 const wchar_t **__s, size_t __n, 242 const wchar_t **__s, size_t __n,
210 mbstate_t *__st) 243 mbstate_t *__st)
@@ -219,6 +252,9 @@ _FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d,
219} 252}
220 253
221__access(write_only, 1, 3) 254__access(write_only, 1, 3)
255#if __has_builtin(__builtin_wcstombs)
256__diagnose_as_builtin(__builtin_wcstombs, 1, 2, 3)
257#endif
222_FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s, 258_FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s,
223 const wchar_t *__ws, size_t __n) 259 const wchar_t *__ws, size_t __n)
224{ 260{
@@ -229,6 +265,9 @@ _FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s,
229 return __orig_wcstombs(__s, __ws, __n); 265 return __orig_wcstombs(__s, __ws, __n);
230} 266}
231 267
268#if __has_builtin(__builtin_wctomb)
269__diagnose_as_builtin(__builtin_wctomb, 1, 2)
270#endif
232_FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w) 271_FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w)
233{ 272{
234 size_t __b = __bos(__s, 0); 273 size_t __b = __bos(__s, 0);
@@ -238,6 +277,9 @@ _FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w)
238 return __orig_wctomb(__s, __w); 277 return __orig_wctomb(__s, __w);
239} 278}
240 279
280#if __has_builtin(__builtin_wmemcpy)
281__diagnose_as_builtin(__builtin_wmemcpy, 1, 2, 3)
282#endif
241_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d, 283_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d,
242 const wchar_t *__s, size_t __n) 284 const wchar_t *__s, size_t __n)
243{ 285{
@@ -248,6 +290,9 @@ _FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d,
248 return __orig_wmemcpy(__d, __s, __n); 290 return __orig_wmemcpy(__d, __s, __n);
249} 291}
250 292
293#if __has_builtin(__builtin_wmemmove)
294__diagnose_as_builtin(__builtin_wmemmove, 1, 2, 3)
295#endif
251_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d, 296_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d,
252 const wchar_t *__s, size_t __n) 297 const wchar_t *__s, size_t __n)
253{ 298{
@@ -258,6 +303,9 @@ _FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d,
258 return __orig_wmemmove(__d, __s, __n); 303 return __orig_wmemmove(__d, __s, __n);
259} 304}
260 305
306#if __has_builtin(__builtin_wmemset)
307__diagnose_as_builtin(__builtin_wmemset, 1, 2, 3)
308#endif
261_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t * _FORTIFY_POS0 __s, 309_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t * _FORTIFY_POS0 __s,
262 wchar_t __c, size_t __n) 310 wchar_t __c, size_t __n)
263{ 311{