Add POSIX swab.

Surprisingly to me, there are actual uses of `swab` in the codebases
I have available to search, including one with a #ifndef __ANDROID__
around it.

Bug: N/A
Test: ran tests
Change-Id: Ic91b78ae22bb65c346cb46dd38916f48d979abe0
diff --git a/libc/Android.bp b/libc/Android.bp
index 81135ea..2e5ec00 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1534,6 +1534,7 @@
         "bionic/strings_l.cpp",
         "bionic/strsignal.cpp",
         "bionic/strtold.cpp",
+        "bionic/swab.cpp",
         "bionic/symlink.cpp",
         "bionic/sync_file_range.cpp",
         "bionic/sys_msg.cpp",
diff --git a/libc/bionic/swab.cpp b/libc/bionic/swab.cpp
new file mode 100644
index 0000000..bc53ba4
--- /dev/null
+++ b/libc/bionic/swab.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+void swab(const void* void_src, void* void_dst, ssize_t byte_count) {
+  const uint8_t* src = static_cast<const uint8_t*>(void_src);
+  uint8_t* dst = static_cast<uint8_t*>(void_dst);
+  while (byte_count > 1) {
+    uint8_t x = *src++;
+    uint8_t y = *src++;
+    *dst++ = y;
+    *dst++ = x;
+    byte_count -= 2;
+  }
+}
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 9cfb918..a2beb38 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -246,6 +246,8 @@
 int getdomainname(char* __buf, size_t __buf_size) __INTRODUCED_IN(26);
 int setdomainname(const char* __name, size_t __n) __INTRODUCED_IN(26);
 
+void swab(const void* __src, void* __dst, ssize_t __byte_count) __INTRODUCED_IN_FUTURE;
+
 #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
 #include <bits/fortify/unistd.h>
 #endif
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index 981dd59..f1dafb1 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1366,6 +1366,7 @@
     sethostent;
     setnetent;
     setprotoent;
+    swab;
     syncfs;
 } LIBC_O;
 
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index 29c5235..2ba32bf 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1286,6 +1286,7 @@
     sethostent;
     setnetent;
     setprotoent;
+    swab;
     syncfs;
 } LIBC_O;
 
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index eafbbd7..0f1e325 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1391,6 +1391,7 @@
     sethostent;
     setnetent;
     setprotoent;
+    swab;
     syncfs;
 } LIBC_O;
 
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index a32131f..8a525bc 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1350,6 +1350,7 @@
     sethostent;
     setnetent;
     setprotoent;
+    swab;
     syncfs;
 } LIBC_O;
 
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index 29c5235..2ba32bf 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1286,6 +1286,7 @@
     sethostent;
     setnetent;
     setprotoent;
+    swab;
     syncfs;
 } LIBC_O;
 
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index f1308ea..b19e181 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1348,6 +1348,7 @@
     sethostent;
     setnetent;
     setprotoent;
+    swab;
     syncfs;
 } LIBC_O;
 
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index 29c5235..2ba32bf 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1286,6 +1286,7 @@
     sethostent;
     setnetent;
     setprotoent;
+    swab;
     syncfs;
 } LIBC_O;