Move AppendFile and *CurrentDirectory to the base namespace.
This moves AppendFile, GetCurrentDirectory, and SetCurrentDirectory to the base namespace.
TBR=jam
Review URL: https://codereview.chromium.org/177923007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256309 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: 37b3c199da23208121a946491ce749bafeb573c2
diff --git a/base/file_util.h b/base/file_util.h
index 32dce3b..3c171f1 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -338,23 +338,23 @@
BASE_EXPORT int WriteFileDescriptor(const int fd, const char* data, int size);
#endif
+// Append the given buffer into the file. Returns the number of bytes written,
+// or -1 on error.
+BASE_EXPORT int AppendToFile(const FilePath& filename,
+ const char* data, int size);
+
+// Gets the current working directory for the process.
+BASE_EXPORT bool GetCurrentDirectory(FilePath* path);
+
+// Sets the current working directory for the process.
+BASE_EXPORT bool SetCurrentDirectory(const FilePath& path);
+
} // namespace base
// -----------------------------------------------------------------------------
namespace file_util {
-// Append the given buffer into the file. Returns the number of bytes written,
-// or -1 on error.
-BASE_EXPORT int AppendToFile(const base::FilePath& filename,
- const char* data, int size);
-
-// Gets the current working directory for the process.
-BASE_EXPORT bool GetCurrentDirectory(base::FilePath* path);
-
-// Sets the current working directory for the process.
-BASE_EXPORT bool SetCurrentDirectory(const base::FilePath& path);
-
// Attempts to find a number that can be appended to the |path| to make it
// unique. If |path| does not exist, 0 is returned. If it fails to find such
// a number, -1 is returned. If |suffix| is not empty, also checks the
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 53c64da..db84c3f 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -739,6 +739,39 @@
return bytes_written_total;
}
+int AppendToFile(const FilePath& filename, const char* data, int size) {
+ ThreadRestrictions::AssertIOAllowed();
+ int fd = HANDLE_EINTR(open(filename.value().c_str(), O_WRONLY | O_APPEND));
+ if (fd < 0)
+ return -1;
+
+ int bytes_written = WriteFileDescriptor(fd, data, size);
+ if (int ret = IGNORE_EINTR(close(fd)) < 0)
+ return ret;
+ return bytes_written;
+}
+
+// Gets the current working directory for the process.
+bool GetCurrentDirectory(FilePath* dir) {
+ // getcwd can return ENOENT, which implies it checks against the disk.
+ ThreadRestrictions::AssertIOAllowed();
+
+ char system_buffer[PATH_MAX] = "";
+ if (!getcwd(system_buffer, sizeof(system_buffer))) {
+ NOTREACHED();
+ return false;
+ }
+ *dir = FilePath(system_buffer);
+ return true;
+}
+
+// Sets the current working directory for the process.
+bool SetCurrentDirectory(const FilePath& path) {
+ ThreadRestrictions::AssertIOAllowed();
+ int ret = chdir(path.value().c_str());
+ return !ret;
+}
+
} // namespace base
// -----------------------------------------------------------------------------
@@ -777,39 +810,6 @@
return OpenFile(FilePath(filename), mode);
}
-int AppendToFile(const FilePath& filename, const char* data, int size) {
- base::ThreadRestrictions::AssertIOAllowed();
- int fd = HANDLE_EINTR(open(filename.value().c_str(), O_WRONLY | O_APPEND));
- if (fd < 0)
- return -1;
-
- int bytes_written = base::WriteFileDescriptor(fd, data, size);
- if (int ret = IGNORE_EINTR(close(fd)) < 0)
- return ret;
- return bytes_written;
-}
-
-// Gets the current working directory for the process.
-bool GetCurrentDirectory(FilePath* dir) {
- // getcwd can return ENOENT, which implies it checks against the disk.
- base::ThreadRestrictions::AssertIOAllowed();
-
- char system_buffer[PATH_MAX] = "";
- if (!getcwd(system_buffer, sizeof(system_buffer))) {
- NOTREACHED();
- return false;
- }
- *dir = FilePath(system_buffer);
- return true;
-}
-
-// Sets the current working directory for the process.
-bool SetCurrentDirectory(const FilePath& path) {
- base::ThreadRestrictions::AssertIOAllowed();
- int ret = chdir(path.value().c_str());
- return !ret;
-}
-
bool VerifyPathControlledByUser(const FilePath& base,
const FilePath& path,
uid_t owner_uid,
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index f360c7a..5b8684f 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -1947,11 +1947,11 @@
FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt")));
std::string data("hello");
- EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length()));
+ EXPECT_EQ(-1, AppendToFile(foobar, data.c_str(), data.length()));
EXPECT_EQ(static_cast<int>(data.length()),
WriteFile(foobar, data.c_str(), data.length()));
EXPECT_EQ(static_cast<int>(data.length()),
- file_util::AppendToFile(foobar, data.c_str(), data.length()));
+ AppendToFile(foobar, data.c_str(), data.length()));
const std::wstring read_content = ReadTextFile(foobar);
EXPECT_EQ(L"hellohello", read_content);
diff --git a/base/path_service.cc b/base/path_service.cc
index f0a6a84..61488d6 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -187,7 +187,7 @@
// special case the current directory because it can never be cached
if (key == base::DIR_CURRENT)
- return file_util::GetCurrentDirectory(result);
+ return base::GetCurrentDirectory(result);
Provider* provider = NULL;
{