Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Unified Diff: base/file_util_posix.cc

Issue 177923007: Move AppendFile and *CurrentDirectory to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_posix.cc
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 39b29b3e26bf7dcdb1aae8c389c0d437e41a2f5a..3d4c545aec5ac85b8aab0416d8c26651482c544f 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -739,6 +739,39 @@ int WriteFileDescriptor(const int fd, const char* data, int size) {
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 @@ FILE* OpenFile(const std::string& filename, const char* mode) {
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,
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698