#define FMT_OS_H_
#include <cerrno>
-#include <clocale> // locale_t
#include <cstddef>
#include <cstdio>
-#include <cstdlib> // strtod_l
#include <system_error> // std::system_error
#if defined __APPLE__ || defined(__FreeBSD__)
};
#ifdef _WIN32
-FMT_API const std::error_category& system_category() FMT_NOEXCEPT;
+FMT_API const std::error_category& system_category() noexcept;
FMT_BEGIN_DETAIL_NAMESPACE
// A converter from UTF-16 to UTF-8.
};
FMT_API void format_windows_error(buffer<char>& out, int error_code,
- const char* message) FMT_NOEXCEPT;
+ const char* message) noexcept;
FMT_END_DETAIL_NAMESPACE
FMT_API std::system_error vwindows_error(int error_code, string_view format_str,
// Reports a Windows error without throwing an exception.
// Can be used to report errors from destructors.
-FMT_API void report_windows_error(int error_code,
- const char* message) FMT_NOEXCEPT;
+FMT_API void report_windows_error(int error_code, const char* message) noexcept;
#else
-inline const std::error_category& system_category() FMT_NOEXCEPT {
+inline const std::error_category& system_category() noexcept {
return std::system_category();
}
#endif // _WIN32
void operator=(const buffered_file&) = delete;
// Constructs a buffered_file object which doesn't represent any file.
- buffered_file() FMT_NOEXCEPT : file_(nullptr) {}
+ buffered_file() noexcept : file_(nullptr) {}
// Destroys the object closing the file it represents if any.
- FMT_API ~buffered_file() FMT_NOEXCEPT;
+ FMT_API ~buffered_file() noexcept;
public:
- buffered_file(buffered_file&& other) FMT_NOEXCEPT : file_(other.file_) {
+ buffered_file(buffered_file&& other) noexcept : file_(other.file_) {
other.file_ = nullptr;
}
FMT_API void close();
// Returns the pointer to a FILE object representing this file.
- FILE* get() const FMT_NOEXCEPT { return file_; }
+ FILE* get() const noexcept { return file_; }
- // We place parentheses around fileno to workaround a bug in some versions
- // of MinGW that define fileno as a macro.
- FMT_API int(fileno)() const;
+ FMT_API int descriptor() const;
void vprint(string_view format_str, format_args args) {
fmt::vprint(file_, format_str, args);
#if FMT_USE_FCNTL
// A file. Closed file is represented by a file object with descriptor -1.
-// Methods that are not declared with FMT_NOEXCEPT may throw
+// Methods that are not declared with noexcept may throw
// fmt::system_error in case of failure. Note that some errors such as
// closing the file multiple times will cause a crash on Windows rather
// than an exception. You can get standard behavior by overriding the
// invalid parameter handler with _set_invalid_parameter_handler.
-class file {
+class FMT_API file {
private:
int fd_; // File descriptor.
};
// Constructs a file object which doesn't represent any file.
- file() FMT_NOEXCEPT : fd_(-1) {}
+ file() noexcept : fd_(-1) {}
// Opens a file and constructs a file object representing this file.
- FMT_API file(cstring_view path, int oflag);
+ file(cstring_view path, int oflag);
public:
file(const file&) = delete;
void operator=(const file&) = delete;
- file(file&& other) FMT_NOEXCEPT : fd_(other.fd_) { other.fd_ = -1; }
+ file(file&& other) noexcept : fd_(other.fd_) { other.fd_ = -1; }
// Move assignment is not noexcept because close may throw.
file& operator=(file&& other) {
}
// Destroys the object closing the file it represents if any.
- FMT_API ~file() FMT_NOEXCEPT;
+ ~file() noexcept;
// Returns the file descriptor.
- int descriptor() const FMT_NOEXCEPT { return fd_; }
+ int descriptor() const noexcept { return fd_; }
// Closes the file.
- FMT_API void close();
+ void close();
// Returns the file size. The size has signed type for consistency with
// stat::st_size.
- FMT_API long long size() const;
+ long long size() const;
// Attempts to read count bytes from the file into the specified buffer.
- FMT_API size_t read(void* buffer, size_t count);
+ size_t read(void* buffer, size_t count);
// Attempts to write count bytes from the specified buffer to the file.
- FMT_API size_t write(const void* buffer, size_t count);
+ size_t write(const void* buffer, size_t count);
// Duplicates a file descriptor with the dup function and returns
// the duplicate as a file object.
- FMT_API static file dup(int fd);
+ static file dup(int fd);
// Makes fd be the copy of this file descriptor, closing fd first if
// necessary.
- FMT_API void dup2(int fd);
+ void dup2(int fd);
// Makes fd be the copy of this file descriptor, closing fd first if
// necessary.
- FMT_API void dup2(int fd, std::error_code& ec) FMT_NOEXCEPT;
+ void dup2(int fd, std::error_code& ec) noexcept;
// Creates a pipe setting up read_end and write_end file objects for reading
// and writing respectively.
- FMT_API static void pipe(file& read_end, file& write_end);
+ static void pipe(file& read_end, file& write_end);
// Creates a buffered_file object associated with this file and detaches
// this file object from the file.
- FMT_API buffered_file fdopen(const char* mode);
+ buffered_file fdopen(const char* mode);
};
// Returns the memory page size.
* ``<integer>``: Flags passed to `open
<https://pubs.opengroup.org/onlinepubs/007904875/functions/open.html>`_
- (``file::WRONLY | file::CREATE`` by default)
+ (``file::WRONLY | file::CREATE | file::TRUNC`` by default)
* ``buffer_size=<integer>``: Output buffer size
**Example**::
}
#endif // FMT_USE_FCNTL
-#ifdef FMT_LOCALE
-// A "C" numeric locale.
-class locale {
- private:
-# ifdef _WIN32
- using locale_t = _locale_t;
-
- static void freelocale(locale_t loc) { _free_locale(loc); }
-
- static double strtod_l(const char* nptr, char** endptr, _locale_t loc) {
- return _strtod_l(nptr, endptr, loc);
- }
-# endif
-
- locale_t locale_;
-
- public:
- using type = locale_t;
- locale(const locale&) = delete;
- void operator=(const locale&) = delete;
-
- locale() {
-# ifndef _WIN32
- locale_ = FMT_SYSTEM(newlocale(LC_NUMERIC_MASK, "C", nullptr));
-# else
- locale_ = _create_locale(LC_NUMERIC, "C");
-# endif
- if (!locale_) FMT_THROW(system_error(errno, "cannot create locale"));
- }
- ~locale() { freelocale(locale_); }
-
- type get() const { return locale_; }
-
- // Converts string to floating-point number and advances str past the end
- // of the parsed input.
- FMT_DEPRECATED double strtod(const char*& str) const {
- char* end = nullptr;
- double result = strtod_l(str, &end, locale_);
- str = end;
- return result;
- }
-};
-using Locale FMT_DEPRECATED_ALIAS = locale;
-#endif // FMT_LOCALE
FMT_MODULE_EXPORT_END
FMT_END_NAMESPACE