diff --git a/src/logging.cc b/src/logging.cc index fa8868561..45d2ce166 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -65,6 +65,7 @@ #include // for std::isspace #ifdef GLOG_OS_WINDOWS #include "windows/dirent.h" +#include // for truncate log file #else #include // for automatic removal of old logs #endif @@ -2425,7 +2426,7 @@ void GetExistingTempDirectories(vector* list) { } void TruncateLogFile(const char *path, uint64 limit, uint64 keep) { -#ifdef HAVE_UNISTD_H +#if defined(HAVE_UNISTD_H) || defined(GLOG_OS_WINDOWS) struct stat statbuf; const int kCopyBlockSize = 8 << 10; char copybuf[kCopyBlockSize]; @@ -2446,7 +2447,11 @@ void TruncateLogFile(const char *path, uint64 limit, uint64 keep) { // all of base/...) with -D_FILE_OFFSET_BITS=64 but that's // rather scary. // Instead just truncate the file to something we can manage +#ifdef GLOG_OS_WINDOWS + if (_chsize_s(fd, 0) != 0) { +#else if (truncate(path, 0) == -1) { +#endif PLOG(ERROR) << "Unable to truncate " << path; } else { LOG(ERROR) << "Truncated " << path << " due to EFBIG error"; @@ -2491,7 +2496,11 @@ void TruncateLogFile(const char *path, uint64 limit, uint64 keep) { // Truncate the remainder of the file. If someone else writes to the // end of the file after our last read() above, we lose their latest // data. Too bad ... +#ifdef GLOG_OS_WINDOWS + if (_chsize_s(fd, write_offset) != 0) { +#else if (ftruncate(fd, write_offset) == -1) { +#endif PLOG(ERROR) << "Unable to truncate " << path; }