diff --git a/.gitignore b/.gitignore index 88882270..c76d9961 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ CTestTestfile.cmake CMakeCache.txt CMakeFiles Makefile +/run-msbuild.bat diff --git a/posix.cc b/posix.cc index b4893cd6..63b37c37 100644 --- a/posix.cc +++ b/posix.cc @@ -75,6 +75,8 @@ inline std::size_t convert_rwcount(std::size_t count) { return count; } #endif } +// Implementations of fmt::BufferedFile + fmt::BufferedFile::~BufferedFile() FMT_NOEXCEPT { if (file_ && FMT_SYSTEM(fclose(file_)) != 0) fmt::report_system_error(errno, "cannot close file"); @@ -102,6 +104,18 @@ int fmt::BufferedFile::fileno() const { return fd; } +void fmt::BufferedFile::flush() { + if (!file_) + return; + // FIXME: int result = FMT_SYSTEM(fflush(file_)); + int result = ::fflush(file_); + if (result != 0) + throw SystemError(errno, "cannot flush file"); +} + + +// Implementations of fmt::File + fmt::File::File(fmt::StringRef path, int oflag) { int mode = S_IRUSR | S_IWUSR; #ifdef _WIN32 @@ -226,6 +240,7 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) { return file; } + long fmt::getpagesize() { #ifdef _WIN32 SYSTEM_INFO si = {}; diff --git a/posix.h b/posix.h index cce1b1b2..0dcc2960 100644 --- a/posix.h +++ b/posix.h @@ -53,7 +53,7 @@ #ifdef FMT_SYSTEM # define FMT_POSIX_CALL(call) FMT_SYSTEM(call) #else -# define FMT_SYSTEM(call) call +# define FMT_SYSTEM(call) ::call # ifdef _WIN32 // Fix warnings about deprecated symbols. # define FMT_POSIX_CALL(call) ::_##call @@ -182,31 +182,33 @@ public: BufferedFile(fmt::StringRef filename, fmt::StringRef mode); // Gets whether a file is opened - bool is_open() { return file_ != 0; } + bool is_open() const FMT_NOEXCEPT { return file_ != 0; } // Closes the file. void close(); // Returns the pointer to a FILE object representing this file. - FILE *get() const { return file_; } - - void flush() { - if (is_open()) { - std::fflush(file_); - } - } - + FILE *get() const FMT_NOEXCEPT{ return file_; } + + // Gets the file number of a file int fileno() const; - void write_raw(fmt::StringRef str) { - if (is_open()) { - std::fwrite(str.c_str(), str.size(), 1, file_); - } + // Flushes the buffer of a file + void flush(); // FIXME: Should be const? + + // Writes raw string without formatting + std::size_t write_raw(fmt::StringRef str) { + // FIXME: throw exception when failing + if (!is_open()) + return 0; + return ::fwrite(str.c_str(), str.size(), 1, file_); } + // Writes a single charactor without formatting void write_raw(char c) { - if (is_open()) { - std::fputc(c, file_); - } + // FIXME: throw exception when failing + if (!is_open()) + return; + ::fputc(c, file_); } void print(fmt::StringRef format_str, const ArgList &args) {