Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Oliva <aoliva@redhat.com>2000-03-08 06:46:01 +0300
committerAlexandre Oliva <aoliva@redhat.com>2000-03-08 06:46:01 +0300
commit85dd2e5b73ef28bac042360f93733d9b4728c4ac (patch)
treedffcfb442d1efe39cac1e56f68e8836e727ee659 /newlib/libc/string/swab.c
parentc505305855a5c7c999c7adfa0271436b3ff6ee55 (diff)
* 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.
Diffstat (limited to 'newlib/libc/string/swab.c')
-rw-r--r--newlib/libc/string/swab.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/newlib/libc/string/swab.c b/newlib/libc/string/swab.c
new file mode 100644
index 000000000..710ec5161
--- /dev/null
+++ b/newlib/libc/string/swab.c
@@ -0,0 +1,44 @@
+/*
+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. */
+}