1.fp 5 CW 2.de Af 3.ds ;G \\*(;G\\f\\$1\\$3\\f\\$2 4.if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" 5.. 6.de aF 7.ie \\$3 .ft \\$1 8.el \{\ 9.ds ;G \& 10.nr ;G \\n(.f 11.Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" 12\\*(;G 13.ft \\n(;G \} 14.. 15.de L 16.aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" 17.. 18.de LR 19.aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" 20.. 21.de RL 22.aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" 23.. 24.de EX \" start example 25.ta 1i 2i 3i 4i 5i 6i 26.PP 27.RS 28.PD 0 29.ft 5 30.nf 31.. 32.de EE \" end example 33.fi 34.ft 35.PD 36.RE 37.PP 38.. 39.TH SWAP 3 40.SH NAME 41swap \- integral representation conversion routines 42.SH SYNOPSIS 43.L "#include <swap.h>" 44.sp 45.L "int swapop(const void* internal, const void* external, int width); 46.L "int_max swapget(int op, const void* from, int width);" 47.L "void* swapput(int op, void* to, int width, int_max value);" 48.L "void* swapmem(int op, const void* from, void* to, size_t n);" 49.SH DESCRIPTION 50These routines convert integral constants between internal and 51external representations. 52They are used to handle binary data generated by foreign programs. 53New binary data representations should use the compact canonical form 54provided by the 55.IR sfio (3) 56routines 57.L sfputu 58and 59.LR sgetu . 60.PP 61.L swapop 62returns the swap operation required to convert the 63.L width 64byte integer 65.L external 66to the 67.L width 68byte integer 69.LR internal . 70The swap operation is a bit mask: 71.TP 72.L 0 73No swapping necessary. 74.TP 75.L 1 76Swap byte 77.L 0 78with byte 79.LR 1 . 80.TP 81.L 2 82Swap bytes 83.L 0 84and 85.L 1 86with bytes 87.L 2 88and 89.LR 3 . 90.TP 91.L 4 92Swap bytes 93.L 0-3 94with bytes 95.LR 4-7 , 96and so on. 97The largest native integral type is defined by the macro 98.L int_max 99in the header 100.L <int.h> 101described in 102.IR int (3). 103.PP 104.L swapget 105returns the 106.L width 107byte integer in the buffer 108.LR from , 109swapped according to 110.LR op . 111.PP 112.L swapput 113copies the 114.L width 115byte integer 116.L value 117into the buffer 118.LR to , 119swapped according to 120.LR op . 121.L to 122is returned. 123.PP 124.L swapmem 125swaps 126.L n 127bytes from the buffer 128.L from 129to the buffer 130.L to 131according to 132.LR op . 133.L to 134and 135.L from 136may be the same. 137.SH "SEE ALSO" 138int(3) 139