fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers
Log | Files | Refs | README | LICENSE

commit 4a26785c0cab4686e5825fe5f5e921d12e7142b7
parent f46714c2f9eb13c12c8218f1b7c045182041fdc9
Author: jvoisin <julien.voisin@dustri.org>
Date:   Fri, 31 Oct 2025 15:55:01 +0100

Add `swab`

Co-Authored-By: Sertonix <sertonix@posteo.net>

Diffstat:
Minclude/unistd.h | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/include/unistd.h b/include/unistd.h @@ -158,6 +158,22 @@ _FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s, return __orig_write(__f, __s, __n); } +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#undef swab + +_FORTIFY_FN(swab) void swab(const void * _FORTIFY_POS0 __os, + void * _FORTIFY_POS0 __od, ssize_t __n) +{ + size_t __bs = __bos(__os, 0); + size_t __bd = __bos(__od, 0); + + if ((size_t)__n > __bs || (size_t)__n > __bd) + __builtin_trap(); + return __orig_swab(__os, __od, __n); +} + +#endif + #ifdef __cplusplus } #endif