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)
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()); }
196 template <
typename... Args>
229 other.
file_ =
nullptr;
235 other.file_ =
nullptr;
253 fmt::vprint(
file_, format_str, args);
256 template <
typename... Args>
274 explicit file(
int fd) : fd_(fd) {}
293 file(
const file&) =
delete;
294 void operator=(
const file&) =
delete;
296 file(file&& other)
FMT_NOEXCEPT : fd_(other.fd_) { other.fd_ = -1; }
316 FMT_API long long size()
const;
319 FMT_API size_t read(
void* buffer,
size_t count);
326 FMT_API static file dup(
int fd);
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();
359struct 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;
378static constexpr detail::buffer_size buffer_size;
386 if (
size() == 0)
return;
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)
400 :
detail::buffer<char>(other.data(), other.size(), other.capacity()),
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) {
428template <
typename... T>
429inline ostream output_file(
cstring_view path, T... params) {
430 return {path, detail::ostream_params(params...)};
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");
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_);
const Char * c_str() const
basic_cstring_view(const Char *s)
basic_cstring_view(const std::basic_string< Char > &s)
FILE * get() const FMT_NOEXCEPT
void print(string_view format_str, const Args &... args)
FMT_API buffered_file(cstring_view filename, cstring_view mode)
void vprint(string_view format_str, format_args args)
void operator=(const buffered_file &)=delete
buffered_file & operator=(buffered_file &&other)
FMT_API int fileno() const
FMT_API ~buffered_file() FMT_NOEXCEPT
buffered_file(const buffered_file &)=delete
buffered_file() FMT_NOEXCEPT
void set(T *buf_data, size_t buf_capacity) FMT_NOEXCEPT
size_t size() const FMT_NOEXCEPT
virtual void grow(size_t capacity)=0
int get() const FMT_NOEXCEPT
error_code(int value=0) FMT_NOEXCEPT
void init(int err_code, string_view format_str, format_args args)
void print(std::FILE *f, const text_style &ts, const S &format_str, const Args &... args)
auto format_to(OutputIt out, const text_style &ts, const S &format_str, Args &&... args) -> typename std::enable_if< enable, OutputIt >::type
basic_string_view< char > string_view
format_arg_store< Context, Args... > make_format_args(const Args &... args)
#define FMT_BEGIN_NAMESPACE
#define FMT_END_NAMESPACE
OutputIt write(OutputIt out, basic_string_view< StrChar > s, const basic_format_specs< Char > &specs)