Fixes for extra methods

This commit is contained in:
carterl 2015-02-11 10:41:43 +01:00
parent 2e7e2279d2
commit 47148771fc
3 changed files with 35 additions and 17 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ CTestTestfile.cmake
CMakeCache.txt
CMakeFiles
Makefile
/run-msbuild.bat

View File

@ -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 = {};

36
posix.h
View File

@ -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) {