From beca89d99a21e0fb1da16541d4206cfb3afbae82 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Wed, 3 Apr 2002 10:55:50 +0000 Subject: Add the xopen swab() function, contributed by Kensuke Otake --- libc/unistd/swab.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 libc/unistd/swab.c (limited to 'libc/unistd/swab.c') diff --git a/libc/unistd/swab.c b/libc/unistd/swab.c new file mode 100644 index 000000000..c63ca7284 --- /dev/null +++ b/libc/unistd/swab.c @@ -0,0 +1,18 @@ +#include +#include + +/* swab() swaps the position of two adjacent bytes, every two bytes. + * Contributed by Kensuke Otake */ + +void swab(const void *source, void *dest, ssize_t count) { + const char *from = (const char *)source; + char *to = (char *)dest; + + count &= ~((ssize_t)1); + + while (count > 1) { + const char b0 = from[--count], b1 = from[--count]; + to[count] = b0; + to[count + 1] = b1; + } +} -- cgit v1.2.3