diff options
-rw-r--r-- | base/file_path.h | 4 | ||||
-rw-r--r-- | base/file_util.cc | 6 | ||||
-rw-r--r-- | base/file_util.h | 2 | ||||
-rw-r--r-- | base/file_util_linux.cc | 4 | ||||
-rw-r--r-- | base/file_util_posix.cc | 20 | ||||
-rw-r--r-- | base/file_util_win.cc | 10 |
6 files changed, 25 insertions, 21 deletions
diff --git a/base/file_path.h b/base/file_path.h index 7dd2a71..6bb426f 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -116,6 +116,10 @@ class FilePath { return *this; } + bool operator==(const FilePath& that) const { + return path_ == that.path_; + } + const StringType& value() const { return path_; } // Returns a FilePath corresponding to the directory containing the path diff --git a/base/file_util.cc b/base/file_util.cc index 4fdc128..0f7b683 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -370,6 +370,12 @@ bool GetTempDir(std::wstring* path_str) { *path_str = path.ToWStringHack(); return true; } +FILE* OpenFile(const std::wstring& filename, const char* mode) { + return OpenFile(FilePath::FromWStringHack(filename), mode); +} +bool SetCurrentDirectory(const std::wstring& directory) { + return SetCurrentDirectory(FilePath::FromWStringHack(directory)); +} } // namespace diff --git a/base/file_util.h b/base/file_util.h index 3df31e4..e274d6a 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -312,6 +312,8 @@ bool GetCurrentDirectory(FilePath* path); bool GetCurrentDirectory(std::wstring* path); // Sets the current working directory for the process. +bool SetCurrentDirectory(const FilePath& path); +// Deprecated temporary compatibility function. bool SetCurrentDirectory(const std::wstring& current_directory); // A class for enumerating the files in a provided path. The order of the diff --git a/base/file_util_linux.cc b/base/file_util_linux.cc index 945200a..f776c91 100644 --- a/base/file_util_linux.cc +++ b/base/file_util_linux.cc @@ -26,10 +26,6 @@ bool GetTempDir(FilePath* path) { return true; } -FILE* OpenFile(const FilePath& filename, const char* mode) { - return fopen(filename.value().c_str(), mode); -} - bool CopyFile(const FilePath& from_path, const FilePath& to_path) { int infile = open(from_path.value().c_str(), O_RDONLY); if (infile < 0) diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index a0c6cb6..1afb573 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -322,18 +322,18 @@ bool GetFileInfo(const FilePath& file_path, FileInfo* results) { } FILE* OpenFile(const std::string& filename, const char* mode) { - return fopen(filename.c_str(), mode); + return OpenFile(FilePath(filename), mode); } -FILE* OpenFile(const std::wstring& filename, const char* mode) { - return fopen(WideToUTF8(filename).c_str(), mode); +FILE* OpenFile(const FilePath& filename, const char* mode) { + return fopen(filename.value().c_str(), mode); } int ReadFile(const std::wstring& filename, char* data, int size) { int fd = open(WideToUTF8(filename).c_str(), O_RDONLY); if (fd < 0) return -1; - + int ret_value = read(fd, data, size); close(fd); return ret_value; @@ -352,7 +352,7 @@ int WriteFile(const std::wstring& filename, const char* data, int size) { size - bytes_written_total); if (bytes_written_partial < 0) { close(fd); - return -1; + return -1; } bytes_written_total += bytes_written_partial; } while (bytes_written_total < size); @@ -373,11 +373,11 @@ bool GetCurrentDirectory(FilePath* dir) { } // Sets the current working directory for the process. -bool SetCurrentDirectory(const std::wstring& current_directory) { - int ret = chdir(WideToUTF8(current_directory).c_str()); - return (ret == 0); +bool SetCurrentDirectory(const FilePath& path) { + int ret = chdir(path.value().c_str()); + return !ret; } - + FileEnumerator::FileEnumerator(const std::wstring& root_path, bool recursive, FileEnumerator::FILE_TYPE file_type) @@ -403,7 +403,7 @@ FileEnumerator::FileEnumerator(const std::wstring& root_path, AppendToPath(&pattern_, pattern); pending_paths_.push(root_path); } - + FileEnumerator::~FileEnumerator() { if (fts_) fts_close(fts_); diff --git a/base/file_util_win.cc b/base/file_util_win.cc index 355bdfd..459e3a8 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -495,10 +495,6 @@ FILE* OpenFile(const std::string& filename, const char* mode) { return file; } -FILE* OpenFile(const std::wstring& filename, const char* mode) { - return OpenFile(FilePath(filename), mode); -} - int ReadFile(const std::wstring& filename, char* data, int size) { ScopedHandle file(CreateFile(filename.c_str(), GENERIC_READ, @@ -594,9 +590,9 @@ bool GetCurrentDirectory(FilePath* dir) { } // Sets the current working directory for the process. -bool SetCurrentDirectory(const std::wstring& current_directory) { - BOOL ret = ::SetCurrentDirectory(current_directory.c_str()); - return (ret ? true : false); +bool SetCurrentDirectory(const FilePath& directory) { + BOOL ret = ::SetCurrentDirectory(directory.value().c_str()); + return ret != 0; } /////////////////////////////////////////////// |