swab(3) CLIX swab(3)
NAME
swab - Swaps bytes
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
void swab(
char *from ,
char *to ,
int nbytes );
PARAMETERS
from Points to the array of bytes (chars) to be copied and swapped.
to Points to the address where the swapped bytes will be stored.
nbytes Specifies the number of bytes to be operated upon.
DESCRIPTION
The swab() function copies nbytes bytes pointed to by from to the array
pointed to by to, exchanging adjacent even and odd bytes. The nbytes
parameter should be even and non-negative. If nbytes is odd and positive,
swab() uses nbytes-1 instead. If nbytes is negative, swab() does nothing.
EXAMPLES
To swap characters and store them in an array:
swapfunc(pre_swap, post_swap, num_bytes)
char *pre_swap;
char *post_swap;
int num_bytes;
{
/*
* if there are characters, swap them and store in the
* post_swap array
*/
if (num_bytes > 0) {
swab (pre_swap, post_swap, num_bytes);
}
...
In this example, a check is made to see if there are characters. If so,
they are swapped and stored in the post_swap array. The swab() function,
in this case, uses num_bytes (or numbytes-1 if num_bytes is odd and
2/94 - Intergraph Corporation 1
swab(3) CLIX swab(3)
positive) and copies num_bytes bytes pointed to by pre_swap to the array
pointed to by post_swap.
NOTES
If nbytes is negative, swab does nothing. If nbytes is odd and positive,
swab operates on nbytes-1.
RETURN VALUES
The return values are not valid.
2 Intergraph Corporation - 2/94