fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / string / swab.c
blobaee07631969ebbfc1b1652c1b4b3a084a34225e1
1 /*
2 FUNCTION
3 <<swab>>---swap adjacent bytes
5 ANSI_SYNOPSIS
6 #include <unistd.h>
7 void swab(const void *<[in]>, void *<[out]>, ssize_t <[n]>);
9 TRAD_SYNOPSIS
10 void swab(<[in]>, <[out]>, <[n]>
11 void *<[in]>;
12 void *<[out]>;
13 ssize_t <[n]>;
15 DESCRIPTION
16 This function copies <[n]> bytes from the memory region
17 pointed to by <[in]> to the memory region pointed to by
18 <[out]>, exchanging adjacent even and odd bytes.
20 PORTABILITY
21 <<swab>> requires no supporting OS subroutines.
24 #include <unistd.h>
26 void
27 _DEFUN (swab, (b1, b2, length),
28 _CONST void *b1 _AND
29 void *b2 _AND
30 ssize_t length)
32 const char *from = b1;
33 char *to = b2;
34 ssize_t ptr;
35 for (ptr = 1; ptr < length; ptr += 2)
37 char p = from[ptr];
38 char q = from[ptr-1];
39 to[ptr-1] = p;
40 to[ptr ] = q;
42 if (ptr == length) /* I.e., if length is odd, */
43 to[ptr-1] = 0; /* then pad with a NUL. */