1.\" $OpenBSD: bemtoh32.9,v 1.7 2019/08/30 18:33:17 deraadt Exp $ 2.\" 3.\" Copyright (c) 2014 David Gwynne <dlg@openbsd.org> 4.\" All rights reserved. 5.\" 6.\" Permission to use, copy, modify, and distribute this software for any 7.\" purpose with or without fee is hereby granted, provided that the above 8.\" copyright notice and this permission notice appear in all copies. 9.\" 10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" 18.Dd $Mdocdate: August 30 2019 $ 19.Dt BEMTOH32 9 20.Os 21.Sh NAME 22.Nm bemtoh16 , 23.Nm bemtoh32 , 24.Nm bemtoh64 , 25.Nm lemtoh16 , 26.Nm lemtoh32 , 27.Nm lemtoh64 , 28.Nm htobem16 , 29.Nm htobem32 , 30.Nm htobem64 , 31.Nm htolem16 , 32.Nm htolem32 , 33.Nm htolem64 34.Nd byte swapping memory load and store operations 35.Sh SYNOPSIS 36.In sys/types.h 37.Ft uint16_t 38.Fn bemtoh16 "volatile const uint16_t *m" 39.Ft uint32_t 40.Fn bemtoh32 "volatile const uint32_t *m" 41.Ft uint64_t 42.Fn bemtoh64 "volatile const uint64_t *m" 43.Ft uint16_t 44.Fn lemtoh16 "volatile const uint16_t *m" 45.Ft uint32_t 46.Fn lemtoh32 "volatile const uint32_t *m" 47.Ft uint64_t 48.Fn lemtoh64 "volatile const uint64_t *m" 49.Ft void 50.Fn htobem16 "volatile uint16_t *m" "uint16_t v" 51.Ft void 52.Fn htobem32 "volatile uint32_t *m" "uint32_t v" 53.Ft void 54.Fn htobem64 "volatile uint64_t *m" "uint64_t v" 55.Ft void 56.Fn htolem16 "volatile uint16_t *m" "uint16_t v" 57.Ft void 58.Fn htolem32 "volatile uint32_t *m" "uint32_t v" 59.Ft void 60.Fn htolem64 "volatile uint64_t *m" "uint64_t v" 61.Sh DESCRIPTION 62This API provides a way to take advantage of an architecture's ability 63to load and store words in memory of different endians. 64If an architecture has no specialised support for these operations 65they will be implemented as a wrapper around the 66.Xr htobe64 3 67API. 68.Pp 69These operations are subject to the same alignment restrictions as 70the host's normal memory loads and stores. 71.Pp 72.Fn bemtoh16 , 73.Fn bemtoh32 , 74and 75.Fn bemtoh64 76read a big endian value from the memory located at 77.Fa m 78into the host's native byte order. 79.Fn lemtoh16 , 80.Fn lemtoh32 , 81and 82.Fn lemtoh64 83read a little endian value from the memory located at 84.Fa m 85into the host's native byte order. 86.Pp 87.Fn htobem16 , 88.Fn htobem32 , 89and 90.Fn htobem64 91store the host's native byte ordered value of 92.Fa v 93as a big endian value in the memory located at 94.Fa m . 95.Fn htolem16 , 96.Fn htolem32 , 97and 98.Fn htolem64 99store the host's native byte ordered value of 100.Fa v 101as a little endian value in the memory located at 102.Fa m . 103.Sh CONTEXT 104.Fn bemtoh16 , 105.Fn bemtoh32 , 106.Fn bemtoh64 , 107.Fn lemtoh16 , 108.Fn lemtoh32 , 109.Fn lemtoh64 , 110.Fn htobem16 , 111.Fn htobem32 , 112.Fn htobem64 , 113.Fn htolem16 , 114.Fn htolem32 , 115and 116.Fn htolem64 117can be called during autoconf, from process context, or from interrupt 118context. 119.Sh RETURN VALUES 120.Fn bemtoh16 , 121.Fn bemtoh32 , 122.Fn bemtoh64 , 123.Fn lemtoh16 , 124.Fn lemtoh32 , 125and 126.Fn lemtoh64 127return the host's native byte ordered value of the memory at 128.Fa m 129after the appropriate byteswapping has occurred. 130.Pp 131.Fn htobem16 , 132.Fn htobem32 , 133.Fn htobem64 , 134.Fn htolem16 , 135.Fn htolem32 , 136and 137.Fn htolem64 138do not return a value. 139.Sh SEE ALSO 140.Xr htobe64 3 141.Sh HISTORY 142These functions first appeared in 143.Ox 5.6 . 144