OSByteOrder.h

Includes:
<stdint.h>
<libkern/_OSByteOrder.h>
<libkern/ppc/OSByteOrder.h>
<libkern/i386/OSByteOrder.h>
<libkern/arm/OSByteOrder.h>
<libkern/machine/OSByteOrder.h>
<libkern/machine/OSByteOrder.h>

Overview

This header provides functions and mmacros for byte swapping between little endian or big endian and host byte order.

For the kernel-space version of this header, see

OSByteOrder.h (Kernel Framework)



Functions

_OSReadInt16

Reads a 16-bit big-endian integer.

_OSReadInt32

Reads a 32-bit big-endian integer.

_OSReadInt64

Reads a 64-bit big-endian integer.

_OSWriteInt16

Writes a 16-bit big-endian integer.

_OSWriteInt32

Writes a 32-bit big-endian integer.

_OSWriteInt64

Writes a 64-bit big-endian integer.

OSHostByteOrder

Returns the byte order of the host.


_OSReadInt16


Reads a 16-bit big-endian integer.

OS_INLINE uint16_t _OSReadInt16( 
    const volatile void * base, 
    uintptr_t byteOffset ) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.


_OSReadInt32


Reads a 32-bit big-endian integer.

OS_INLINE uint32_t _OSReadInt32( 
    const volatile void * base, 
    uintptr_t byteOffset ) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.


_OSReadInt64


Reads a 64-bit big-endian integer.

OS_INLINE uint64_t _OSReadInt64( 
    const volatile void * base, 
    uintptr_t byteOffset ) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.


_OSWriteInt16


Writes a 16-bit big-endian integer.

OS_INLINE void _OSWriteInt16( 
    volatile void *base, 
    uintptr_t byteOffset, 
    uint16_t data ) 
Parameters
base

An address at or below the address of the integer to be written.

byteOffset

The offset from base (in bytes) of the start of the integer to be written.

data

The value to write (in host byte order).


_OSWriteInt32


Writes a 32-bit big-endian integer.

OS_INLINE void _OSWriteInt32( 
    volatile void *base, 
    uintptr_t byteOffset, 
    uint32_t data ) 
Parameters
base

An address at or below the address of the integer to be written.

byteOffset

The offset from base (in bytes) of the start of the integer to be written.

data

The value to write (in host byte order).


_OSWriteInt64


Writes a 64-bit big-endian integer.

OS_INLINE void _OSWriteInt64( 
    volatile void *base, 
    uintptr_t byteOffset, 
    uint64_t data ) 
Parameters
base

An address at or below the address of the integer to be written.

byteOffset

The offset from base (in bytes) of the start of the integer to be written.

data

The value to write (in host byte order).


OSHostByteOrder


Returns the byte order of the host.

OS_INLINE int32_t OSHostByteOrder(
    void) 
Return Value

Returns one of the constants defined by Byte order constants.

Enumerated Types

Byte order constants

Byte order constants.


Byte order constants


Byte order constants.

enum { 
    OSUnknownByteOrder, 
    OSLittleEndian, 
    OSBigEndian 
};  
Discussion

These constants are returned by OSHostByteOrder.

Macro Definitions

OSReadBigInt

Reads a 32-bit big-endian integer.

OSReadBigInt16

Reads a 16-bit big endian integer and swaps to host byte order.

OSReadBigInt32

Reads a 32-bit big endian integer and swaps to host byte order.

OSReadBigInt64

Reads a 64-bit big endian integer and swaps to host byte order.

OSReadLittleInt

Reads a 32-bit little-endian integer.

OSReadLittleInt16

Reads a 16-bit little endian integer and swaps to host byte order.

OSReadLittleInt32

Reads a 32-bit little endian integer and swaps to host byte order.

OSReadLittleInt64

Reads a 64-bit little endian integer and swaps to host byte order.

OSSwapBigToHostConstInt16

Converts a 16-bit big endian constant to host byte order.

OSSwapBigToHostConstInt32

Converts a 32-bit big endian constant to host byte order.

OSSwapBigToHostConstInt64

Converts a 64-bit big endian constant to host byte order.

OSSwapBigToHostInt

Swaps a 32-bit integer from big endian to host byte order.

OSSwapBigToHostInt16

Converts a 16-bit big endian integer to host byte order.

OSSwapBigToHostInt32

Converts a 32-bit big endian integer to host byte order.

OSSwapBigToHostInt64

Converts a 64-bit big endian integer to host byte order.

OSSwapConstInt16

Byte swaps a 16-bit constant.

OSSwapConstInt32

Byte swaps a 32-bit constant.

OSSwapConstInt64

Byte swaps a 64-bit constant.

OSSwapHostToBigConstInt16

Converts a 16-bit host endian constant to big endian.

OSSwapHostToBigConstInt32

Converts a 32-bit host endian constant to big endian.

OSSwapHostToBigConstInt64

Converts a 64-bit host endian constant to big endian.

OSSwapHostToBigInt

Swaps a 32-bit integer from host byte order to big endian.

OSSwapHostToBigInt16

Converts a 16-bit host endian integer to big endian.

OSSwapHostToBigInt32

Converts a 32-bit host endian integer to big endian.

OSSwapHostToBigInt64

Converts a 64-bit host endian integer to big endian.

OSSwapHostToLittleConstInt16

Converts a 16-bit host endian constant to little endian.

OSSwapHostToLittleConstInt32

Converts a 32-bit host endian constant to little endian.

OSSwapHostToLittleConstInt64

Converts a 64-bit host endian constant to little endian.

OSSwapHostToLittleInt

Swaps a 32-bit integer from host byte order to little endian.

OSSwapHostToLittleInt16

Converts a 16-bit host endian integer to little endian.

OSSwapHostToLittleInt32

Converts a 32-bit host endian integer to little endian.

OSSwapHostToLittleInt64

Converts a 64-bit host endian integer to little endian.

OSSwapLittleToHostConstInt16

Converts a 16-bit little endian constant to host byte order.

OSSwapLittleToHostConstInt32

Converts a 32-bit little endian constant to host byte order.

OSSwapLittleToHostConstInt64

Converts a 64-bit little endian constant to host byte order.

OSSwapLittleToHostInt

Swaps a 32-bit integer from little endian to host byte order.

OSSwapLittleToHostInt16

Converts a 16-bit little endian integer to host byte order.

OSSwapLittleToHostInt32

Converts a 32-bit little endian integer to host byte order.

OSSwapLittleToHostInt64

Converts a 64-bit little endian integer to host byte order.

OSWriteBigInt

Writes a 32-bit big-endian integer.

OSWriteBigInt16

Writes a 16-bit big endian integer and swaps from host byte order.

OSWriteBigInt32

Writes a 32-bit big endian integer and swaps from host byte order.

OSWriteBigInt64

Writes a 64-bit big endian integer and swaps from host byte order.

OSWriteLittleInt

Writes a 32-bit little-endian integer.

OSWriteLittleInt16

Writes a 16-bit little endian integer and swaps from host byte order.

OSWriteLittleInt32

Writes a 32-bit little endian integer and swaps from host byte order.

OSWriteLittleInt64

Writes a 64-bit little endian integer and swaps from host byte order.


OSReadBigInt


Reads a 32-bit big-endian integer.

#define OSReadBigInt(x, y) OSReadBigInt32(x, y) 
Discussion

See documentation for OSReadBigInt32.


OSReadBigInt16


Reads a 16-bit big endian integer and swaps to host byte order.

#define OSReadBigInt16(base, byteOffset) OSReadSwapInt16(base, byteOffset) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.


OSReadBigInt32


Reads a 32-bit big endian integer and swaps to host byte order.

#define OSReadBigInt32(base, byteOffset) OSReadSwapInt32(base, byteOffset) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.


OSReadBigInt64


Reads a 64-bit big endian integer and swaps to host byte order.

#define OSReadBigInt64(base, byteOffset) OSReadSwapInt64(base, byteOffset) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.


OSReadLittleInt


Reads a 32-bit little-endian integer.

#define OSReadLittleInt(x, y) OSReadLittleInt32(x, y) 
Discussion

See documentation for OSReadLittleInt32.


OSReadLittleInt16


Reads a 16-bit little endian integer and swaps to host byte order.

#define OSReadLittleInt16(base, byteOffset) _OSReadInt16(base, byteOffset) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.


OSReadLittleInt32


Reads a 32-bit little endian integer and swaps to host byte order.

#define OSReadLittleInt32(base, byteOffset) _OSReadInt32(base, byteOffset) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.


OSReadLittleInt64


Reads a 64-bit little endian integer and swaps to host byte order.

#define OSReadLittleInt64(base, byteOffset) _OSReadInt64(base, byteOffset) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.


OSSwapBigToHostConstInt16


Converts a 16-bit big endian constant to host byte order.

#define OSSwapBigToHostConstInt16(x) __DARWIN_OSSwapConstInt16(x) 
Parameters
x

The constant to convert.


OSSwapBigToHostConstInt32


Converts a 32-bit big endian constant to host byte order.

#define OSSwapBigToHostConstInt32(x) __DARWIN_OSSwapConstInt32(x) 
Parameters
x

The constant to convert.


OSSwapBigToHostConstInt64


Converts a 64-bit big endian constant to host byte order.

#define OSSwapBigToHostConstInt64(x) __DARWIN_OSSwapConstInt64(x) 
Parameters
x

The constant to convert.


OSSwapBigToHostInt


Swaps a 32-bit integer from big endian to host byte order.

Discussion

See documentation for OSSwapBigToHostInt32.


OSSwapBigToHostInt16


Converts a 16-bit big endian integer to host byte order.

#define OSSwapBigToHostInt16(x) OSSwapInt16(x) 
Parameters
x

The integer to convert.


OSSwapBigToHostInt32


Converts a 32-bit big endian integer to host byte order.

#define OSSwapBigToHostInt32(x) OSSwapInt32(x) 
Parameters
x

The integer to convert.


OSSwapBigToHostInt64


Converts a 64-bit big endian integer to host byte order.

#define OSSwapBigToHostInt64(x) OSSwapInt64(x) 
Parameters
x

The integer to convert.


OSSwapConstInt16


Byte swaps a 16-bit constant.

#define OSSwapConstInt16(x) __DARWIN_OSSwapConstInt16(x) 


OSSwapConstInt32


Byte swaps a 32-bit constant.

#define OSSwapConstInt32(x) __DARWIN_OSSwapConstInt32(x) 


OSSwapConstInt64


Byte swaps a 64-bit constant.

#define OSSwapConstInt64(x) __DARWIN_OSSwapConstInt64(x) 


OSSwapHostToBigConstInt16


Converts a 16-bit host endian constant to big endian.

#define OSSwapHostToBigConstInt16(x) __DARWIN_OSSwapConstInt16(x) 
Parameters
x

The constant value to convert.


OSSwapHostToBigConstInt32


Converts a 32-bit host endian constant to big endian.

#define OSSwapHostToBigConstInt32(x) __DARWIN_OSSwapConstInt32(x) 
Parameters
x

The constant value to convert.


OSSwapHostToBigConstInt64


Converts a 64-bit host endian constant to big endian.

#define OSSwapHostToBigConstInt64(x) __DARWIN_OSSwapConstInt64(x) 
Parameters
x

The constant value to convert.


OSSwapHostToBigInt


Swaps a 32-bit integer from host byte order to big endian.

Discussion

See documentation for OSSwapHostToBigInt32.


OSSwapHostToBigInt16


Converts a 16-bit host endian integer to big endian.

#define OSSwapHostToBigInt16(x) OSSwapInt16(x) 
Parameters
x

The integer to convert.


OSSwapHostToBigInt32


Converts a 32-bit host endian integer to big endian.

#define OSSwapHostToBigInt32(x) OSSwapInt32(x) 
Parameters
x

The integer to convert.


OSSwapHostToBigInt64


Converts a 64-bit host endian integer to big endian.

#define OSSwapHostToBigInt64(x) OSSwapInt64(x) 
Parameters
x

The integer to convert.


OSSwapHostToLittleConstInt16


Converts a 16-bit host endian constant to little endian.

Parameters
x

The constant to convert.


OSSwapHostToLittleConstInt32


Converts a 32-bit host endian constant to little endian.

Parameters
x

The constant to convert.


OSSwapHostToLittleConstInt64


Converts a 64-bit host endian constant to little endian.

Parameters
x

The constant to convert.


OSSwapHostToLittleInt


Swaps a 32-bit integer from host byte order to little endian.

Discussion

See documentation for OSSwapHostToLittleInt32.


OSSwapHostToLittleInt16


Converts a 16-bit host endian integer to little endian.

Parameters
x

The integer to convert.


OSSwapHostToLittleInt32


Converts a 32-bit host endian integer to little endian.

Parameters
x

The integer to convert.


OSSwapHostToLittleInt64


Converts a 64-bit host endian integer to little endian.

Parameters
x

The integer to convert.


OSSwapLittleToHostConstInt16


Converts a 16-bit little endian constant to host byte order.

Parameters
x

The constant to convert.


OSSwapLittleToHostConstInt32


Converts a 32-bit little endian constant to host byte order.

Parameters
x

The constant to convert.


OSSwapLittleToHostConstInt64


Converts a 64-bit little endian constant to host byte order.

Parameters
x

The constant to convert.


OSSwapLittleToHostInt


Swaps a 32-bit integer from little endian to host byte order.

Discussion

See documentation for OSSwapLittleToHostInt32.


OSSwapLittleToHostInt16


Converts a 16-bit little endian integer to host byte order.

Parameters
x

The integer to convert.


OSSwapLittleToHostInt32


Converts a 32-bit little endian integer to host byte order.

Parameters
x

The integer to convert.


OSSwapLittleToHostInt64


Converts a 64-bit little endian integer to host byte order.

Parameters
x

The integer to convert.


OSWriteBigInt


Writes a 32-bit big-endian integer.

#define OSWriteBigInt(x, y, z) OSWriteBigInt32(x, y, z) 
Discussion

See documentation for OSWriteBigInt32.


OSWriteBigInt16


Writes a 16-bit big endian integer and swaps from host byte order.

#define OSWriteBigInt16(base, byteOffset, data) OSWriteSwapInt16(base, byteOffset, data) 
Parameters
base

An address at or below the address of the integer to be written.

byteOffset

The offset from base (in bytes) of the start of the integer to be written.

data

The value to write (in host byte order).


OSWriteBigInt32


Writes a 32-bit big endian integer and swaps from host byte order.

#define OSWriteBigInt32(base, byteOffset, data) OSWriteSwapInt32(base, byteOffset, data) 
Parameters
base

An address at or below the address of the integer to be written.

byteOffset

The offset from base (in bytes) of the start of the integer to be written.

data

The value to write (in host byte order).


OSWriteBigInt64


Writes a 64-bit big endian integer and swaps from host byte order.

#define OSWriteBigInt64(base, byteOffset, data) OSWriteSwapInt64(base, byteOffset, data) 
Parameters
base

An address at or below the address of the integer to be written.

byteOffset

The offset from base (in bytes) of the start of the integer to be written.

data

The value to write (in host byte order).


OSWriteLittleInt


Writes a 32-bit little-endian integer.

#define OSWriteLittleInt(x, y, z) OSWriteLittleInt32(x, y, z) 
Discussion

See documentation for OSWriteLittleInt32.


OSWriteLittleInt16


Writes a 16-bit little endian integer and swaps from host byte order.

#define OSWriteLittleInt16(base, byteOffset, data) _OSWriteInt16(base, byteOffset, data) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.

data

The value to write (in host byte order).


OSWriteLittleInt32


Writes a 32-bit little endian integer and swaps from host byte order.

#define OSWriteLittleInt32(base, byteOffset, data) _OSWriteInt32(base, byteOffset, data) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.

data

The value to write (in host byte order).


OSWriteLittleInt64


Writes a 64-bit little endian integer and swaps from host byte order.

#define OSWriteLittleInt64(base, byteOffset, data) _OSWriteInt64(base, byteOffset, data) 
Parameters
base

An address at or below the address of the integer to be read.

byteOffset

The offset from base (in bytes) of the start of the integer to be read.

data

The value to write (in host byte order).

 

Did this document help you? Yes It's good, but... Not helpful...

 

Last Updated: 2009-10-15