BEMTOH32(9)
okay bestie, welcome to BEMTOH32(9) from the Kernel Developer's Manual β the byte-swapping memory load and store operations page, and yes we're making it cute. π
π NAME π
Meet the whole squad: bemtoh16, bemtoh32, bemtoh64, lemtoh16, lemtoh32, lemtoh64, htobem16, htobem32, htobem64, htolem16, htolem32, htolem64 β all here for byte swapping memory load and store operations. periodt. π
β¨ SYNOPSIS β¨
#include <sys/types.h>
uint16_t
bemtoh16(volatile const uint16_t *m);
uint32_t
bemtoh32(volatile const uint32_t *m);
uint64_t
bemtoh64(volatile const uint64_t *m);
uint16_t
lemtoh16(volatile const uint16_t *m);
uint32_t
lemtoh32(volatile const uint32_t *m);
uint64_t
lemtoh64(volatile const uint64_t *m);
void
htobem16(volatile uint16_t *m, uint16_t v);
void
htobem32(volatile uint32_t *m, uint32_t v);
void
htobem64(volatile uint64_t *m, uint64_t v);
void
htolem16(volatile uint16_t *m, uint16_t v);
void
htolem32(volatile uint32_t *m, uint32_t v);
void
htolem64(volatile uint64_t *m, uint64_t v);
πΈ DESCRIPTION πΈ
So this API is giving main character energy because it lets you take advantage of an architecture's ability to load and store words in memory of different endians. π¦ If an architecture has no specialised support for these operations, they will be implemented as a wrapper around the htobe64(3) API. no cap.
These operations are subject to the same alignment restrictions as the host's normal memory loads and stores. like, the alignment rules are not a vibe you can ignore, bestie. π
bemtoh16(),bemtoh32(),bemtoh64()β read a big endian value from the memory located atminto the host's native byte order. πlemtoh16(),lemtoh32(),lemtoh64()β read a little endian value from the memory located atminto the host's native byte order. β¨htobem16(),htobem32(),htobem64()β store the host's native byte ordered value ofvas a big endian value in the memory located atm. πhtolem16(),htolem32(),htolem64()β store the host's native byte ordered value ofvas a little endian value in the memory located atm. π§
π¦ CONTEXT π¦
bemtoh16(), bemtoh32(), bemtoh64(), lemtoh16(), lemtoh32(), lemtoh64(), htobem16(), htobem32(), htobem64(), htolem16(), htolem32(), and htolem64() can be called during autoconf, from process context, or from interrupt context. they're flexible like that. π
π RETURN VALUES π
bemtoh16(), bemtoh32(), bemtoh64(), lemtoh16(), lemtoh32(), and lemtoh64() return the host's native byte ordered value of the memory at m after the appropriate byteswapping has occurred. π«Ά
htobem16(), htobem32(), htobem64(), htolem16(), htolem32(), and htolem64() do not return a value. they're void, they said no return value and they meant it. π
π₯ SEE ALSO π₯
htobe64(3) β go read that one too, iykyk. π
β HISTORY β
These functions first appeared in OpenBSD 5.6. iconic behavior, honestly. π
π cute little sign-off: this page comes from Debian, dated March 31, 2022 β bye bestie, go byteswap responsibly. πβ¨
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2014 David Gwynne <dlg@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms