4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-29 02:20:21 +08:00
Alexandre Oliva 85dd2e5b73 * libc/string/Makefile.am (lib_a_SOURCES): Added swab.c.
(CHEWOUT_FILES): Added swab.def.
* libc/string/Makefile.in: Rebuilt.
* libc/string/string.tex: Include swab.def.
* libc/include/string.h (swab): Declare.
* libc/string/swab.c: New file.
2000-03-08 03:46:01 +00:00

45 lines
898 B
C

/*
FUNCTION
<<swab>>---swap adjacent bytes
ANSI_SYNOPSIS
#include <string.h>
void swab(const void *<[in]>, void *<[out]>, size_t <[n]>);
TRAD_SYNOPSIS
void swab(<[in]>, <[out]>, <[n]>
void *<[in]>;
void *<[out]>;
size_t <[n]>;
DESCRIPTION
This function copies <[n]> bytes from the memory region
pointed to by <[in]> to the memory region pointed to by
<[out]>, exchanging adjacent even and odd bytes.
PORTABILITY
<<swab>> requires no supporting OS subroutines.
*/
#include <string.h>
void
_DEFUN (swab, (b1, b2, length),
_CONST void *b1 _AND
void *b2 _AND
ssize_t length)
{
const char *from = b1;
char *to = b2;
ssize_t ptr;
for (ptr = 1; ptr < length; ptr += 2)
{
char p = from[ptr];
char q = from[ptr-1];
to[ptr-1] = p;
to[ptr ] = q;
}
if (ptr == length) /* I.e., if length is odd, */
to[ptr-1] = 0; /* then pad with a NUL. */
}