summaryrefslogtreecommitdiff
path: root/lib/libc/unistd/swab.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/unistd/swab.c')
-rw-r--r--lib/libc/unistd/swab.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/libc/unistd/swab.c b/lib/libc/unistd/swab.c
new file mode 100644
index 00000000..5e4e7e3b
--- /dev/null
+++ b/lib/libc/unistd/swab.c
@@ -0,0 +1,17 @@
+#include <unistd.h>
+
+void swab(const void *restrict src, void *restrict dest, ssize_t nbytes)
+{
+ const char *s = src;
+ char *d = dest;
+
+ if (nbytes <= 0)
+ return;
+
+ ssize_t n = nbytes & ~1;
+
+ for (ssize_t i = 0; i < n; i += 2) {
+ d[i] = s[i + 1];
+ d[i + 1] = s[i];
+ }
+}