From 4a26785c0cab4686e5825fe5f5e921d12e7142b7 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 31 Oct 2025 15:55:01 +0100 Subject: Add `swab` Co-Authored-By: Sertonix --- include/unistd.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include') diff --git a/include/unistd.h b/include/unistd.h index 3e5c040..4c18b73 100644 --- 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 -- cgit v1.3