From 6f6ef39b481d8b3f7fb24536b3e28327a48fcec4 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Wed, 16 Jan 2019 14:17:08 -0800 Subject: [PATCH] Remove liblog/uio.c and readv() isn't used by anyone, writev() has one easily replaced user. uio.h can be left as a private header for windows compatibility with struct iovec. Test: build Change-Id: I33d4c6bdee6fd818271f78ae06abdd2aa09430f2 --- liblog/Android.bp | 1 - liblog/fake_log_device.cpp | 1 - liblog/fake_log_device.h | 1 + liblog/include/log/log.h | 1 - liblog/logd_writer.cpp | 1 + liblog/logger.h | 2 +- liblog/logger_write.cpp | 8 ++-- liblog/pmsg_writer.cpp | 1 + liblog/stderr_write.cpp | 2 +- liblog/tests/liblog_benchmark.cpp | 1 + liblog/uio.cpp | 73 ------------------------------- liblog/{include/log => }/uio.h | 28 ++---------- libstats/statsd_writer.c | 1 + 13 files changed, 14 insertions(+), 107 deletions(-) delete mode 100644 liblog/uio.cpp rename liblog/{include/log => }/uio.h (67%) diff --git a/liblog/Android.bp b/liblog/Android.bp index e213e9026..58d88dfa8 100644 --- a/liblog/Android.bp +++ b/liblog/Android.bp @@ -86,7 +86,6 @@ cc_library { ldflags: ["-Wl,--hash-style=both"], }, windows: { - srcs: ["uio.cpp"], enabled: true, }, not_windows: { diff --git a/liblog/fake_log_device.cpp b/liblog/fake_log_device.cpp index 4f3a23061..5daae41e4 100644 --- a/liblog/fake_log_device.cpp +++ b/liblog/fake_log_device.cpp @@ -33,7 +33,6 @@ #include #include -#include #include "log_portability.h" diff --git a/liblog/fake_log_device.h b/liblog/fake_log_device.h index 74d434e60..ef0beb68a 100644 --- a/liblog/fake_log_device.h +++ b/liblog/fake_log_device.h @@ -19,6 +19,7 @@ #include #include "log_portability.h" +#include "uio.h" struct iovec; diff --git a/liblog/include/log/log.h b/liblog/include/log/log.h index df5affb4a..6f93396aa 100644 --- a/liblog/include/log/log.h +++ b/liblog/include/log/log.h @@ -34,7 +34,6 @@ #include #include #include -#include /* helper to define iovec for portability */ #ifdef __cplusplus extern "C" { diff --git a/liblog/logd_writer.cpp b/liblog/logd_writer.cpp index 4731487b6..ed906b3ee 100644 --- a/liblog/logd_writer.cpp +++ b/liblog/logd_writer.cpp @@ -38,6 +38,7 @@ #include "config_write.h" #include "log_portability.h" #include "logger.h" +#include "uio.h" /* branchless on many architectures. */ #define min(x, y) ((y) ^ (((x) ^ (y)) & -((x) < (y)))) diff --git a/liblog/logger.h b/liblog/logger.h index 25ee06547..b2479d274 100644 --- a/liblog/logger.h +++ b/liblog/logger.h @@ -21,9 +21,9 @@ #include #include -#include #include "log_portability.h" +#include "uio.h" __BEGIN_DECLS diff --git a/liblog/logger_write.cpp b/liblog/logger_write.cpp index fbe687455..af8cb2d24 100644 --- a/liblog/logger_write.cpp +++ b/liblog/logger_write.cpp @@ -33,6 +33,7 @@ #include "config_write.h" #include "log_portability.h" #include "logger.h" +#include "uio.h" #define LOG_BUF_SIZE 1024 @@ -524,11 +525,8 @@ LIBLOG_ABI_PUBLIC void __android_log_assert(const char* cond, const char* tag, c // Log assertion failures to stderr for the benefit of "adb shell" users // and gtests (http://b/23675822). - struct iovec iov[2] = { - {buf, strlen(buf)}, - {(char*)"\n", 1}, - }; - TEMP_FAILURE_RETRY(writev(2, iov, 2)); + TEMP_FAILURE_RETRY(write(2, buf, strlen(buf))); + TEMP_FAILURE_RETRY(write(2, "\n", 1)); __android_log_write(ANDROID_LOG_FATAL, tag, buf); abort(); /* abort so we have a chance to debug the situation */ diff --git a/liblog/pmsg_writer.cpp b/liblog/pmsg_writer.cpp index c50c7f7be..b2fc6d06e 100644 --- a/liblog/pmsg_writer.cpp +++ b/liblog/pmsg_writer.cpp @@ -33,6 +33,7 @@ #include "config_write.h" #include "log_portability.h" #include "logger.h" +#include "uio.h" static int pmsgOpen(); static void pmsgClose(); diff --git a/liblog/stderr_write.cpp b/liblog/stderr_write.cpp index f9cb37d02..28195aac1 100644 --- a/liblog/stderr_write.cpp +++ b/liblog/stderr_write.cpp @@ -37,10 +37,10 @@ #include #include #include -#include #include "log_portability.h" #include "logger.h" +#include "uio.h" static int stderrOpen(); static void stderrClose(); diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp index c2f3f837a..c8ac321f8 100644 --- a/liblog/tests/liblog_benchmark.cpp +++ b/liblog/tests/liblog_benchmark.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/liblog/uio.cpp b/liblog/uio.cpp deleted file mode 100644 index 05145d736..000000000 --- a/liblog/uio.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2007-2014 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. - */ - -#if defined(_WIN32) - -#include - -#include - -#include "log_portability.h" - -LIBLOG_ABI_PUBLIC int readv(int fd, struct iovec* vecs, int count) { - int total = 0; - - for (; count > 0; count--, vecs++) { - char* buf = static_cast(vecs->iov_base); - int len = vecs->iov_len; - - while (len > 0) { - int ret = read(fd, buf, len); - if (ret < 0) { - if (total == 0) total = -1; - goto Exit; - } - if (ret == 0) goto Exit; - - total += ret; - buf += ret; - len -= ret; - } - } -Exit: - return total; -} - -LIBLOG_ABI_PUBLIC int writev(int fd, const struct iovec* vecs, int count) { - int total = 0; - - for (; count > 0; count--, vecs++) { - const char* buf = static_cast(vecs->iov_base); - int len = vecs->iov_len; - - while (len > 0) { - int ret = write(fd, buf, len); - if (ret < 0) { - if (total == 0) total = -1; - goto Exit; - } - if (ret == 0) goto Exit; - - total += ret; - buf += ret; - len -= ret; - } - } -Exit: - return total; -} - -#endif diff --git a/liblog/include/log/uio.h b/liblog/uio.h similarity index 67% rename from liblog/include/log/uio.h rename to liblog/uio.h index 7feb5527f..c85893cf4 100644 --- a/liblog/include/log/uio.h +++ b/liblog/uio.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2014 The Android Open Source Project + * Copyright (C) 2019 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. @@ -16,32 +16,12 @@ #pragma once -#if !defined(_WIN32) - -#include - -#else - -#ifdef __cplusplus -extern "C" { -#endif - -// -// Implementation of sys/uio.h for Win32. -// - +#if defined(_WIN32) #include - struct iovec { void* iov_base; size_t iov_len; }; - -extern int readv(int fd, struct iovec* vecs, int count); -extern int writev(int fd, const struct iovec* vecs, int count); - -#ifdef __cplusplus -} -#endif - +#else +#include #endif diff --git a/libstats/statsd_writer.c b/libstats/statsd_writer.c index f00fc2d89..f5be95c19 100644 --- a/libstats/statsd_writer.c +++ b/libstats/statsd_writer.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include