table of contents
SWAP(3) | Library Functions Manual | SWAP(3) |
NAME¶
swap - integral representation conversion routines
SYNOPSIS¶
#include <swap.h>
int swapop(const void* internal, const void* external, int width); int_max swapget(int op, const void* from, int width); void* swapput(int op, void* to, int width, int_max value); void* swapmem(int op, const void* from, void* to, size_t n);
DESCRIPTION¶
These routines convert integral constants between internal and external representations. They are used to handle binary data generated by foreign programs. New binary data representations should use the compact canonical form provided by the sfio(3) routines sfputu and sgetu.
swapop returns the swap operation required to convert the width byte integer external to the width byte integer internal. The swap operation is a bit mask:
- 0
- No swapping necessary.
- 1
- Swap byte 0 with byte 1.
- 2
- Swap bytes 0 and 1 with bytes 2 and 3.
- 4
- Swap bytes 0-3 with bytes 4-7, and so on. The largest native integral type is defined by the macro int_max in the header <int.h> described in int(3).
swapget returns the width byte integer in the buffer from, swapped according to op.
swapput copies the width byte integer value into the buffer to, swapped according to op. to is returned.
swapmem swaps n bytes from the buffer from to the buffer to according to op. to and from may be the same.