Revert "Write string_view to fd"
This reverts commit 0598b07fc6be9eaaa03179c66e09d2fa01b0a4d8.
Reason for revert: DroidMonitor: Potential culprit for b/260066911 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.
Change-Id: I79a109e289466a31f45e64cc7fae0a229dfea9e7
diff --git a/abi_compatibility.cpp b/abi_compatibility.cpp
index a75d949..06a7801 100644
--- a/abi_compatibility.cpp
+++ b/abi_compatibility.cpp
@@ -46,7 +46,7 @@
}
bool WriteStringToFd(const std::string& content, int fd) {
- return WriteStringToFd(std::string_view(content), borrowed_fd(fd));
+ return WriteStringToFd(content, borrowed_fd(fd));
}
bool ReadFully(int fd, void* data, size_t byte_count) {
diff --git a/file.cpp b/file.cpp
index f4f3ad4..71683fd 100644
--- a/file.cpp
+++ b/file.cpp
@@ -245,7 +245,7 @@
return ReadFdToString(fd, content);
}
-bool WriteStringToFd(std::string_view content, borrowed_fd fd) {
+bool WriteStringToFd(const std::string& content, borrowed_fd fd) {
const char* p = content.data();
size_t left = content.size();
while (left > 0) {
diff --git a/file_test.cpp b/file_test.cpp
index 2474f7b..f178945 100644
--- a/file_test.cpp
+++ b/file_test.cpp
@@ -176,7 +176,7 @@
}
#endif
-TEST(file, WriteStringToFd_StringLiteral) {
+TEST(file, WriteStringToFd) {
TemporaryFile tf;
ASSERT_NE(tf.fd, -1) << tf.path;
ASSERT_TRUE(android::base::WriteStringToFd("abc", tf.fd));
@@ -188,32 +188,6 @@
EXPECT_EQ("abc", s);
}
-TEST(file, WriteStringToFd_String) {
- std::string testStr = "def";
- TemporaryFile tf;
- ASSERT_NE(tf.fd, -1) << tf.path;
- ASSERT_TRUE(android::base::WriteStringToFd(testStr, tf.fd));
-
- ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET)) << strerror(errno);
-
- std::string s;
- ASSERT_TRUE(android::base::ReadFdToString(tf.fd, &s)) << strerror(errno);
- EXPECT_EQ(testStr, s);
-}
-
-TEST(file, WriteStringToFd_StringView) {
- std::string_view testStrView = "ghi";
- TemporaryFile tf;
- ASSERT_NE(tf.fd, -1) << tf.path;
- ASSERT_TRUE(android::base::WriteStringToFd(testStrView, tf.fd));
-
- ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET)) << strerror(errno);
-
- std::string s;
- ASSERT_TRUE(android::base::ReadFdToString(tf.fd, &s)) << strerror(errno);
- EXPECT_EQ(testStrView, s);
-}
-
TEST(file, WriteFully) {
TemporaryFile tf;
ASSERT_NE(tf.fd, -1) << tf.path;
diff --git a/include/android-base/file.h b/include/android-base/file.h
index 23812f1..a1fb6b6 100644
--- a/include/android-base/file.h
+++ b/include/android-base/file.h
@@ -84,7 +84,7 @@
bool WriteStringToFile(const std::string& content, const std::string& path,
bool follow_symlinks = false);
-bool WriteStringToFd(std::string_view content, borrowed_fd fd);
+bool WriteStringToFd(const std::string& content, borrowed_fd fd);
#if !defined(_WIN32)
bool WriteStringToFile(const std::string& content, const std::string& path,