summaryrefslogtreecommitdiffstats
path: root/libc/unistd/swab.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-04-03 10:55:50 +0000
committerEric Andersen <andersen@codepoet.org>2002-04-03 10:55:50 +0000
commitbeca89d99a21e0fb1da16541d4206cfb3afbae82 (patch)
tree89b438ab79cd60d0726c9d7d4b65674675483c5e /libc/unistd/swab.c
parentae9317047b75e773c37e9aab2d8fff1652954e71 (diff)
downloaduClibc-alpine-beca89d99a21e0fb1da16541d4206cfb3afbae82.tar.bz2
uClibc-alpine-beca89d99a21e0fb1da16541d4206cfb3afbae82.tar.xz
Add the xopen swab() function, contributed by Kensuke Otake <kensuke@phreaker.net>
Diffstat (limited to 'libc/unistd/swab.c')
-rw-r--r--libc/unistd/swab.c18
1 files changed, 18 insertions, 0 deletions
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 <unistd.h>
+#include <sys/types.h>
+
+/* swab() swaps the position of two adjacent bytes, every two bytes.
+ * Contributed by Kensuke Otake <kensuke@phreaker.net> */
+
+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;
+ }
+}