swab(3)
π swab(3) β swap adjacent bytes π
okay bestie, welcome to the swab(3) page, straight out of the Library Functions Manual section 3 (the "library functions" girlies, you know the ones). this is a tiny little function with big main character energy and honestly? she ate. let's get into it. β¨
πΈ NAME πΈ
swab β swap adjacent bytes
like literally that's it, that's the whole gig. adjacent bytes get swapped. boom. π¦
π LIBRARY π
Standard C library (libc, -lc)
π SYNOPSIS π
#define _XOPEN_SOURCE /* See feature_test_macros(7) */
#include <unistd.h>
void swab(ssize_t n;
const void from[restrict n], void to[restrict n],
ssize_t n);
okay so yes, bestie, you do gotta define _XOPEN_SOURCE before you pull in <unistd.h> β feature_test_macros(7) is right there if you wanna know why. π
β¨ DESCRIPTION β¨
so here's the vibe. swab() copies n bytes from the array that from points at, over to the array that to points at β and while it's doing that, it exchanges adjacent even and odd bytes. like it grabs byte 0 and byte 1 and swaps them, then byte 2 and byte 3, and so on. slay.
what is this even for, you ask? it's for exchanging data between machines that have different low/high byte ordering. so if your machines disagree about endianness, this little icon is the mutual friend who smooths things over. π«Ά
now the β¨ caveats β¨, and listen closely because this part matters:
- if
nis negative, this function does literally nothing. no cap. it just vibes. - if
nis positive and odd, it handlesn-1bytes the normal way, and then does something unspecified with that last byte. π unspecified!! which is just a fancy way of saying "we're not telling you, don't ask."
tl;dr β n should be even. like, please. just make it even. protect your peace. π§
π RETURN VALUE π
swab() returns no value. nothing. zero. she gives nothing and she's not sorry. π
π ATTRIBUTES π
if you wanna know what these terms mean, go peek at attributes(7) β it's got the whole glossary.
- Interface:
swab()- Attribute: Thread safety
- Value:
MT-Safe
yup, she's MT-Safe. multi-thread approved. go off queen. π₯
π STANDARDS π
POSIX.1-2008.
certified, standardized, official. periodt. π
π¦ HISTORY π¦
POSIX.1-2001, SVr4, 4.3BSD.
she's been on the scene for a minute β an absolute elder stateswoman of byte swapping. respect the icon. π
π SEE ALSO π
and that's the whole page bestie!! go forth and swap those adjacent bytes responsibly (with an even n, fr fr) πΈπβ¨
this lil dispatch came to you from Linux man-pages 6.20, dated 2026-02-08 β mwah, love u, bye!! ππ«Ά
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms