Fixes for extra methods
This commit is contained in:
parent
2e7e2279d2
commit
47148771fc
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@ CTestTestfile.cmake
|
|||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
CMakeFiles
|
CMakeFiles
|
||||||
Makefile
|
Makefile
|
||||||
|
/run-msbuild.bat
|
||||||
|
|||||||
15
posix.cc
15
posix.cc
@ -75,6 +75,8 @@ inline std::size_t convert_rwcount(std::size_t count) { return count; }
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementations of fmt::BufferedFile
|
||||||
|
|
||||||
fmt::BufferedFile::~BufferedFile() FMT_NOEXCEPT {
|
fmt::BufferedFile::~BufferedFile() FMT_NOEXCEPT {
|
||||||
if (file_ && FMT_SYSTEM(fclose(file_)) != 0)
|
if (file_ && FMT_SYSTEM(fclose(file_)) != 0)
|
||||||
fmt::report_system_error(errno, "cannot close file");
|
fmt::report_system_error(errno, "cannot close file");
|
||||||
@ -102,6 +104,18 @@ int fmt::BufferedFile::fileno() const {
|
|||||||
return fd;
|
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) {
|
fmt::File::File(fmt::StringRef path, int oflag) {
|
||||||
int mode = S_IRUSR | S_IWUSR;
|
int mode = S_IRUSR | S_IWUSR;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -226,6 +240,7 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) {
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long fmt::getpagesize() {
|
long fmt::getpagesize() {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
SYSTEM_INFO si = {};
|
SYSTEM_INFO si = {};
|
||||||
|
|||||||
34
posix.h
34
posix.h
@ -53,7 +53,7 @@
|
|||||||
#ifdef FMT_SYSTEM
|
#ifdef FMT_SYSTEM
|
||||||
# define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
|
# define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
|
||||||
#else
|
#else
|
||||||
# define FMT_SYSTEM(call) call
|
# define FMT_SYSTEM(call) ::call
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
// Fix warnings about deprecated symbols.
|
// Fix warnings about deprecated symbols.
|
||||||
# define FMT_POSIX_CALL(call) ::_##call
|
# define FMT_POSIX_CALL(call) ::_##call
|
||||||
@ -182,31 +182,33 @@ public:
|
|||||||
BufferedFile(fmt::StringRef filename, fmt::StringRef mode);
|
BufferedFile(fmt::StringRef filename, fmt::StringRef mode);
|
||||||
|
|
||||||
// Gets whether a file is opened
|
// Gets whether a file is opened
|
||||||
bool is_open() { return file_ != 0; }
|
bool is_open() const FMT_NOEXCEPT { return file_ != 0; }
|
||||||
|
|
||||||
// Closes the file.
|
// Closes the file.
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
// Returns the pointer to a FILE object representing this file.
|
// Returns the pointer to a FILE object representing this file.
|
||||||
FILE *get() const { return file_; }
|
FILE *get() const FMT_NOEXCEPT{ return file_; }
|
||||||
|
|
||||||
void flush() {
|
|
||||||
if (is_open()) {
|
|
||||||
std::fflush(file_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Gets the file number of a file
|
||||||
int fileno() const;
|
int fileno() const;
|
||||||
|
|
||||||
void write_raw(fmt::StringRef str) {
|
// Flushes the buffer of a file
|
||||||
if (is_open()) {
|
void flush(); // FIXME: Should be const?
|
||||||
std::fwrite(str.c_str(), str.size(), 1, file_);
|
|
||||||
}
|
// 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) {
|
void write_raw(char c) {
|
||||||
if (is_open()) {
|
// FIXME: throw exception when failing
|
||||||
std::fputc(c, file_);
|
if (!is_open())
|
||||||
}
|
return;
|
||||||
|
::fputc(c, file_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(fmt::StringRef format_str, const ArgList &args) {
|
void print(fmt::StringRef format_str, const ArgList &args) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user