Merge "liblog: __android_log_pmsg_file_write() cleanup"
diff --git a/Android.bp b/Android.bp
deleted file mode 100644
index 949a7fe..0000000
--- a/Android.bp
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (C) 2016 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-ndk_headers {
- name: "liblog_headers",
- from: "include/android",
- to: "android",
- srcs: ["include/android/log.h"],
-}
-
-optional_subdirs = ["*"]
diff --git a/adb/Android.mk b/adb/Android.mk
index e17240b..be04cfa 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -18,11 +18,9 @@
-DADB_REVISION='"$(adb_version)"' \
ADB_COMMON_linux_CFLAGS := \
- -std=c++14 \
-Wexit-time-destructors \
ADB_COMMON_darwin_CFLAGS := \
- -std=c++14 \
-Wexit-time-destructors \
# Define windows.h and tchar.h Unicode preprocessor symbols so that
diff --git a/adb/bugreport.cpp b/adb/bugreport.cpp
index c348dd5..24be529 100644
--- a/adb/bugreport.cpp
+++ b/adb/bugreport.cpp
@@ -21,6 +21,7 @@
#include <string>
#include <vector>
+#include <android-base/parseint.h>
#include <android-base/strings.h>
#include "sysdeps.h"
@@ -143,9 +144,11 @@
//
size_t idx1 = line.rfind(BUGZ_PROGRESS_PREFIX) + strlen(BUGZ_PROGRESS_PREFIX);
size_t idx2 = line.rfind(BUGZ_PROGRESS_SEPARATOR);
- int progress = std::stoi(line.substr(idx1, (idx2 - idx1)));
- int total = std::stoi(line.substr(idx2 + 1));
- br_->UpdateProgress(line_message_, progress, total);
+ int progress, total;
+ if (android::base::ParseInt(line.substr(idx1, (idx2 - idx1)), &progress) &&
+ android::base::ParseInt(line.substr(idx2 + 1), &total)) {
+ br_->UpdateProgress(line_message_, progress, total);
+ }
} else {
invalid_lines_.push_back(line);
}
diff --git a/adb/sysdeps.h b/adb/sysdeps.h
index ded8214..ad9b9fd 100644
--- a/adb/sysdeps.h
+++ b/adb/sysdeps.h
@@ -598,7 +598,10 @@
}
inline int network_loopback_server(int port, int type, std::string* error) {
- return _fd_set_error_str(socket_loopback_server(port, type), error);
+ int fd = socket_loopback_server(port, type);
+ if (fd < 0 && errno == EAFNOSUPPORT)
+ return _fd_set_error_str(socket_loopback_server6(port, type), error);
+ return _fd_set_error_str(fd, error);
}
inline int network_inaddr_any_server(int port, int type, std::string* error) {
diff --git a/base/include/android-base/parseint.h b/base/include/android-base/parseint.h
index 7415409..2c8570e 100644
--- a/base/include/android-base/parseint.h
+++ b/base/include/android-base/parseint.h
@@ -21,13 +21,15 @@
#include <stdlib.h>
#include <limits>
+#include <string>
namespace android {
namespace base {
// Parses the unsigned decimal integer in the string 's' and sets 'out' to
// that value. Optionally allows the caller to define a 'max' beyond which
-// otherwise valid values will be rejected. Returns boolean success.
+// otherwise valid values will be rejected. Returns boolean success; 'out'
+// is untouched if parsing fails.
template <typename T>
bool ParseUint(const char* s, T* out,
T max = std::numeric_limits<T>::max()) {
@@ -45,10 +47,17 @@
return true;
}
+// TODO: string_view
+template <typename T>
+bool ParseUint(const std::string& s, T* out,
+ T max = std::numeric_limits<T>::max()) {
+ return ParseUint(s.c_str(), out, max);
+}
+
// Parses the signed decimal integer in the string 's' and sets 'out' to
// that value. Optionally allows the caller to define a 'min' and 'max
// beyond which otherwise valid values will be rejected. Returns boolean
-// success.
+// success; 'out' is untouched if parsing fails.
template <typename T>
bool ParseInt(const char* s, T* out,
T min = std::numeric_limits<T>::min(),
@@ -67,6 +76,14 @@
return true;
}
+// TODO: string_view
+template <typename T>
+bool ParseInt(const std::string& s, T* out,
+ T min = std::numeric_limits<T>::min(),
+ T max = std::numeric_limits<T>::max()) {
+ return ParseInt(s.c_str(), out, min, max);
+}
+
} // namespace base
} // namespace android
diff --git a/base/parseint_test.cpp b/base/parseint_test.cpp
index 6a3ba31..483b1d3 100644
--- a/base/parseint_test.cpp
+++ b/base/parseint_test.cpp
@@ -19,7 +19,7 @@
#include <gtest/gtest.h>
TEST(parseint, signed_smoke) {
- int i;
+ int i = 0;
ASSERT_FALSE(android::base::ParseInt("x", &i));
ASSERT_FALSE(android::base::ParseInt("123x", &i));
@@ -28,7 +28,7 @@
ASSERT_TRUE(android::base::ParseInt("-123", &i));
ASSERT_EQ(-123, i);
- short s;
+ short s = 0;
ASSERT_TRUE(android::base::ParseInt("1234", &s));
ASSERT_EQ(1234, s);
@@ -39,7 +39,7 @@
}
TEST(parseint, unsigned_smoke) {
- unsigned int i;
+ unsigned int i = 0u;
ASSERT_FALSE(android::base::ParseUint("x", &i));
ASSERT_FALSE(android::base::ParseUint("123x", &i));
@@ -47,7 +47,7 @@
ASSERT_EQ(123u, i);
ASSERT_FALSE(android::base::ParseUint("-123", &i));
- unsigned short s;
+ unsigned short s = 0u;
ASSERT_TRUE(android::base::ParseUint("1234", &s));
ASSERT_EQ(1234u, s);
@@ -58,21 +58,41 @@
}
TEST(parseint, no_implicit_octal) {
- int i;
+ int i = 0;
ASSERT_TRUE(android::base::ParseInt("0123", &i));
ASSERT_EQ(123, i);
- unsigned int u;
+ unsigned int u = 0u;
ASSERT_TRUE(android::base::ParseUint("0123", &u));
ASSERT_EQ(123u, u);
}
TEST(parseint, explicit_hex) {
- int i;
+ int i = 0;
ASSERT_TRUE(android::base::ParseInt("0x123", &i));
ASSERT_EQ(0x123, i);
- unsigned int u;
+ unsigned int u = 0u;
ASSERT_TRUE(android::base::ParseUint("0x123", &u));
ASSERT_EQ(0x123u, u);
}
+
+TEST(parseint, string) {
+ int i = 0;
+ ASSERT_TRUE(android::base::ParseInt(std::string("123"), &i));
+ ASSERT_EQ(123, i);
+
+ unsigned int u = 0u;
+ ASSERT_TRUE(android::base::ParseUint(std::string("123"), &u));
+ ASSERT_EQ(123u, u);
+}
+
+TEST(parseint, untouched_on_failure) {
+ int i = 123;
+ ASSERT_FALSE(android::base::ParseInt("456x", &i));
+ ASSERT_EQ(123, i);
+
+ unsigned int u = 123u;
+ ASSERT_FALSE(android::base::ParseInt("456x", &u));
+ ASSERT_EQ(123u, u);
+}
diff --git a/base/properties.cpp b/base/properties.cpp
index fab3005..37daf9a 100644
--- a/base/properties.cpp
+++ b/base/properties.cpp
@@ -52,7 +52,7 @@
T GetIntProperty(const std::string& key, T default_value, T min, T max) {
T result;
std::string value = GetProperty(key, "");
- if (!value.empty() && android::base::ParseInt(value.c_str(), &result, min, max)) return result;
+ if (!value.empty() && android::base::ParseInt(value, &result, min, max)) return result;
return default_value;
}
@@ -60,7 +60,7 @@
T GetUintProperty(const std::string& key, T default_value, T max) {
T result;
std::string value = GetProperty(key, "");
- if (!value.empty() && android::base::ParseUint(value.c_str(), &result, max)) return result;
+ if (!value.empty() && android::base::ParseUint(value, &result, max)) return result;
return default_value;
}
diff --git a/bootstat/boot_event_record_store.cpp b/bootstat/boot_event_record_store.cpp
index 346eada..78be944 100644
--- a/bootstat/boot_event_record_store.cpp
+++ b/bootstat/boot_event_record_store.cpp
@@ -59,7 +59,7 @@
// Ignore existing bootstat records (which do not contain file content).
if (!content.empty()) {
int32_t value;
- if (android::base::ParseInt(content.c_str(), &value)) {
+ if (android::base::ParseInt(content, &value)) {
bootstat::LogHistogram("bootstat_mtime_matches_content", value == *uptime);
}
}
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index 0ab4c98..e5ddab3 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -60,7 +60,7 @@
BootEventRecordStore boot_event_store;
if (!value_str.empty()) {
int32_t value = 0;
- if (android::base::ParseInt(value_str.c_str(), &value)) {
+ if (android::base::ParseInt(value_str, &value)) {
boot_event_store.AddBootEventWithValue(event, value);
}
} else {
@@ -193,7 +193,7 @@
std::string build_date_str = GetProperty("ro.build.date.utc");
int32_t build_date;
- if (!android::base::ParseInt(build_date_str.c_str(), &build_date)) {
+ if (!android::base::ParseInt(build_date_str, &build_date)) {
return std::string();
}
diff --git a/debuggerd/Android.mk b/debuggerd/Android.mk
index fdedb76..1fc850f 100644
--- a/debuggerd/Android.mk
+++ b/debuggerd/Android.mk
@@ -1,7 +1,6 @@
LOCAL_PATH := $(call my-dir)
common_cppflags := \
- -std=gnu++11 \
-W \
-Wall \
-Wextra \
diff --git a/fastboot/Android.mk b/fastboot/Android.mk
index d69a81f..286de5b 100644
--- a/fastboot/Android.mk
+++ b/fastboot/Android.mk
@@ -37,7 +37,6 @@
LOCAL_MODULE := fastboot
LOCAL_MODULE_TAGS := debug
LOCAL_MODULE_HOST_OS := darwin linux windows
-LOCAL_CONLYFLAGS += -std=gnu99
LOCAL_CFLAGS += -Wall -Wextra -Werror -Wunreachable-code
LOCAL_CFLAGS += -DFASTBOOT_REVISION='"$(fastboot_version)"'
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index d6b631f..4cd423a 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -755,7 +755,7 @@
max_download_size = android::base::Trim(max_download_size);
uint64_t limit;
- if (!android::base::ParseUint(max_download_size.c_str(), &limit)) {
+ if (!android::base::ParseUint(max_download_size, &limit)) {
fprintf(stderr, "couldn't parse max-download-size '%s'\n", max_download_size.c_str());
return 0;
}
@@ -903,7 +903,7 @@
if (!fb_getvar(transport, "slot-count", &var)) {
if (supports_AB_obsolete(transport)) return 2; // Legacy support
}
- if (!android::base::ParseInt(var.c_str(), &count)) return 0;
+ if (!android::base::ParseInt(var, &count)) return 0;
return count;
}
@@ -1362,7 +1362,7 @@
}
int64_t size;
- if (!android::base::ParseInt(partition_size.c_str(), &size)) {
+ if (!android::base::ParseInt(partition_size, &size)) {
fprintf(stderr, "Couldn't parse partition size '%s'.\n", partition_size.c_str());
return;
}
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index f81e7d9..0c90a54 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -29,6 +29,7 @@
#include <memory>
#include <android-base/file.h>
+#include <android-base/parseint.h>
#include <android-base/strings.h>
#include <batteryservice/BatteryService.h>
#include <cutils/klog.h>
@@ -182,7 +183,7 @@
int value = 0;
if (readFromFile(path, &buf) > 0)
- value = std::stoi(buf.c_str(), NULL, 0);
+ android::base::ParseInt(buf, &value);
return value;
}
diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h
index 813dadc..7d6a988 100644
--- a/include/cutils/native_handle.h
+++ b/include/cutils/native_handle.h
@@ -17,10 +17,17 @@
#ifndef NATIVE_HANDLE_H_
#define NATIVE_HANDLE_H_
+#include <stdalign.h>
+
#ifdef __cplusplus
extern "C" {
#endif
+/* Declare a char array for use with native_handle_init */
+#define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \
+ alignas(native_handle_t) char name[ \
+ sizeof(native_handle_t) + sizeof(int) * (maxFds + maxInts)]
+
typedef struct native_handle
{
int version; /* sizeof(native_handle_t) */
@@ -46,6 +53,14 @@
*/
int native_handle_close(const native_handle_t* h);
+/*
+ * native_handle_init
+ *
+ * Initializes a native_handle_t from storage. storage must be declared with
+ * NATIVE_HANDLE_DECLARE_STORAGE. numFds and numInts must not respectively
+ * exceed maxFds and maxInts used to declare the storage.
+ */
+native_handle_t* native_handle_init(char* storage, int numFds, int numInts);
/*
* native_handle_create
diff --git a/include/cutils/sockets.h b/include/cutils/sockets.h
index a93c8ea..4626e7a 100644
--- a/include/cutils/sockets.h
+++ b/include/cutils/sockets.h
@@ -84,11 +84,11 @@
*
* These functions return INVALID_SOCKET (-1) on failure for all platforms.
*/
-int socket_loopback_client(int port, int type);
cutils_socket_t socket_network_client(const char* host, int port, int type);
int socket_network_client_timeout(const char* host, int port, int type,
int timeout, int* getaddrinfo_error);
int socket_loopback_server(int port, int type);
+int socket_loopback_server6(int port, int type);
int socket_local_server(const char* name, int namespaceId, int type);
int socket_local_server_bind(int s, const char* name, int namespaceId);
int socket_local_client_connect(int fd, const char *name, int namespaceId,
diff --git a/init/builtins.cpp b/init/builtins.cpp
index f4ba018..da4b84e 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -304,7 +304,7 @@
/* mkdir <path> [mode] [owner] [group] */
if (args.size() >= 3) {
- mode = std::stoul(args[2], 0, 8);
+ mode = std::strtoul(args[2].c_str(), 0, 8);
}
ret = make_dir(args[1].c_str(), mode);
@@ -637,10 +637,13 @@
static int do_setrlimit(const std::vector<std::string>& args) {
struct rlimit limit;
int resource;
- resource = std::stoi(args[1]);
- limit.rlim_cur = std::stoi(args[2]);
- limit.rlim_max = std::stoi(args[3]);
- return setrlimit(resource, &limit);
+ if (android::base::ParseInt(args[1], &resource) &&
+ android::base::ParseUint(args[2], &limit.rlim_cur) &&
+ android::base::ParseUint(args[3], &limit.rlim_max)) {
+ return setrlimit(resource, &limit);
+ }
+ LOG(WARNING) << "ignoring setrlimit " << args[1] << " " << args[2] << " " << args[3];
+ return -1;
}
static int do_start(const std::vector<std::string>& args) {
@@ -709,7 +712,7 @@
std::string timeout = property_get("ro.build.shutdown_timeout");
unsigned int delay = 0;
- if (android::base::ParseUint(timeout.c_str(), &delay) && delay > 0) {
+ if (android::base::ParseUint(timeout, &delay) && delay > 0) {
Timer t;
// Ask all services to terminate.
ServiceManager::GetInstance().ForEachService(
@@ -764,13 +767,11 @@
}
static int do_sysclktz(const std::vector<std::string>& args) {
- struct timezone tz;
-
- memset(&tz, 0, sizeof(tz));
- tz.tz_minuteswest = std::stoi(args[1]);
- if (settimeofday(NULL, &tz))
- return -1;
- return 0;
+ struct timezone tz = {};
+ if (android::base::ParseInt(args[1], &tz.tz_minuteswest) && settimeofday(NULL, &tz) != -1) {
+ return 0;
+ }
+ return -1;
}
static int do_verity_load_state(const std::vector<std::string>& args) {
@@ -914,7 +915,8 @@
static int do_loglevel(const std::vector<std::string>& args) {
// TODO: support names instead/as well?
- int log_level = std::stoi(args[1]);
+ int log_level = -1;
+ android::base::ParseInt(args[1], &log_level);
android::base::LogSeverity severity;
switch (log_level) {
case 7: severity = android::base::DEBUG; break;
@@ -947,9 +949,12 @@
if (args.size() == 2) {
return wait_for_file(args[1].c_str(), COMMAND_RETRY_TIMEOUT);
} else if (args.size() == 3) {
- return wait_for_file(args[1].c_str(), std::stoi(args[2]));
- } else
- return -1;
+ int timeout;
+ if (android::base::ParseInt(args[2], &timeout)) {
+ return wait_for_file(args[1].c_str(), timeout);
+ }
+ }
+ return -1;
}
/*
diff --git a/init/service.cpp b/init/service.cpp
index 503d84f..22fb013 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -31,6 +31,7 @@
#include <selinux/selinux.h>
#include <android-base/file.h>
+#include <android-base/parseint.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <cutils/android_reboot.h>
@@ -46,6 +47,7 @@
#include "property_service.h"
#include "util.h"
+using android::base::ParseInt;
using android::base::StringPrintf;
using android::base::WriteStringToFile;
@@ -351,22 +353,19 @@
}
bool Service::ParsePriority(const std::vector<std::string>& args, std::string* err) {
- priority_ = std::stoi(args[1]);
-
- if (priority_ < ANDROID_PRIORITY_HIGHEST || priority_ > ANDROID_PRIORITY_LOWEST) {
- priority_ = 0;
+ priority_ = 0;
+ if (!ParseInt(args[1], &priority_,
+ static_cast<int>(ANDROID_PRIORITY_LOWEST),
+ static_cast<int>(ANDROID_PRIORITY_HIGHEST))) {
*err = StringPrintf("process priority value must be range %d - %d",
ANDROID_PRIORITY_HIGHEST, ANDROID_PRIORITY_LOWEST);
return false;
}
-
return true;
}
bool Service::ParseIoprio(const std::vector<std::string>& args, std::string* err) {
- ioprio_pri_ = std::stoul(args[2], 0, 8);
-
- if (ioprio_pri_ < 0 || ioprio_pri_ > 7) {
+ if (!ParseInt(args[2], &ioprio_pri_, 0, 7)) {
*err = "priority value must be range 0 - 7";
return false;
}
@@ -387,7 +386,12 @@
bool Service::ParseKeycodes(const std::vector<std::string>& args, std::string* err) {
for (std::size_t i = 1; i < args.size(); i++) {
- keycodes_.emplace_back(std::stoi(args[i]));
+ int code;
+ if (ParseInt(args[i], &code)) {
+ keycodes_.emplace_back(code);
+ } else {
+ LOG(WARNING) << "ignoring invalid keycode: " << args[i];
+ }
}
return true;
}
@@ -420,17 +424,13 @@
}
bool Service::ParseOomScoreAdjust(const std::vector<std::string>& args, std::string* err) {
- oom_score_adjust_ = std::stol(args[1], 0, 10);
-
- if (oom_score_adjust_ < -1000 || oom_score_adjust_ > 1000) {
+ if (!ParseInt(args[1], &oom_score_adjust_, -1000, 1000)) {
*err = "oom_score_adjust value must be in range -1000 - +1000";
return false;
}
-
return true;
}
-
bool Service::ParseSeclabel(const std::vector<std::string>& args, std::string* err) {
seclabel_ = args[1];
return true;
@@ -448,7 +448,7 @@
return false;
}
- int perm = std::stoul(args[3], 0, 8);
+ int perm = std::strtoul(args[3].c_str(), 0, 8);
uid_t uid = args.size() > 4 ? decode_uid(args[4].c_str()) : 0;
gid_t gid = args.size() > 5 ? decode_uid(args[5].c_str()) : 0;
std::string socketcon = args.size() > 6 ? args[6] : "";
diff --git a/libbacktrace/Android.bp b/libbacktrace/Android.bp
index 93d997b..85b5597 100644
--- a/libbacktrace/Android.bp
+++ b/libbacktrace/Android.bp
@@ -21,8 +21,6 @@
"-Wall",
"-Werror",
],
- conlyflags: ["-std=gnu99"],
- cppflags: ["-std=gnu++11"],
clang_cflags: ["-Wno-inline-asm"],
diff --git a/libbacktrace/Android.mk b/libbacktrace/Android.mk
index 56a3970..bb17325 100644
--- a/libbacktrace/Android.mk
+++ b/libbacktrace/Android.mk
@@ -20,12 +20,6 @@
-Wall \
-Werror \
-libbacktrace_common_conlyflags := \
- -std=gnu99 \
-
-libbacktrace_common_cppflags := \
- -std=gnu++11 \
-
libbacktrace_common_c_includes := \
external/libunwind/include/tdep \
diff --git a/libcrypto_utils/Android.bp b/libcrypto_utils/Android.bp
index ca7bd31..f2560e6 100644
--- a/libcrypto_utils/Android.bp
+++ b/libcrypto_utils/Android.bp
@@ -24,7 +24,6 @@
"-Wall",
"-Wextra",
"-Werror",
- "-std=c99",
],
local_include_dirs: ["include"],
export_include_dirs: ["include"],
diff --git a/libcrypto_utils/tests/Android.mk b/libcrypto_utils/tests/Android.mk
index bdaef71..ef3d0cf 100644
--- a/libcrypto_utils/tests/Android.mk
+++ b/libcrypto_utils/tests/Android.mk
@@ -19,6 +19,6 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto_utils_test
LOCAL_SRC_FILES := android_pubkey_test.cpp
-LOCAL_CFLAGS := -Wall -Werror -Wextra -std=c++11
+LOCAL_CFLAGS := -Wall -Werror -Wextra
LOCAL_SHARED_LIBRARIES := libcrypto_utils libcrypto
include $(BUILD_HOST_NATIVE_TEST)
diff --git a/libcutils/Android.bp b/libcutils/Android.bp
index 955c0ec..943926b 100644
--- a/libcutils/Android.bp
+++ b/libcutils/Android.bp
@@ -23,7 +23,6 @@
"socket_inaddr_any_server_unix.c",
"socket_local_client_unix.c",
"socket_local_server_unix.c",
- "socket_loopback_client_unix.c",
"socket_loopback_server_unix.c",
"socket_network_client_unix.c",
"sockets_unix.cpp",
@@ -89,10 +88,6 @@
static_libs: ["libdebuggerd_client"],
export_static_lib_headers: ["libdebuggerd_client"],
-
- cflags: [
- "-std=gnu90",
- ],
},
android_arm: {
diff --git a/libcutils/native_handle.c b/libcutils/native_handle.c
index cae146d..9f4840a 100644
--- a/libcutils/native_handle.c
+++ b/libcutils/native_handle.c
@@ -28,6 +28,20 @@
static const int kMaxNativeFds = 1024;
static const int kMaxNativeInts = 1024;
+native_handle_t* native_handle_init(char* storage, int numFds, int numInts)
+{
+ if ((uintptr_t) storage % alignof(native_handle_t)) {
+ return NULL;
+ }
+
+ native_handle_t* handle = (native_handle_t*) storage;
+ handle->version = sizeof(native_handle_t);
+ handle->numFds = numFds;
+ handle->numInts = numInts;
+
+ return handle;
+}
+
native_handle_t* native_handle_create(int numFds, int numInts)
{
if (numFds < 0 || numInts < 0 || numFds > kMaxNativeFds || numInts > kMaxNativeInts) {
diff --git a/libcutils/socket_loopback_client_unix.c b/libcutils/socket_loopback_client_unix.c
deleted file mode 100644
index 137e369..0000000
--- a/libcutils/socket_loopback_client_unix.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#include <errno.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#if !defined(_WIN32)
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#endif
-
-#include <cutils/sockets.h>
-
-/* Connect to port on the loopback IP interface. type is
- * SOCK_STREAM or SOCK_DGRAM.
- * return is a file descriptor or -1 on error
- */
-int socket_loopback_client(int port, int type)
-{
- return socket_network_client("localhost", port, type);
-}
-
diff --git a/libcutils/socket_loopback_server_unix.c b/libcutils/socket_loopback_server_unix.c
index b600e34..7b92fd6 100644
--- a/libcutils/socket_loopback_server_unix.c
+++ b/libcutils/socket_loopback_server_unix.c
@@ -31,24 +31,18 @@
#include <cutils/sockets.h>
-/* open listen() port on loopback interface */
-int socket_loopback_server(int port, int type)
+static int _socket_loopback_server(int family, int type, struct sockaddr * addr, size_t size)
{
- struct sockaddr_in addr;
int s, n;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-
- s = socket(AF_INET, type, 0);
- if(s < 0) return -1;
+ s = socket(family, type, 0);
+ if(s < 0)
+ return -1;
n = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *) &n, sizeof(n));
- if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ if(bind(s, addr, size) < 0) {
close(s);
return -1;
}
@@ -60,10 +54,35 @@
if (ret < 0) {
close(s);
- return -1;
+ return -1;
}
}
return s;
}
+/* open listen() port on loopback IPv6 interface */
+int socket_loopback_server6(int port, int type)
+{
+ struct sockaddr_in6 addr;
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin6_family = AF_INET6;
+ addr.sin6_port = htons(port);
+ addr.sin6_addr = in6addr_loopback;
+
+ return _socket_loopback_server(AF_INET6, type, (struct sockaddr *) &addr, sizeof(addr));
+}
+
+/* open listen() port on loopback interface */
+int socket_loopback_server(int port, int type)
+{
+ struct sockaddr_in addr;
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+ addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ return _socket_loopback_server(AF_INET, type, (struct sockaddr *) &addr, sizeof(addr));
+}
diff --git a/liblog/Android.bp b/liblog/Android.bp
index c59dde9..bbaced5 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -91,6 +91,21 @@
compile_multilib: "both",
}
+// system/core/android/log.h needs some work before it can be included in the
+// NDK. It defines a *lot* of macros that previously were usable names in NDK
+// sources that used android/log.h. As an example, the following file defines
+// LOG_TAG as a variable, but the variable name gets macro replaced if we use
+// the current android/log.h.
+// https://android.googlesource.com/platform/external/deqp/+/4adc1515f867b26c19c2f7498e9de93a230a234d/framework/platform/android/tcuTestLogParserJNI.cpp#41
+//
+// For now, we keep a copy of the old NDK android/log.h in legacy-ndk-includes.
+ndk_headers {
+ name: "liblog_headers",
+ from: "legacy-ndk-includes",
+ to: "android",
+ srcs: ["legacy-ndk-includes/log.h"],
+}
+
ndk_library {
name: "liblog.ndk",
symbol_file: "liblog.map.txt",
diff --git a/liblog/legacy-ndk-includes/log.h b/liblog/legacy-ndk-includes/log.h
new file mode 100644
index 0000000..0ea4c29
--- /dev/null
+++ b/liblog/legacy-ndk-includes/log.h
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ANDROID_LOG_H
+#define _ANDROID_LOG_H
+
+/******************************************************************
+ *
+ * IMPORTANT NOTICE:
+ *
+ * This file is part of Android's set of stable system headers
+ * exposed by the Android NDK (Native Development Kit) since
+ * platform release 1.5
+ *
+ * Third-party source AND binary code relies on the definitions
+ * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
+ *
+ * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
+ * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
+ * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
+ * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
+ */
+
+/*
+ * Support routines to send messages to the Android in-kernel log buffer,
+ * which can later be accessed through the 'logcat' utility.
+ *
+ * Each log message must have
+ * - a priority
+ * - a log tag
+ * - some text
+ *
+ * The tag normally corresponds to the component that emits the log message,
+ * and should be reasonably small.
+ *
+ * Log message text may be truncated to less than an implementation-specific
+ * limit (e.g. 1023 characters max).
+ *
+ * Note that a newline character ("\n") will be appended automatically to your
+ * log message, if not already there. It is not possible to send several messages
+ * and have them appear on a single line in logcat.
+ *
+ * PLEASE USE LOGS WITH MODERATION:
+ *
+ * - Sending log messages eats CPU and slow down your application and the
+ * system.
+ *
+ * - The circular log buffer is pretty small (<64KB), sending many messages
+ * might push off other important log messages from the rest of the system.
+ *
+ * - In release builds, only send log messages to account for exceptional
+ * conditions.
+ *
+ * NOTE: These functions MUST be implemented by /system/lib/liblog.so
+ */
+
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Android log priority values, in ascending priority order.
+ */
+typedef enum android_LogPriority {
+ ANDROID_LOG_UNKNOWN = 0,
+ ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
+ ANDROID_LOG_VERBOSE,
+ ANDROID_LOG_DEBUG,
+ ANDROID_LOG_INFO,
+ ANDROID_LOG_WARN,
+ ANDROID_LOG_ERROR,
+ ANDROID_LOG_FATAL,
+ ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
+} android_LogPriority;
+
+/*
+ * Send a simple string to the log.
+ */
+int __android_log_write(int prio, const char *tag, const char *text);
+
+/*
+ * Send a formatted string to the log, used like printf(fmt,...)
+ */
+int __android_log_print(int prio, const char *tag, const char *fmt, ...)
+#if defined(__GNUC__)
+ __attribute__ ((format(printf, 3, 4)))
+#endif
+ ;
+
+/*
+ * A variant of __android_log_print() that takes a va_list to list
+ * additional parameters.
+ */
+int __android_log_vprint(int prio, const char *tag,
+ const char *fmt, va_list ap);
+
+/*
+ * Log an assertion failure and SIGTRAP the process to have a chance
+ * to inspect it, if a debugger is attached. This uses the FATAL priority.
+ */
+void __android_log_assert(const char *cond, const char *tag,
+ const char *fmt, ...)
+#if defined(__GNUC__)
+ __attribute__ ((noreturn))
+ __attribute__ ((format(printf, 3, 4)))
+#endif
+ ;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ANDROID_LOG_H */
diff --git a/liblog/tests/Android.mk b/liblog/tests/Android.mk
index a755b98..158987a 100644
--- a/liblog/tests/Android.mk
+++ b/liblog/tests/Android.mk
@@ -28,7 +28,6 @@
-Wall -Wextra \
-Werror \
-fno-builtin \
- -std=gnu++11
benchmark_src_files := \
benchmark_main.cpp \
@@ -54,7 +53,6 @@
-Wall -Wextra \
-Werror \
-fno-builtin \
- -std=gnu++11
test_src_files := \
liblog_test.cpp
diff --git a/libmemunreachable/Android.bp b/libmemunreachable/Android.bp
index 85bc421..4662368 100644
--- a/libmemunreachable/Android.bp
+++ b/libmemunreachable/Android.bp
@@ -2,7 +2,6 @@
name: "libmemunreachable_defaults",
cflags: [
- "-std=c++14",
"-Wall",
"-Wextra",
"-Werror",
diff --git a/libnativebridge/Android.bp b/libnativebridge/Android.bp
index 598dfcd..5fb56f2 100644
--- a/libnativebridge/Android.bp
+++ b/libnativebridge/Android.bp
@@ -12,7 +12,6 @@
"-Wall",
],
cppflags: [
- "-std=gnu++11",
"-fvisibility=protected",
],
diff --git a/libnativebridge/tests/Android.mk b/libnativebridge/tests/Android.mk
index 7265939..5ad1569 100644
--- a/libnativebridge/tests/Android.mk
+++ b/libnativebridge/tests/Android.mk
@@ -31,7 +31,6 @@
$(foreach file,$(test_src_files), \
$(eval include $(CLEAR_VARS)) \
$(eval LOCAL_CLANG := true) \
- $(eval LOCAL_CPPFLAGS := -std=gnu++11) \
$(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \
$(eval LOCAL_SRC_FILES := $(file)) \
$(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \
@@ -41,7 +40,6 @@
$(foreach file,$(test_src_files), \
$(eval include $(CLEAR_VARS)) \
$(eval LOCAL_CLANG := true) \
- $(eval LOCAL_CPPFLAGS := -std=gnu++11) \
$(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \
$(eval LOCAL_SRC_FILES := $(file)) \
$(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \
diff --git a/libnativebridge/tests/Android.nativebridge-dummy.mk b/libnativebridge/tests/Android.nativebridge-dummy.mk
index 551765a..e556f80 100644
--- a/libnativebridge/tests/Android.nativebridge-dummy.mk
+++ b/libnativebridge/tests/Android.nativebridge-dummy.mk
@@ -12,7 +12,7 @@
LOCAL_SRC_FILES:= $(NATIVE_BRIDGE_COMMON_SRC_FILES)
LOCAL_CLANG := true
LOCAL_CFLAGS += -Werror -Wall
-LOCAL_CPPFLAGS := -std=gnu++11 -fvisibility=protected
+LOCAL_CPPFLAGS := -fvisibility=protected
LOCAL_SHARED_LIBRARIES := libdl
LOCAL_MULTILIB := both
@@ -27,7 +27,7 @@
LOCAL_SRC_FILES:= $(NATIVE_BRIDGE_COMMON_SRC_FILES)
LOCAL_CLANG := true
LOCAL_CFLAGS += -Werror -Wall
-LOCAL_CPPFLAGS := -std=gnu++11 -fvisibility=protected
+LOCAL_CPPFLAGS := -fvisibility=protected
LOCAL_LDFLAGS := -ldl
LOCAL_MULTILIB := both
@@ -48,7 +48,7 @@
LOCAL_SRC_FILES:= $(NATIVE_BRIDGE2_COMMON_SRC_FILES)
LOCAL_CLANG := true
LOCAL_CFLAGS += -Werror -Wall
-LOCAL_CPPFLAGS := -std=gnu++11 -fvisibility=protected
+LOCAL_CPPFLAGS := -fvisibility=protected
LOCAL_SHARED_LIBRARIES := libdl
LOCAL_MULTILIB := both
@@ -63,7 +63,7 @@
LOCAL_SRC_FILES:= $(NATIVE_BRIDGE2_COMMON_SRC_FILES)
LOCAL_CLANG := true
LOCAL_CFLAGS += -Werror -Wall
-LOCAL_CPPFLAGS := -std=gnu++11 -fvisibility=protected
+LOCAL_CPPFLAGS := -fvisibility=protected
LOCAL_LDFLAGS := -ldl
LOCAL_MULTILIB := both
diff --git a/libnativeloader/Android.bp b/libnativeloader/Android.bp
index b4a69bc..30531bc 100644
--- a/libnativeloader/Android.bp
+++ b/libnativeloader/Android.bp
@@ -24,7 +24,6 @@
"-Wall",
],
cppflags: [
- "-std=gnu++14",
"-fvisibility=hidden",
],
export_include_dirs: ["include"],
diff --git a/libsync/Android.bp b/libsync/Android.bp
index 4948aa5..a4e5599 100644
--- a/libsync/Android.bp
+++ b/libsync/Android.bp
@@ -34,7 +34,6 @@
"-g",
"-Wall",
"-Werror",
- "-std=gnu++11",
"-Wno-missing-field-initializers",
"-Wno-sign-compare",
],
diff --git a/logcat/tests/Android.mk b/logcat/tests/Android.mk
index a28664e..99c2e0a 100644
--- a/logcat/tests/Android.mk
+++ b/logcat/tests/Android.mk
@@ -25,7 +25,6 @@
-Wall -Wextra \
-Werror \
-fno-builtin \
- -std=gnu++11
# -----------------------------------------------------------------------------
# Benchmarks (actually a gTest where the result code does not matter)
diff --git a/logwrapper/Android.bp b/logwrapper/Android.bp
index 41f0726..7ee0464 100644
--- a/logwrapper/Android.bp
+++ b/logwrapper/Android.bp
@@ -14,7 +14,6 @@
local_include_dirs: ["include"],
cflags: [
"-Werror",
- "-std=gnu99",
],
}
@@ -31,6 +30,5 @@
],
cflags: [
"-Werror",
- "-std=gnu99",
],
}
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 4852fa4..5319ff4 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -42,7 +42,6 @@
LOCAL_CFLAGS += $(common_cflags)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/upstream-netbsd/include/
-LOCAL_CONLYFLAGS += -std=gnu99
LOCAL_SHARED_LIBRARIES := \
libcutils \