4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-29 10:30:50 +08:00
Jeff Johnston 3072163c0f Wed Mar 8 17:11:41 2000 Jeff Johnston <jjohnstn@cygnus.com>
* libc/include/string.h: Changed last argument to size_t.
        * libc/string/swab.c: Changed last argument to size_t.
2000-03-08 22:16:06 +00:00

45 lines
896 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
size_t length)
{
const char *from = b1;
char *to = b2;
size_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. */
}