diff options
author | Elliott Hughes <enh@google.com> | 2015-09-01 13:35:44 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-09-01 13:35:44 -0700 |
commit | 470d79a09c43acc710d91b4ba9b563afaed6d76b (patch) | |
tree | 6e75a944fdd9d26cbb8c73fe4d2d683fbc8e7216 /base/file.cpp | |
parent | 7c4ed6af79a14cc93cf3aa3de857d56d9c6db7b4 (diff) | |
download | system_core-470d79a09c43acc710d91b4ba9b563afaed6d76b.tar.gz system_core-470d79a09c43acc710d91b4ba9b563afaed6d76b.tar.bz2 system_core-470d79a09c43acc710d91b4ba9b563afaed6d76b.zip |
Use O_BINARY in base/file for Windows.
This matches the behavior of the google3/Chrome APIs. It's probably what you
want in all cases except where you plan on calling Split(content, "\n"), but
we should probably have something like simpleperf's LineReader for that
anyway.
Change-Id: I1a128ed8c328bc95b0b2ef4068a65a8562721418
Diffstat (limited to 'base/file.cpp')
-rw-r--r-- | base/file.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/base/file.cpp b/base/file.cpp index 9a340b7f8..3468dcfbf 100644 --- a/base/file.cpp +++ b/base/file.cpp @@ -28,6 +28,10 @@ #include "cutils/log.h" #include "utils/Compat.h" +#if !defined(_WIN32) +#define O_BINARY 0 +#endif + namespace android { namespace base { @@ -45,8 +49,7 @@ bool ReadFdToString(int fd, 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 | O_BINARY)); if (fd == -1) { return false; } @@ -80,9 +83,8 @@ static bool CleanUpAfterFailedWrite(const std::string& path) { #if !defined(_WIN32) 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)); + int flags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_BINARY; + int fd = TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode)); if (fd == -1) { ALOGE("android::WriteStringToFile open failed: %s", strerror(errno)); return false; @@ -108,9 +110,8 @@ bool WriteStringToFile(const std::string& content, const std::string& path, #endif 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)); + int flags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_BINARY; + int fd = TEMP_FAILURE_RETRY(open(path.c_str(), flags, DEFFILEMODE)); if (fd == -1) { return false; } |