summaryrefslogtreecommitdiff
path: root/include/unistd.h
diff options
context:
space:
mode:
authorSertonix2025-10-11 18:25:20 +0200
committerJulien Voisin2025-10-12 14:47:11 +0200
commit41d3081c4ac0a79a4ad292957ead84f8477eaa55 (patch)
treee1c2c2e51beb8009c61789bd6239e083e8288805 /include/unistd.h
parent2e22fe52b441308c274cfec4436204a9e5f70db7 (diff)
Add `swab`
Make the overlap check pedantic only since some software seems to rely on glibc working when src and dest are the same.
Diffstat (limited to 'include/unistd.h')
-rw-r--r--include/unistd.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h
index f6d4e87..b91dc56 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -178,6 +178,32 @@ _FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p,
178 return __orig_readlinkat(__f, __p, __s, __n); 178 return __orig_readlinkat(__f, __p, __s, __n);
179} 179}
180 180
181#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
182#undef swab
183
184__fh_access(read_only, 1, 3)
185__fh_access(write_only, 2, 3)
186#if __has_builtin(__builtin_swab)
187__diagnose_as_builtin(__builtin_swab, 1, 2, 3)
188#endif
189_FORTIFY_FN(swab) void swab(const void *restrict _FORTIFY_POS0 __os,
190 void *restrict _FORTIFY_POS0 __od, ssize_t __n)
191__error_if((__fh_bos(__od, 0) < __n), "'swab' called with `n` bigger than the size of `d`.")
192{
193 __fh_size_t __bs = __fh_bos(__os, 0);
194 __fh_size_t __bd = __fh_bos(__od, 0);
195
196#if defined FORTIFY_PEDANTIC_CHECKS
197 if (__n > 0 && __fh_overlap(__os, __n, __od, __n))
198 __builtin_trap();
199#endif
200 if (__n > __bs || __n > __bd)
201 __builtin_trap();
202 return __orig_swab(__os, __od, __n);
203}
204
205#endif
206
181__fh_access(write_only, 2, 3) 207__fh_access(write_only, 2, 3)
182#if __has_builtin(__builtin_ttyname_r) 208#if __has_builtin(__builtin_ttyname_r)
183__diagnose_as_builtin(__builtin_ttyname_r, 1, 2, 3) 209__diagnose_as_builtin(__builtin_ttyname_r, 1, 2, 3)