summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2015-03-14 23:46:10 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-03-14 23:46:11 +0000
commita68c814898b31b76ca2729a50fbc1a821bd0af70 (patch)
tree54d1196083e2e4dc4b53353a2a77be6abd265066
parentf1c2ba490ef979b3d347f08535ab8b817e917e62 (diff)
parent98ff77204cef9bb8f0f27420833233622060a09e (diff)
downloadsystem_core-a68c814898b31b76ca2729a50fbc1a821bd0af70.zip
system_core-a68c814898b31b76ca2729a50fbc1a821bd0af70.tar.gz
system_core-a68c814898b31b76ca2729a50fbc1a821bd0af70.tar.bz2
Merge "Create libbase."
-rw-r--r--adb/Android.mk5
-rw-r--r--adb/adb_io_test.cpp14
-rw-r--r--base/.clang-format11
-rw-r--r--base/Android.mk96
-rw-r--r--base/CPPLINT.cfg2
-rw-r--r--base/file.cpp (renamed from libutils/file.cpp)48
-rw-r--r--base/file_test.cpp (renamed from libutils/tests/file_test.cpp)27
-rw-r--r--base/include/base/file.h (renamed from include/utils/file.h)12
-rw-r--r--base/include/base/stringprintf.h (renamed from include/utils/stringprintf.h)12
-rw-r--r--base/stringprintf.cpp (renamed from libutils/stringprintf.cpp)18
-rw-r--r--base/stringprintf_test.cpp (renamed from libutils/tests/stringprintf_test.cpp)14
-rw-r--r--init/Android.mk5
-rw-r--r--init/bootchart.cpp18
-rw-r--r--init/property_service.cpp2
-rw-r--r--init/util.cpp8
-rw-r--r--libutils/Android.mk2
-rw-r--r--libutils/tests/Android.mk2
17 files changed, 213 insertions, 83 deletions
diff --git a/adb/Android.mk b/adb/Android.mk
index 8171611..7cfbcb9 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -90,7 +90,7 @@ LOCAL_MODULE := adbd_test
LOCAL_CFLAGS := -DADB_HOST=0 $(LIBADB_CFLAGS)
LOCAL_SRC_FILES := $(LIBADB_TEST_SRCS)
LOCAL_STATIC_LIBRARIES := libadbd
-LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
+LOCAL_SHARED_LIBRARIES := liblog libbase libcutils
include $(BUILD_NATIVE_TEST)
include $(CLEAR_VARS)
@@ -98,12 +98,11 @@ LOCAL_CLANG := $(ADB_CLANG)
LOCAL_MODULE := adb_test
LOCAL_CFLAGS := -DADB_HOST=1 $(LIBADB_CFLAGS)
LOCAL_SRC_FILES := $(LIBADB_TEST_SRCS) services.cpp
-LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_SHARED_LIBRARIES := liblog libbase
LOCAL_STATIC_LIBRARIES := \
libadb \
libcrypto_static \
libcutils \
- libutils \
ifeq ($(HOST_OS),linux)
LOCAL_LDLIBS += -lrt -ldl -lpthread
diff --git a/adb/adb_io_test.cpp b/adb/adb_io_test.cpp
index 330d9ce..0c69bc9 100644
--- a/adb/adb_io_test.cpp
+++ b/adb/adb_io_test.cpp
@@ -24,7 +24,7 @@
#include <string>
-#include "utils/file.h"
+#include "base/file.h"
class TemporaryFile {
public:
@@ -55,7 +55,7 @@ TEST(io, ReadFdExactly_whole) {
TemporaryFile tf;
ASSERT_NE(-1, tf.fd);
- ASSERT_TRUE(android::WriteStringToFd(expected, tf.fd)) << strerror(errno);
+ ASSERT_TRUE(android::base::WriteStringToFd(expected, tf.fd)) << strerror(errno);
ASSERT_EQ(0, lseek(tf.fd, SEEK_SET, 0));
// Test reading the whole file.
@@ -69,7 +69,7 @@ TEST(io, ReadFdExactly_eof) {
TemporaryFile tf;
ASSERT_NE(-1, tf.fd);
- ASSERT_TRUE(android::WriteStringToFd(expected, tf.fd)) << strerror(errno);
+ ASSERT_TRUE(android::base::WriteStringToFd(expected, tf.fd)) << strerror(errno);
ASSERT_EQ(0, lseek(tf.fd, SEEK_SET, 0));
// Test that not having enough data will fail.
@@ -83,7 +83,7 @@ TEST(io, ReadFdExactly_partial) {
TemporaryFile tf;
ASSERT_NE(-1, tf.fd);
- ASSERT_TRUE(android::WriteStringToFd(input, tf.fd)) << strerror(errno);
+ ASSERT_TRUE(android::base::WriteStringToFd(input, tf.fd)) << strerror(errno);
ASSERT_EQ(0, lseek(tf.fd, SEEK_SET, 0));
// Test reading a partial file.
@@ -106,7 +106,7 @@ TEST(io, WriteFdExactly_whole) {
ASSERT_EQ(0, lseek(tf.fd, SEEK_SET, 0));
std::string s;
- ASSERT_TRUE(android::ReadFdToString(tf.fd, &s));
+ ASSERT_TRUE(android::base::ReadFdToString(tf.fd, &s));
EXPECT_STREQ(expected, s.c_str());
}
@@ -123,7 +123,7 @@ TEST(io, WriteFdExactly_partial) {
expected.pop_back();
std::string s;
- ASSERT_TRUE(android::ReadFdToString(tf.fd, &s));
+ ASSERT_TRUE(android::base::ReadFdToString(tf.fd, &s));
EXPECT_EQ(expected, s);
}
@@ -137,6 +137,6 @@ TEST(io, WriteStringFully) {
ASSERT_EQ(0, lseek(tf.fd, SEEK_SET, 0));
std::string s;
- ASSERT_TRUE(android::ReadFdToString(tf.fd, &s));
+ ASSERT_TRUE(android::base::ReadFdToString(tf.fd, &s));
EXPECT_STREQ(str, s.c_str());
}
diff --git a/base/.clang-format b/base/.clang-format
new file mode 100644
index 0000000..2b83a1f
--- /dev/null
+++ b/base/.clang-format
@@ -0,0 +1,11 @@
+BasedOnStyle: Google
+AllowShortBlocksOnASingleLine: false
+AllowShortFunctionsOnASingleLine: false
+
+CommentPragmas: NOLINT:.*
+DerivePointerAlignment: false
+IndentWidth: 2
+PointerAlignment: Left
+TabWidth: 2
+UseTab: Never
+PenaltyExcessCharacter: 32
diff --git a/base/Android.mk b/base/Android.mk
new file mode 100644
index 0000000..3b64ab0
--- /dev/null
+++ b/base/Android.mk
@@ -0,0 +1,96 @@
+#
+# Copyright (C) 2015 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+libbase_src_files := \
+ file.cpp \
+ stringprintf.cpp \
+
+libbase_test_src_files := \
+ file_test.cpp \
+ stringprintf_test.cpp \
+
+libbase_cppflags := \
+ -Wall \
+ -Wextra \
+ -Werror \
+
+# Device
+# ------------------------------------------------------------------------------
+include $(CLEAR_VARS)
+LOCAL_MODULE := libbase
+LOCAL_CLANG := true
+LOCAL_SRC_FILES := $(libbase_src_files)
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CPPFLAGS := $(libbase_cppflags)
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+LOCAL_MULTILIB := both
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libbase
+LOCAL_CLANG := true
+LOCAL_WHOLE_STATIC_LIBRARIES := libbase
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+LOCAL_MULTILIB := both
+include $(BUILD_SHARED_LIBRARY)
+
+# Host
+# ------------------------------------------------------------------------------
+include $(CLEAR_VARS)
+LOCAL_MODULE := libbase
+LOCAL_CLANG := true
+LOCAL_SRC_FILES := $(libbase_src_files)
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CPPFLAGS := $(libbase_cppflags)
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+LOCAL_MULTILIB := both
+include $(BUILD_HOST_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libbase
+LOCAL_CLANG := true
+LOCAL_WHOLE_STATIC_LIBRARIES := libbase
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+LOCAL_MULTILIB := both
+include $(BUILD_HOST_SHARED_LIBRARY)
+
+# Tests
+# ------------------------------------------------------------------------------
+include $(CLEAR_VARS)
+LOCAL_MODULE := libbase_test
+LOCAL_CLANG := true
+LOCAL_SRC_FILES := $(libbase_test_src_files)
+LOCAL_CPPFLAGS := $(libbase_cppflags)
+LOCAL_SHARED_LIBRARIES := libbase
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+include $(BUILD_NATIVE_TEST)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libbase_test
+LOCAL_CLANG := true
+LOCAL_SRC_FILES := $(libbase_test_src_files)
+LOCAL_CPPFLAGS := $(libbase_cppflags)
+LOCAL_SHARED_LIBRARIES := libbase
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+include $(BUILD_HOST_NATIVE_TEST)
diff --git a/base/CPPLINT.cfg b/base/CPPLINT.cfg
new file mode 100644
index 0000000..5ee068e
--- /dev/null
+++ b/base/CPPLINT.cfg
@@ -0,0 +1,2 @@
+set noparent
+filter=-build/header_guard
diff --git a/libutils/file.cpp b/base/file.cpp
index 0690bc2..773f33b 100644
--- a/libutils/file.cpp
+++ b/base/file.cpp
@@ -14,19 +14,23 @@
* limitations under the License.
*/
-#define LOG_TAG "utils.file"
-#include <cutils/log.h>
-
-#include "utils/file.h"
+#include "base/file.h"
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <utils/Compat.h> // For TEMP_FAILURE_RETRY on Darwin.
+#include <string>
+
+#define LOG_TAG "base.file"
+#include "cutils/log.h"
+#include "utils/Compat.h" // For TEMP_FAILURE_RETRY on Darwin.
-bool android::ReadFdToString(int fd, std::string* content) {
+namespace android {
+namespace base {
+
+bool ReadFdToString(int fd, std::string* content) {
content->clear();
char buf[BUFSIZ];
@@ -37,10 +41,11 @@ bool android::ReadFdToString(int fd, std::string* content) {
return (n == 0) ? true : false;
}
-bool android::ReadFileToString(const std::string& path, std::string* content) {
+bool ReadFileToString(const std::string& path, std::string* content) {
content->clear();
- int fd = TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
+ int fd =
+ TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
if (fd == -1) {
return false;
}
@@ -49,7 +54,7 @@ bool android::ReadFileToString(const std::string& path, std::string* content) {
return result;
}
-bool android::WriteStringToFd(const std::string& content, int fd) {
+bool WriteStringToFd(const std::string& content, int fd) {
const char* p = content.data();
size_t left = content.size();
while (left > 0) {
@@ -72,18 +77,18 @@ static bool CleanUpAfterFailedWrite(const std::string& path) {
}
#if !defined(_WIN32)
-bool android::WriteStringToFile(const std::string& content, const std::string& path,
- mode_t mode, uid_t owner, gid_t group) {
- int fd = TEMP_FAILURE_RETRY(open(path.c_str(),
- O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW,
- mode));
+bool WriteStringToFile(const std::string& content, const std::string& path,
+ mode_t mode, uid_t owner, gid_t group) {
+ int fd = TEMP_FAILURE_RETRY(
+ open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW,
+ mode));
if (fd == -1) {
ALOGE("android::WriteStringToFile open failed: %s", strerror(errno));
return false;
}
- // We do an explicit fchmod here because we assume that the caller really meant what they
- // said and doesn't want the umask-influenced mode.
+ // We do an explicit fchmod here because we assume that the caller really
+ // meant what they said and doesn't want the umask-influenced mode.
if (fchmod(fd, mode) == -1) {
ALOGE("android::WriteStringToFile fchmod failed: %s", strerror(errno));
return CleanUpAfterFailedWrite(path);
@@ -101,10 +106,10 @@ bool android::WriteStringToFile(const std::string& content, const std::string& p
}
#endif
-bool android::WriteStringToFile(const std::string& content, const std::string& path) {
- int fd = TEMP_FAILURE_RETRY(open(path.c_str(),
- O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW,
- DEFFILEMODE));
+bool WriteStringToFile(const std::string& content, const std::string& path) {
+ int fd = TEMP_FAILURE_RETRY(
+ open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW,
+ DEFFILEMODE));
if (fd == -1) {
return false;
}
@@ -113,3 +118,6 @@ bool android::WriteStringToFile(const std::string& content, const std::string& p
TEMP_FAILURE_RETRY(close(fd));
return result || CleanUpAfterFailedWrite(path);
}
+
+} // namespace base
+} // namespace android
diff --git a/libutils/tests/file_test.cpp b/base/file_test.cpp
index cea18b6..34b8755 100644
--- a/libutils/tests/file_test.cpp
+++ b/base/file_test.cpp
@@ -14,12 +14,15 @@
* limitations under the License.
*/
-#include "utils/file.h"
+#include "base/file.h"
+
+#include <gtest/gtest.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
-#include <gtest/gtest.h>
+
+#include <string>
class TemporaryFile {
public:
@@ -48,14 +51,14 @@ class TemporaryFile {
TEST(file, ReadFileToString_ENOENT) {
std::string s("hello");
errno = 0;
- ASSERT_FALSE(android::ReadFileToString("/proc/does-not-exist", &s));
+ ASSERT_FALSE(android::base::ReadFileToString("/proc/does-not-exist", &s));
EXPECT_EQ(ENOENT, errno);
- EXPECT_EQ("", s); // s was cleared.
+ EXPECT_EQ("", s); // s was cleared.
}
TEST(file, ReadFileToString_success) {
std::string s("hello");
- ASSERT_TRUE(android::ReadFileToString("/proc/version", &s)) << errno;
+ ASSERT_TRUE(android::base::ReadFileToString("/proc/version", &s)) << errno;
EXPECT_GT(s.length(), 6U);
EXPECT_EQ('\n', s[s.length() - 1]);
s[5] = 0;
@@ -65,34 +68,36 @@ TEST(file, ReadFileToString_success) {
TEST(file, WriteStringToFile) {
TemporaryFile tf;
ASSERT_TRUE(tf.fd != -1);
- ASSERT_TRUE(android::WriteStringToFile("abc", tf.filename)) << errno;
+ ASSERT_TRUE(android::base::WriteStringToFile("abc", tf.filename)) << errno;
std::string s;
- ASSERT_TRUE(android::ReadFileToString(tf.filename, &s)) << errno;
+ ASSERT_TRUE(android::base::ReadFileToString(tf.filename, &s)) << errno;
EXPECT_EQ("abc", s);
}
TEST(file, WriteStringToFile2) {
TemporaryFile tf;
ASSERT_TRUE(tf.fd != -1);
- ASSERT_TRUE(android::WriteStringToFile("abc", tf.filename, 0660, getuid(), getgid())) << errno;
+ ASSERT_TRUE(android::base::WriteStringToFile("abc", tf.filename, 0660,
+ getuid(), getgid()))
+ << errno;
struct stat sb;
ASSERT_EQ(0, stat(tf.filename, &sb));
ASSERT_EQ(0660U, (sb.st_mode & ~S_IFMT));
ASSERT_EQ(getuid(), sb.st_uid);
ASSERT_EQ(getgid(), sb.st_gid);
std::string s;
- ASSERT_TRUE(android::ReadFileToString(tf.filename, &s)) << errno;
+ ASSERT_TRUE(android::base::ReadFileToString(tf.filename, &s)) << errno;
EXPECT_EQ("abc", s);
}
TEST(file, WriteStringToFd) {
TemporaryFile tf;
ASSERT_TRUE(tf.fd != -1);
- ASSERT_TRUE(android::WriteStringToFd("abc", tf.fd));
+ ASSERT_TRUE(android::base::WriteStringToFd("abc", tf.fd));
ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET)) << errno;
std::string s;
- ASSERT_TRUE(android::ReadFdToString(tf.fd, &s)) << errno;
+ ASSERT_TRUE(android::base::ReadFdToString(tf.fd, &s)) << errno;
EXPECT_EQ("abc", s);
}
diff --git a/include/utils/file.h b/base/include/base/file.h
index a80afb1..ef97742 100644
--- a/include/utils/file.h
+++ b/base/include/base/file.h
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-#ifndef UTILS_FILE_H
-#define UTILS_FILE_H
+#ifndef BASE_FILE_H
+#define BASE_FILE_H
-#include <string>
#include <sys/stat.h>
+#include <string>
namespace android {
+namespace base {
bool ReadFdToString(int fd, std::string* content);
bool ReadFileToString(const std::string& path, std::string* content);
@@ -33,6 +34,7 @@ bool WriteStringToFile(const std::string& content, const std::string& path,
mode_t mode, uid_t owner, gid_t group);
#endif
-} // namespace android
+} // namespace base
+} // namespace android
-#endif
+#endif // BASE_FILE_H
diff --git a/include/utils/stringprintf.h b/base/include/base/stringprintf.h
index e7dbac7..195c1de 100644
--- a/include/utils/stringprintf.h
+++ b/base/include/base/stringprintf.h
@@ -14,25 +14,27 @@
* limitations under the License.
*/
-#ifndef UTILS_STRINGPRINTF_H_
-#define UTILS_STRINGPRINTF_H_
+#ifndef BASE_STRINGPRINTF_H
+#define BASE_STRINGPRINTF_H
#include <stdarg.h>
#include <string>
namespace android {
+namespace base {
// Returns a string corresponding to printf-like formatting of the arguments.
std::string StringPrintf(const char* fmt, ...)
- __attribute__((__format__(__printf__, 1, 2)));
+ __attribute__((__format__(__printf__, 1, 2)));
// Appends a printf-like formatting of the arguments to 'dst'.
void StringAppendF(std::string* dst, const char* fmt, ...)
- __attribute__((__format__(__printf__, 2, 3)));
+ __attribute__((__format__(__printf__, 2, 3)));
// Appends a printf-like formatting of the arguments to 'dst'.
void StringAppendV(std::string* dst, const char* format, va_list ap);
+} // namespace base
} // namespace android
-#endif
+#endif // BASE_STRINGPRINTF_H
diff --git a/libutils/stringprintf.cpp b/base/stringprintf.cpp
index 5eaa293..d55ff52 100644
--- a/libutils/stringprintf.cpp
+++ b/base/stringprintf.cpp
@@ -14,11 +14,16 @@
* limitations under the License.
*/
-#include <utils/stringprintf.h>
+#include "base/stringprintf.h"
#include <stdio.h>
-void android::StringAppendV(std::string* dst, const char* format, va_list ap) {
+#include <string>
+
+namespace android {
+namespace base {
+
+void StringAppendV(std::string* dst, const char* format, va_list ap) {
// First try with a small fixed size buffer
char space[1024];
@@ -45,7 +50,7 @@ void android::StringAppendV(std::string* dst, const char* format, va_list ap) {
// Increase the buffer size to the size requested by vsnprintf,
// plus one for the closing \0.
- int length = result+1;
+ int length = result + 1;
char* buf = new char[length];
// Restore the va_list before we use it again
@@ -60,7 +65,7 @@ void android::StringAppendV(std::string* dst, const char* format, va_list ap) {
delete[] buf;
}
-std::string android::StringPrintf(const char* fmt, ...) {
+std::string StringPrintf(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
std::string result;
@@ -69,9 +74,12 @@ std::string android::StringPrintf(const char* fmt, ...) {
return result;
}
-void android::StringAppendF(std::string* dst, const char* format, ...) {
+void StringAppendF(std::string* dst, const char* format, ...) {
va_list ap;
va_start(ap, format);
StringAppendV(dst, format, ap);
va_end(ap);
}
+
+} // namespace base
+} // namespace android
diff --git a/libutils/tests/stringprintf_test.cpp b/base/stringprintf_test.cpp
index f995452..5cc2086 100644
--- a/libutils/tests/stringprintf_test.cpp
+++ b/base/stringprintf_test.cpp
@@ -14,25 +14,27 @@
* limitations under the License.
*/
-#include <utils/stringprintf.h>
+#include "base/stringprintf.h"
#include <gtest/gtest.h>
+#include <string>
+
TEST(StringPrintfTest, HexSizeT) {
size_t size = 0x00107e59;
- EXPECT_EQ("00107e59", android::StringPrintf("%08zx", size));
- EXPECT_EQ("0x00107e59", android::StringPrintf("0x%08zx", size));
+ EXPECT_EQ("00107e59", android::base::StringPrintf("%08zx", size));
+ EXPECT_EQ("0x00107e59", android::base::StringPrintf("0x%08zx", size));
}
TEST(StringPrintfTest, StringAppendF) {
std::string s("a");
- android::StringAppendF(&s, "b");
+ android::base::StringAppendF(&s, "b");
EXPECT_EQ("ab", s);
}
TEST(StringPrintfTest, Errno) {
errno = 123;
- android::StringPrintf("hello %s", "world");
+ android::base::StringPrintf("hello %s", "world");
EXPECT_EQ(123, errno);
}
@@ -40,7 +42,7 @@ void TestN(size_t n) {
char* buf = new char[n + 1];
memset(buf, 'x', n);
buf[n] = '\0';
- std::string s(android::StringPrintf("%s", buf));
+ std::string s(android::base::StringPrintf("%s", buf));
EXPECT_EQ(buf, s);
delete[] buf;
}
diff --git a/init/Android.mk b/init/Android.mk
index ec2861b..5b8094f 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -27,6 +27,7 @@ LOCAL_SRC_FILES:= \
parser.cpp \
util.cpp \
+LOCAL_STATIC_LIBRARIES := libbase
LOCAL_MODULE := libinit
include $(BUILD_STATIC_LIBRARY)
@@ -55,7 +56,7 @@ LOCAL_STATIC_LIBRARIES := \
libfs_mgr \
liblogwrap \
libcutils \
- libutils \
+ libbase \
liblog \
libc \
libselinux \
@@ -80,7 +81,7 @@ LOCAL_SRC_FILES := \
LOCAL_SHARED_LIBRARIES += \
libcutils \
- libutils \
+ libbase \
LOCAL_STATIC_LIBRARIES := libinit
include $(BUILD_NATIVE_TEST)
diff --git a/init/bootchart.cpp b/init/bootchart.cpp
index cc31920..530eba8 100644
--- a/init/bootchart.cpp
+++ b/init/bootchart.cpp
@@ -32,7 +32,7 @@
#include <string>
-#include <utils/file.h>
+#include <base/file.h>
#define LOG_ROOT "/data/bootchart"
#define LOG_STAT LOG_ROOT"/proc_stat.log"
@@ -59,7 +59,7 @@ static FILE* log_disks;
static long long get_uptime_jiffies() {
std::string uptime;
- if (!android::ReadFileToString("/proc/uptime", &uptime)) {
+ if (!android::base::ReadFileToString("/proc/uptime", &uptime)) {
return 0;
}
return 100LL * strtod(uptime.c_str(), NULL);
@@ -82,7 +82,7 @@ static void log_header() {
}
std::string kernel_cmdline;
- android::ReadFileToString("/proc/cmdline", &kernel_cmdline);
+ android::base::ReadFileToString("/proc/cmdline", &kernel_cmdline);
FILE* out = fopen(LOG_HEADER, "we");
if (out == NULL) {
@@ -106,7 +106,7 @@ static void do_log_file(FILE* log, const char* procfile) {
do_log_uptime(log);
std::string content;
- if (android::ReadFileToString(procfile, &content)) {
+ if (android::base::ReadFileToString(procfile, &content)) {
fprintf(log, "%s\n", content.c_str());
}
}
@@ -127,13 +127,13 @@ static void do_log_procs(FILE* log) {
// name from /proc/<pid>/cmdline.
snprintf(filename, sizeof(filename), "/proc/%d/cmdline", pid);
std::string cmdline;
- android::ReadFileToString(filename, &cmdline);
+ android::base::ReadFileToString(filename, &cmdline);
const char* full_name = cmdline.c_str(); // So we stop at the first NUL.
// Read process stat line.
snprintf(filename, sizeof(filename), "/proc/%d/stat", pid);
std::string stat;
- if (android::ReadFileToString(filename, &stat)) {
+ if (android::base::ReadFileToString(filename, &stat)) {
if (!cmdline.empty()) {
// Substitute the process name with its real name.
size_t open = stat.find('(');
@@ -155,7 +155,7 @@ static int bootchart_init() {
int timeout = 0;
std::string start;
- android::ReadFileToString(LOG_STARTFILE, &start);
+ android::base::ReadFileToString(LOG_STARTFILE, &start);
if (!start.empty()) {
timeout = atoi(start.c_str());
} else {
@@ -164,7 +164,7 @@ static int bootchart_init() {
// timeout. this is useful when using -wipe-data since the /data
// partition is fresh.
std::string cmdline;
- android::ReadFileToString("/proc/cmdline", &cmdline);
+ android::base::ReadFileToString("/proc/cmdline", &cmdline);
#define KERNEL_OPTION "androidboot.bootchart="
if (strstr(cmdline.c_str(), KERNEL_OPTION) != NULL) {
timeout = atoi(cmdline.c_str() + sizeof(KERNEL_OPTION) - 1);
@@ -226,7 +226,7 @@ static int bootchart_step() {
// Stop if /data/bootchart/stop contains 1.
std::string stop;
- if (android::ReadFileToString(LOG_STOPFILE, &stop) && stop == "1") {
+ if (android::base::ReadFileToString(LOG_STOPFILE, &stop) && stop == "1") {
return -1;
}
diff --git a/init/property_service.cpp b/init/property_service.cpp
index 05c03d6..ddb8050 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -30,8 +30,6 @@
#include <cutils/sockets.h>
#include <cutils/multiuser.h>
-#include <utils/file.h>
-
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
diff --git a/init/util.cpp b/init/util.cpp
index 3dddb15..c805083 100644
--- a/init/util.cpp
+++ b/init/util.cpp
@@ -32,11 +32,11 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include <base/file.h>
+
/* for ANDROID_SOCKET_* */
#include <cutils/sockets.h>
-#include <utils/file.h>
-
#include <private/android_filesystem_config.h>
#include "init.h"
@@ -168,7 +168,7 @@ bool read_file(const char* path, std::string* content) {
return false;
}
- bool okay = android::ReadFdToString(fd, content);
+ bool okay = android::base::ReadFdToString(fd, content);
TEMP_FAILURE_RETRY(close(fd));
if (okay) {
content->append("\n", 1);
@@ -181,7 +181,7 @@ int write_file(const char* path, const char* content) {
if (fd == -1) {
return -errno;
}
- int result = android::WriteStringToFd(content, fd) ? 0 : -errno;
+ int result = android::base::WriteStringToFd(content, fd) ? 0 : -errno;
TEMP_FAILURE_RETRY(close(fd));
return result;
}
diff --git a/libutils/Android.mk b/libutils/Android.mk
index 7bff14e..e9c5f89 100644
--- a/libutils/Android.mk
+++ b/libutils/Android.mk
@@ -39,9 +39,7 @@ commonSources:= \
Tokenizer.cpp \
Unicode.cpp \
VectorImpl.cpp \
- file.cpp \
misc.cpp \
- stringprintf.cpp \
host_commonCflags := -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -Werror
diff --git a/libutils/tests/Android.mk b/libutils/tests/Android.mk
index ce288ca..634f44f 100644
--- a/libutils/tests/Android.mk
+++ b/libutils/tests/Android.mk
@@ -26,11 +26,9 @@ LOCAL_SRC_FILES := \
BasicHashtable_test.cpp \
BlobCache_test.cpp \
BitSet_test.cpp \
- file_test.cpp \
Looper_test.cpp \
LruCache_test.cpp \
String8_test.cpp \
- stringprintf_test.cpp \
Unicode_test.cpp \
Vector_test.cpp \