Commit a1e7e4a7 authored by Victor Zverovich's avatar Victor Zverovich

Fix compilation with -fno-exceptions (#402, #405)

parent 3f24a388
...@@ -70,7 +70,7 @@ fmt::BufferedFile::BufferedFile( ...@@ -70,7 +70,7 @@ fmt::BufferedFile::BufferedFile(
fmt::cstring_view filename, fmt::cstring_view mode) { fmt::cstring_view filename, fmt::cstring_view mode) {
FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), 0); FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), 0);
if (!file_) if (!file_)
throw system_error(errno, "cannot open file {}", filename.c_str()); FMT_THROW(system_error(errno, "cannot open file {}", filename.c_str()));
} }
void fmt::BufferedFile::close() { void fmt::BufferedFile::close() {
...@@ -79,7 +79,7 @@ void fmt::BufferedFile::close() { ...@@ -79,7 +79,7 @@ void fmt::BufferedFile::close() {
int result = FMT_SYSTEM(fclose(file_)); int result = FMT_SYSTEM(fclose(file_));
file_ = 0; file_ = 0;
if (result != 0) if (result != 0)
throw system_error(errno, "cannot close file"); FMT_THROW(system_error(errno, "cannot close file"));
} }
// A macro used to prevent expansion of fileno on broken versions of MinGW. // A macro used to prevent expansion of fileno on broken versions of MinGW.
...@@ -88,7 +88,7 @@ void fmt::BufferedFile::close() { ...@@ -88,7 +88,7 @@ void fmt::BufferedFile::close() {
int fmt::BufferedFile::fileno() const { int fmt::BufferedFile::fileno() const {
int fd = FMT_POSIX_CALL(fileno FMT_ARGS(file_)); int fd = FMT_POSIX_CALL(fileno FMT_ARGS(file_));
if (fd == -1) if (fd == -1)
throw system_error(errno, "cannot get file descriptor"); FMT_THROW(system_error(errno, "cannot get file descriptor"));
return fd; return fd;
} }
...@@ -101,7 +101,7 @@ fmt::File::File(fmt::cstring_view path, int oflag) { ...@@ -101,7 +101,7 @@ fmt::File::File(fmt::cstring_view path, int oflag) {
FMT_RETRY(fd_, FMT_POSIX_CALL(open(path.c_str(), oflag, mode))); FMT_RETRY(fd_, FMT_POSIX_CALL(open(path.c_str(), oflag, mode)));
#endif #endif
if (fd_ == -1) if (fd_ == -1)
throw system_error(errno, "cannot open file {}", path.c_str()); FMT_THROW(system_error(errno, "cannot open file {}", path.c_str()));
} }
fmt::File::~File() FMT_NOEXCEPT { fmt::File::~File() FMT_NOEXCEPT {
...@@ -119,7 +119,7 @@ void fmt::File::close() { ...@@ -119,7 +119,7 @@ void fmt::File::close() {
int result = FMT_POSIX_CALL(close(fd_)); int result = FMT_POSIX_CALL(close(fd_));
fd_ = -1; fd_ = -1;
if (result != 0) if (result != 0)
throw system_error(errno, "cannot close file"); FMT_THROW(system_error(errno, "cannot close file"));
} }
long long fmt::File::size() const { long long fmt::File::size() const {
...@@ -133,7 +133,7 @@ long long fmt::File::size() const { ...@@ -133,7 +133,7 @@ long long fmt::File::size() const {
if (size_lower == INVALID_FILE_SIZE) { if (size_lower == INVALID_FILE_SIZE) {
DWORD error = GetLastError(); DWORD error = GetLastError();
if (error != NO_ERROR) if (error != NO_ERROR)
throw windows_error(GetLastError(), "cannot get file size"); FMT_THROW(windows_error(GetLastError(), "cannot get file size"));
} }
unsigned long long long_size = size_upper; unsigned long long long_size = size_upper;
return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower; return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower;
...@@ -141,7 +141,7 @@ long long fmt::File::size() const { ...@@ -141,7 +141,7 @@ long long fmt::File::size() const {
typedef struct stat Stat; typedef struct stat Stat;
Stat file_stat = Stat(); Stat file_stat = Stat();
if (FMT_POSIX_CALL(fstat(fd_, &file_stat)) == -1) if (FMT_POSIX_CALL(fstat(fd_, &file_stat)) == -1)
throw system_error(errno, "cannot get file attributes"); FMT_THROW(system_error(errno, "cannot get file attributes"));
static_assert(sizeof(long long) >= sizeof(file_stat.st_size), static_assert(sizeof(long long) >= sizeof(file_stat.st_size),
"return type of File::size is not large enough"); "return type of File::size is not large enough");
return file_stat.st_size; return file_stat.st_size;
...@@ -152,7 +152,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) { ...@@ -152,7 +152,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) {
RWResult result = 0; RWResult result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count)))); FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count))));
if (result < 0) if (result < 0)
throw system_error(errno, "cannot read from file"); FMT_THROW(system_error(errno, "cannot read from file"));
return internal::to_unsigned(result); return internal::to_unsigned(result);
} }
...@@ -160,7 +160,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) { ...@@ -160,7 +160,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) {
RWResult result = 0; RWResult result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(write(fd_, buffer, convert_rwcount(count)))); FMT_RETRY(result, FMT_POSIX_CALL(write(fd_, buffer, convert_rwcount(count))));
if (result < 0) if (result < 0)
throw system_error(errno, "cannot write to file"); FMT_THROW(system_error(errno, "cannot write to file"));
return internal::to_unsigned(result); return internal::to_unsigned(result);
} }
...@@ -169,7 +169,7 @@ fmt::File fmt::File::dup(int fd) { ...@@ -169,7 +169,7 @@ fmt::File fmt::File::dup(int fd) {
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html // http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html
int new_fd = FMT_POSIX_CALL(dup(fd)); int new_fd = FMT_POSIX_CALL(dup(fd));
if (new_fd == -1) if (new_fd == -1)
throw system_error(errno, "cannot duplicate file descriptor {}", fd); FMT_THROW(system_error(errno, "cannot duplicate file descriptor {}", fd));
return File(new_fd); return File(new_fd);
} }
...@@ -205,7 +205,7 @@ void fmt::File::pipe(File &read_end, File &write_end) { ...@@ -205,7 +205,7 @@ void fmt::File::pipe(File &read_end, File &write_end) {
int result = FMT_POSIX_CALL(pipe(fds)); int result = FMT_POSIX_CALL(pipe(fds));
#endif #endif
if (result != 0) if (result != 0)
throw system_error(errno, "cannot create pipe"); FMT_THROW(system_error(errno, "cannot create pipe"));
// The following assignments don't throw because read_fd and write_fd // The following assignments don't throw because read_fd and write_fd
// are closed. // are closed.
read_end = File(fds[0]); read_end = File(fds[0]);
...@@ -216,7 +216,8 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) { ...@@ -216,7 +216,8 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) {
// Don't retry as fdopen doesn't return EINTR. // Don't retry as fdopen doesn't return EINTR.
FILE *f = FMT_POSIX_CALL(fdopen(fd_, mode)); FILE *f = FMT_POSIX_CALL(fdopen(fd_, mode));
if (!f) if (!f)
throw system_error(errno, "cannot associate stream with file descriptor"); FMT_THROW(system_error(errno,
"cannot associate stream with file descriptor"));
BufferedFile file(f); BufferedFile file(f);
fd_ = -1; fd_ = -1;
return file; return file;
...@@ -230,7 +231,7 @@ long fmt::getpagesize() { ...@@ -230,7 +231,7 @@ long fmt::getpagesize() {
#else #else
long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE)); long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE));
if (size < 0) if (size < 0)
throw system_error(errno, "cannot get memory page size"); FMT_THROW(system_error(errno, "cannot get memory page size"));
return size; return size;
#endif #endif
} }
...@@ -388,7 +388,7 @@ class Locale { ...@@ -388,7 +388,7 @@ class Locale {
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", NULL)) { Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", NULL)) {
if (!locale_) if (!locale_)
throw fmt::system_error(errno, "cannot create locale"); FMT_THROW(fmt::system_error(errno, "cannot create locale"));
} }
~Locale() { freelocale(locale_); } ~Locale() { freelocale(locale_); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment