Skip to content

Commit

Permalink
Fix compilation error on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlocsomor committed Aug 26, 2019
1 parent fb91869 commit 912feb8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/cpp/util/file_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ bool ReadFile(const Path &filename, std::string *content,
// There must be enough memory allocated at `data`.
// Returns true on success, false on error.
bool ReadFile(const std::string &filename, void *data, size_t size);
bool ReadFile(const Path &filename, void *data, size_t size);

// Writes `size` bytes from `data` into file `filename` and chmods it to `perm`.
// Returns false on failure, sets errno.
Expand Down
4 changes: 4 additions & 0 deletions src/main/cpp/util/file_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ bool ReadFile(const string &filename, void *data, size_t size) {
return result;
}

bool ReadFile(const Path &filename, void *data, size_t size) {
return ReadFile(filename.AsNativePath(), data, size);
}

bool WriteFile(const void *data, size_t size, const string &filename,
unsigned int perm) {
UnlinkPath(filename); // We don't care about the success of this.
Expand Down
10 changes: 7 additions & 3 deletions src/main/cpp/util/file_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,19 @@ bool ReadFile(const Path &path, std::string *content, int max_size) {
}

bool ReadFile(const string& filename, void* data, size_t size) {
if (filename.empty()) {
return ReadFile(Path(filename), data, size);
}

bool ReadFile(const Path &path, void *data, size_t size) {
if (path.IsEmpty()) {
return false;
}
if (IsDevNull(filename.c_str())) {
if (path.IsNull()) {
// mimic read(2) behavior: we can always read 0 bytes from /dev/null
return true;
}
HANDLE handle;
if (!OpenFileForReading(filename, &handle)) {
if (!OpenFileForReading(path, &handle)) {
return false;
}

Expand Down

0 comments on commit 912feb8

Please sign in to comment.