Export bionic's resolv base64 functions to musl
Musl doesn't provide the resolv b64_* functions, but adb uses them.
Export them from bionic.
Bug: 190084016
Test: m USE_HOST_MUSL=true host-native
Change-Id: I37837e6179a15754d4cbd89e67649df9dea9d9f1
diff --git a/libc/Android.bp b/libc/Android.bp
index 63cdd35..83fe1db 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -2592,6 +2592,29 @@
stl: "none",
}
+cc_library_host_static {
+ name: "libb64",
+ visibility: ["//external/musl"],
+ srcs: ["upstream-openbsd/lib/libc/net/base64.c"],
+ export_include_dirs: ["b64/include"],
+ local_include_dirs: [
+ "private",
+ "upstream-openbsd/android/include",
+ ],
+ cflags: [
+ "-include openbsd-compat.h",
+ ],
+ enabled: false,
+ target: {
+ musl: {
+ enabled: true,
+ system_shared_libs: [],
+ header_libs: ["libc_musl_headers"],
+ },
+ },
+ stl: "none",
+}
+
subdirs = [
"bionic/scudo",
]
diff --git a/libc/NOTICE b/libc/NOTICE
index ff16da7..9cbbde2 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -910,6 +910,34 @@
-------------------------------------------------------------------
+Copyright (C) 2022 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.
+
+-------------------------------------------------------------------
+
Copyright (c) 1980, 1983, 1988, 1993
The Regents of the University of California. All rights reserved.
diff --git a/libc/b64/include/bionic/b64.h b/libc/b64/include/bionic/b64.h
new file mode 100644
index 0000000..f365bae
--- /dev/null
+++ b/libc/b64/include/bionic/b64.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#pragma once
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+int b64_ntop(unsigned char const* __src, size_t __src_size, char* __dst, size_t __dst_size);
+int b64_pton(char const* __src, u_char* __dst, size_t __dst_size);
+
+__END_DECLS
diff --git a/tests/resolv_test.cpp b/tests/resolv_test.cpp
index 4425503..0cd8e63 100644
--- a/tests/resolv_test.cpp
+++ b/tests/resolv_test.cpp
@@ -33,7 +33,6 @@
#include <gtest/gtest.h>
TEST(resolv, b64_pton_28035006) {
-#if !defined(ANDROID_HOST_MUSL)
// Test data from https://groups.google.com/forum/#!topic/mailing.openbsd.tech/w3ACIlklJkI.
const char* data =
"p1v3+nehH3N3n+/OokzXpsyGF2VVpxIxkjSn3Mv/Sq74OE1iFuVU+K4bQImuVj"
@@ -44,33 +43,22 @@
// incorrectly required an extra byte. http://b/28035006.
uint8_t buf[128];
ASSERT_EQ(128, b64_pton(data, buf, sizeof(buf)));
-#else
- GTEST_SKIP() << "musl doesn't have b64_pton";
-#endif
}
TEST(resolv, b64_ntop) {
-#if !defined(ANDROID_HOST_MUSL)
char buf[128];
memset(buf, 'x', sizeof(buf));
ASSERT_EQ(static_cast<int>(strlen("aGVsbG8=")),
b64_ntop(reinterpret_cast<u_char const*>("hello"), strlen("hello"),
buf, sizeof(buf)));
ASSERT_STREQ(buf, "aGVsbG8=");
-#else
- GTEST_SKIP() << "musl doesn't have b64_ntop";
-#endif
}
TEST(resolv, b64_pton) {
-#if !defined(ANDROID_HOST_MUSL)
u_char buf[128];
memset(buf, 'x', sizeof(buf));
ASSERT_EQ(static_cast<int>(strlen("hello")), b64_pton("aGVsbG8=", buf, sizeof(buf)));
ASSERT_STREQ(reinterpret_cast<char*>(buf), "hello");
-#else
- GTEST_SKIP() << "musl doesn't have b64_pton";
-#endif
}
TEST(resolv, p_class) {