14#include <system_error>
16#if defined __APPLE__ || defined(__FreeBSD__)
24#if FMT_HAS_INCLUDE("winapifamily.h")
25#include <winapifamily.h>
27#if (FMT_HAS_INCLUDE(<fcntl.h>) || defined(__APPLE__) || \
28 defined(__linux__)) && \
29 (!defined(WINAPI_FAMILY) || \
30 (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
32#define FMT_USE_FCNTL 1
34#define FMT_USE_FCNTL 0
39#if defined(_WIN32) && !defined(__MINGW32__)
41#define FMT_POSIX(call) _##call
43#define FMT_POSIX(call) call
49#define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
51#define FMT_SYSTEM(call) ::call
54#define FMT_POSIX_CALL(call) ::_##call
56#define FMT_POSIX_CALL(call) ::call
63#define FMT_RETRY_VAL(result, expression, error_result) \
66 (result) = (expression); \
67 } while ((result) == (error_result) && errno == EINTR)
69#define FMT_RETRY_VAL(result, expression, error_result) result = (expression)
72#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
102template <
typename Char>
135template <
typename Char>
138 template <
typename ParseContext>
144 template <
typename FormatContext>
146 ->
decltype(ctx.out())
148 auto out = ctx.out();
149 out = detail::write_bytes(
out, ec.category().name(),
151 out = detail::write<Char>(
out, Char(
':'));
152 out = detail::write<Char>(
out, ec.value());
179 return buffer_.size() - 1;
181 const char* c_str()
const
185 std::string str()
const
187 return std::string(&buffer_[0], size());
229template <
typename... Args>
230std::system_error windows_error(
int error_code,
string_view message,
const Args&... args)
232 return vwindows_error(error_code, message, fmt::make_format_args(args...));
237FMT_API void report_windows_error(
int error_code,
const char* message)
noexcept;
241 return std::system_category();
247template <
typename S,
typename... Args,
typename Char =
char_t<S>>
248void say(
const S& format_str, Args&&... args)
250 std::system(
format(
"say \"{}\"",
format(format_str, args...)).c_str());
284 other.
file_ =
nullptr;
291 other.file_ =
nullptr;
302 FILE*
get() const noexcept
311 fmt::vprint(
file_, format_str, args);
314 template <
typename... Args>
317 vprint(format_str, fmt::make_format_args(args...));
334 explicit file(
int fd)
361 file(
const file&) =
delete;
362 void operator=(
const file&) =
delete;
364 file(file&& other) noexcept
371 file& operator=(file&& other)
383 int descriptor() const noexcept
393 long long size()
const;
403 static file dup(
int fd);
411 void dup2(
int fd, std::error_code& ec)
noexcept;
415 static void pipe(file& read_end, file& write_end);
429 buffer_size() =
default;
431 buffer_size operator=(
size_t val)
const
433 auto bs = buffer_size();
441 int oflag = file::WRONLY | file::CREATE | file::TRUNC;
442 size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768;
448 template <
typename... T>
449 ostream_params(T... params,
int new_oflag)
450 : ostream_params(params...)
455 template <
typename... T>
456 ostream_params(T... params, detail::buffer_size bs)
457 : ostream_params(params...)
459 this->buffer_size = bs.value;
464#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 2000
465 ostream_params(
int new_oflag)
469 ostream_params(detail::buffer_size bs)
470 : buffer_size(bs.
value)
480constexpr detail::buffer_size buffer_size{};
483class FMT_API ostream final :
private detail::buffer<char>
488 void grow(
size_t)
override;
490 ostream(
cstring_view path,
const detail::ostream_params& params)
491 : file_(path, params.oflag)
493 set(
new char[params.buffer_size], params.buffer_size);
497 ostream(ostream&& other)
499 file_(
std::move(other.file_))
502 other.set(
nullptr, 0);
514 file_.write(
data(), size());
518 template <
typename... T>
519 friend ostream output_file(
cstring_view path, T... params);
531 template <
typename... T>
535 fmt::make_format_args(args...));
554template <
typename... T>
555inline ostream output_file(
cstring_view path, T... params)
557 return {path, detail::ostream_params(params...)};
basic_cstring_view(const std::basic_string< Char > &s)
Definition os.h:120
const Char * data_
Definition os.h:106
basic_cstring_view(const Char *s)
Definition os.h:110
const Char * c_str() const
Definition os.h:126
void clear()
Definition core.h:1114
void vprint(string_view format_str, format_args args)
Definition os.h:309
void operator=(const buffered_file &)=delete
FMT_API int descriptor() const
FMT_API ~buffered_file() noexcept
friend class file
Definition os.h:260
FILE * get() const noexcept
Definition os.h:302
buffered_file(FILE *f)
Definition os.h:262
buffered_file() noexcept
Definition os.h:272
FMT_API buffered_file(cstring_view filename, cstring_view mode)
FILE * file_
Definition os.h:258
buffered_file(const buffered_file &)=delete
void print(string_view format_str, const Args &... args)
Definition os.h:315
buffered_file & operator=(buffered_file &&other)
Definition os.h:287
void print(std::FILE *f, const text_style &ts, const S &format_str, const Args &... args)
Definition color.h:601
void vformat_to(buffer< Char > &buf, const text_style &ts, basic_string_view< Char > format_str, basic_format_args< buffer_context< type_identity_t< Char > > > args)
Definition color.h:545
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
Definition color.h:646
basic_string_view< char > string_view
Definition core.h:604
typename detail::char_t_impl< S >::type char_t
Definition core.h:759
#define FMT_END_DETAIL_NAMESPACE
Definition core.h:231
#define FMT_MODULE_EXPORT_BEGIN
Definition core.h:226
constexpr auto count() -> size_t
Definition core.h:1538
basic_format_string< char, type_identity_t< Args >... > format_string
Definition core.h:4059
#define FMT_CONSTEXPR
Definition core.h:106
#define FMT_BEGIN_NAMESPACE
Definition core.h:214
#define FMT_BEGIN_DETAIL_NAMESPACE
Definition core.h:228
#define FMT_API
Definition core.h:250
#define FMT_END_NAMESPACE
Definition core.h:219
#define FMT_MODULE_EXPORT_END
Definition core.h:227
#define out
Definition encodings.cpp:5
#define FMT_POSIX(call)
Definition os.h:43
const std::error_category & system_category() noexcept
Definition os.h:239
basic_cstring_view< wchar_t > wcstring_view
Definition os.h:133
basic_cstring_view< char > cstring_view
Definition os.h:132
Definition bin_to_hex.h:111
s
Definition tag_strings.h:47