11 #if defined(__MINGW32__) || defined(__CYGWIN__) 13 # undef __STRICT_ANSI__ 22 #if defined __APPLE__ || defined(__FreeBSD__) 29 #if FMT_HAS_INCLUDE("winapifamily.h") 30 # include <winapifamily.h> 32 #if (FMT_HAS_INCLUDE(<fcntl.h>) || defined(__APPLE__) || \ 33 defined(__linux__)) && \ 34 (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) 36 # define FMT_USE_FCNTL 1 38 # define FMT_USE_FCNTL 0 42 # if defined(_WIN32) && !defined(__MINGW32__) 44 # define FMT_POSIX(call) _##call 46 # define FMT_POSIX(call) call 52 # define FMT_POSIX_CALL(call) FMT_SYSTEM(call) 54 # define FMT_SYSTEM(call) ::call 57 # define FMT_POSIX_CALL(call) ::_##call 59 # define FMT_POSIX_CALL(call) ::call 66 # define FMT_RETRY_VAL(result, expression, error_result) \ 68 (result) = (expression); \ 69 } while ((result) == (error_result) && errno == EINTR) 71 # define FMT_RETRY_VAL(result, expression, error_result) result = (expression) 74 #define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1) 119 const Char*
c_str()
const {
return data_; }
131 explicit error_code(
int value = 0) FMT_NOEXCEPT : value_(value) {}
133 int get()
const FMT_NOEXCEPT {
return value_; }
140 class utf16_to_utf8 {
148 size_t size()
const {
return buffer_.
size() - 1; }
149 const char*
c_str()
const {
return &buffer_[0]; }
150 std::string str()
const {
return std::string(&buffer_[0], size()); }
158 FMT_API
void format_windows_error(buffer<char>& out,
int error_code,
196 template <
typename... Args>
197 windows_error(
int error_code,
string_view message,
const Args&... args) {
198 init(error_code, message, make_format_args(args...));
204 FMT_API
void report_windows_error(
int error_code,
229 other.file_ =
nullptr;
235 other.file_ =
nullptr;
243 FMT_API
void close();
246 FILE*
get()
const FMT_NOEXCEPT {
return file_; }
250 FMT_API int(fileno)()
const;
253 fmt::vprint(file_, format_str, args);
256 template <
typename... Args>
257 inline void print(
string_view format_str,
const Args&... args) {
258 vprint(format_str, make_format_args(args...));
274 explicit file(
int fd) : fd_(fd) {}
279 RDONLY = FMT_POSIX(O_RDONLY),
280 WRONLY = FMT_POSIX(O_WRONLY),
281 RDWR = FMT_POSIX(O_RDWR),
282 CREATE = FMT_POSIX(O_CREAT),
283 APPEND = FMT_POSIX(O_APPEND)
287 file() FMT_NOEXCEPT : fd_(-1) {}
293 file(
const file&) =
delete;
294 void operator=(
const file&) =
delete;
296 file(file&& other) FMT_NOEXCEPT : fd_(other.fd_) { other.fd_ = -1; }
298 file& operator=(file&& other) FMT_NOEXCEPT {
306 FMT_API ~file() FMT_NOEXCEPT;
309 int descriptor()
const FMT_NOEXCEPT {
return fd_; }
312 FMT_API
void close();
316 FMT_API
long long size()
const;
319 FMT_API
size_t read(
void* buffer,
size_t count);
322 FMT_API
size_t write(
const void* buffer,
size_t count);
326 FMT_API
static file dup(
int fd);
330 FMT_API
void dup2(
int fd);
334 FMT_API
void dup2(
int fd,
error_code& ec) FMT_NOEXCEPT;
338 FMT_API
static void pipe(file& read_end, file& write_end);
352 buffer_size operator=(
size_t val)
const {
353 auto bs = buffer_size();
359 struct ostream_params {
360 int oflag = file::WRONLY | file::CREATE;
361 size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768;
365 template <
typename... T>
366 ostream_params(T... params,
int oflag) : ostream_params(params...) {
370 template <
typename... T>
371 ostream_params(T... params, detail::buffer_size bs)
372 : ostream_params(params...) {
373 this->buffer_size = bs.value;
378 static constexpr detail::buffer_size buffer_size;
386 if (size() == 0)
return;
387 file_.write(data(), size());
391 FMT_API
void grow(
size_t)
override final;
393 ostream(
cstring_view path,
const detail::ostream_params& params)
394 : file_(path, params.oflag) {
395 set(
new char[params.buffer_size], params.buffer_size);
399 ostream(ostream&& other)
401 file_(std::move(other.file_)) {
402 other.set(
nullptr, 0);
409 template <
typename... T>
410 friend ostream output_file(
cstring_view path, T... params);
417 template <
typename S,
typename... Args>
418 void print(
const S& format_str,
const Args&... args) {
428 template <
typename... T>
429 inline ostream output_file(
cstring_view path, T... params) {
430 return {path, detail::ostream_params(params...)};
432 #endif // FMT_USE_FCNTL 439 using locale_t = _locale_t;
441 static void freelocale(locale_t loc) { _free_locale(loc); }
443 static double strtod_l(
const char* nptr,
char** endptr, _locale_t loc) {
444 return _strtod_l(nptr, endptr, loc);
451 using type = locale_t;
452 locale(
const locale&) =
delete;
453 void operator=(
const locale&) =
delete;
457 locale_ = FMT_SYSTEM(newlocale(LC_NUMERIC_MASK,
"C",
nullptr));
459 locale_ = _create_locale(LC_NUMERIC,
"C");
461 if (!locale_) FMT_THROW(
system_error(errno,
"cannot create locale"));
463 ~locale() { freelocale(locale_); }
465 type
get()
const {
return locale_; }
469 double strtod(
const char*& str)
const {
471 double result = strtod_l(str, &end, locale_);
basic_cstring_view(const Char *s)
Constructs a string reference object from a C string.
Definition: os.h:109
A dynamically growing memory buffer for trivially copyable/constructible types with the first SIZE el...
Definition: format.h:654
Definition: blocking.hpp:208
size_t size() const FMT_NOEXCEPT
Returns the size of this buffer.
Definition: core.h:706
An error returned by an operating system or a language runtime, for example a file opening error...
Definition: format.h:3267
std::size_t read(SyncReadStream &s, const MutableBufferSequence &buffers, CompletionCondition completion_condition, asio::error_code &ec, typename enable_if< is_mutable_buffer_sequence< MutableBufferSequence >::value >::type *)
Attempt to read a certain amount of data from a stream before returning.
Definition: read.hpp:66
An implementation of std::basic_string_view for pre-C++17.
Definition: core.h:355
std::size_t write(SyncWriteStream &s, const ConstBufferSequence &buffers, CompletionCondition completion_condition, asio::error_code &ec, typename enable_if< is_const_buffer_sequence< ConstBufferSequence >::value >::type *)
Write a certain amount of data to a stream before returning.
Definition: write.hpp:64
A reference to a null-terminated string.
Definition: os.h:103
basic_cstring_view(const std::basic_string< Char > &s)
Constructs a string reference from an std::string object.
Definition: os.h:116
A contiguous memory buffer with an optional growing ability.
Definition: core.h:665
const Char * c_str() const
Returns the pointer to a C string.
Definition: os.h:119