.fp 5 CW .de Af .ds ;G \\*(;G\\f\\$1\\$3\\f\\$2 .if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" .. .de aF .ie \\$3 .ft \\$1 .el \{\ .ds ;G \& .nr ;G \\n(.f .Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" \\*(;G .ft \\n(;G \} .. .de L .aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" .. .de LR .aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" .. .de RL .aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" .. .de EX \" start example .ta 1i 2i 3i 4i 5i 6i .PP .RS .PD 0 .ft 5 .nf .. .de EE \" end example .fi .ft .PD .RE .PP .. .TH SWAP 3 .SH NAME swap \- integral representation conversion routines .SH SYNOPSIS .L "#include " .sp .L "int swapop(const void* internal, const void* external, int width); .L "int_max swapget(int op, const void* from, int width);" .L "void* swapput(int op, void* to, int width, int_max value);" .L "void* swapmem(int op, const void* from, void* to, size_t n);" .SH 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 .IR sfio (3) routines .L sfputu and .LR sgetu . .PP .L swapop returns the swap operation required to convert the .L width byte integer .L external to the .L width byte integer .LR internal . The swap operation is a bit mask: .TP .L 0 No swapping necessary. .TP .L 1 Swap byte .L 0 with byte .LR 1 . .TP .L 2 Swap bytes .L 0 and .L 1 with bytes .L 2 and .LR 3 . .TP .L 4 Swap bytes .L 0-3 with bytes .LR 4-7 , and so on. The largest native integral type is defined by the macro .L int_max in the header .L described in .IR int (3). .PP .L swapget returns the .L width byte integer in the buffer .LR from , swapped according to .LR op . .PP .L swapput copies the .L width byte integer .L value into the buffer .LR to , swapped according to .LR op . .L to is returned. .PP .L swapmem swaps .L n bytes from the buffer .L from to the buffer .L to according to .LR op . .L to and .L from may be the same. .SH "SEE ALSO" int(3)