SWAB(3POSIX)

πŸ’« hey bestie, welcome to SWAB(3POSIX) πŸ’«

okay so this page is part of the POSIX Programmer's Manual β€” that's the vibe. but real talk, a few disclaimers first because i love you and i want you to be safe:

the Linux implementation of this interface may differ (so go check the corresponding Linux manual page for the tea on Linux behavior), or honestly the interface may not even be implemented on Linux at all. no cap. πŸ™ˆ

✨ NAME ✨

swab β€” swap bytes, bestie. that's it, that's the whole thing. πŸ¦‹


🌸 SYNOPSIS 🌸

#include <unistd.h>

void swab(const void *restrict src, void *restrict dest,
    ssize_t nbytes);

πŸ’– DESCRIPTION πŸ’–

so here's what's happening, and it's lowkey elegant:

the swab() function shall copy nbytes bytes, which are pointed to by src, over to the object pointed to by dest β€” but it's exchanging adjacent bytes. swapping the pairs. iconic behavior honestly. πŸ”₯

the nbytes argument should be even. and the way that it gets weird is this:

  • if nbytes is odd, swab() copies and exchanges nbytes-1 bytes, and the disposition of the last byte is unspecified. so like... the last byte is in its main character era and nobody knows where it goes. πŸ’€
  • if copying takes place between objects that overlap, the behavior is undefined. do not do that. periodt.
  • if nbytes is negative, swab() does nothing. it just vibes. ✨

🫢 RETURN VALUE 🫢

None. it returns nothing. it's a void function, she simply doesn't give anything back and that's her right. πŸ’…


πŸŽ€ ERRORS πŸŽ€

no errors are defined. like, none. zero. the girl does not error. πŸ‘‘

the following sections are informative β€” meaning they're here for the lore, not the rules.

🌈 EXAMPLES 🌈

None. there are no examples. i know, i know, i wanted one too. 😭


🧚 APPLICATION USAGE 🧚

None. nothing here either. the page is giving minimalist. πŸ“


⭐ RATIONALE ⭐

None. no reasoning given, she just is. πŸ’œ


πŸ¦‹ FUTURE DIRECTIONS πŸ¦‹

None. the future is unclear but swab() stays unbothered. ✨


πŸ‘‘ SEE ALSO πŸ‘‘

  • the Base Definitions volume of POSIX.1‐2017, <unistd.h> β€” go read the header's moment, iykyk πŸ“–

okay this part is the legal bit and we keep every word of it, so here we go:

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page bestie!! 🫢 this one's brought to you by IEEE/The Open Group, 2017 β€” mwah, thank you for your service, we stan the standards committee fr fr. πŸ’–βœ¨πŸŽ€