Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / string / swab.c
blob28ab978bd98f62d71a87bc6e832297ad604c65cb
1 /*
2 FUNCTION
3 <<swab>>---swap adjacent bytes
5 SYNOPSIS
6 #include <unistd.h>
7 void swab(const void *<[in]>, void *<[out]>, ssize_t <[n]>);
9 DESCRIPTION
10 This function copies <[n]> bytes from the memory region
11 pointed to by <[in]> to the memory region pointed to by
12 <[out]>, exchanging adjacent even and odd bytes.
14 PORTABILITY
15 <<swab>> requires no supporting OS subroutines.
18 #include <unistd.h>
20 void
21 swab (const void *b1,
22 void *b2,
23 ssize_t length)
25 const char *from = b1;
26 char *to = b2;
27 ssize_t ptr;
28 for (ptr = 1; ptr < length; ptr += 2)
30 char p = from[ptr];
31 char q = from[ptr-1];
32 to[ptr-1] = p;
33 to[ptr ] = q;
35 if (ptr == length) /* I.e., if length is odd, */
36 to[ptr-1] = 0; /* then pad with a NUL. */