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) \
65 (result) = (expression); \
66 } while ((result) == (error_result) && errno == EINTR)
68# define FMT_RETRY_VAL(result, expression, error_result) result = (expression)
71#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
117 const Char*
c_str()
const {
return data_; }
124 template <
typename ParseContext>
129 template <
typename FormatContext>
131 ->
decltype(ctx.out()) {
132 auto out = ctx.out();
135 out = detail::write<Char>(out, Char(
':'));
136 out = detail::write<Char>(out, ec.value());
155 size_t size()
const {
return buffer_.size() - 1; }
156 const char* c_str()
const {
return &buffer_[0]; }
157 std::string str()
const {
return std::string(&buffer_[0],
size()); }
166 const char* message)
noexcept;
200template <
typename... Args>
202 const Args&... args) {
208FMT_API void report_windows_error(
int error_code,
const char* message)
noexcept;
217template <
typename S,
typename... Args,
typename Char =
char_t<S>>
218void say(
const S& format_str, Args&&... args) {
219 std::system(
format(
"say \"{}\"",
format(format_str, args...)).c_str());
244 other.file_ =
nullptr;
250 other.file_ =
nullptr;
261 FILE*
get() const noexcept {
return file_; }
269 template <
typename... Args>
287 explicit file(
int fd) : fd_(fd) {}
301 file() noexcept : fd_(-1) {}
308 void operator=(
const file&) =
delete;
310 file(
file&& other) noexcept : fd_(other.fd_) { other.fd_ = -1; }
324 int descriptor() const noexcept {
return fd_; }
331 long long size()
const;
341 static file dup(
int fd);
349 void dup2(
int fd, std::error_code& ec)
noexcept;
353 static void pipe(
file& read_end,
file& write_end);
366 buffer_size() =
default;
368 buffer_size operator=(
size_t val)
const {
369 auto bs = buffer_size();
375struct ostream_params {
376 int oflag = file::WRONLY | file::CREATE | file::TRUNC;
377 size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768;
381 template <
typename... T>
382 ostream_params(T... params,
int new_oflag) : ostream_params(params...) {
386 template <
typename... T>
387 ostream_params(T... params, detail::buffer_size bs)
388 : ostream_params(params...) {
389 this->buffer_size = bs.value;
394# if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 2000
395 ostream_params(
int new_oflag) : oflag(new_oflag) {}
396 ostream_params(detail::buffer_size bs) : buffer_size(bs.
value) {}
404constexpr detail::buffer_size buffer_size{};
407class FMT_API ostream final :
private detail::buffer<char> {
411 void grow(
size_t)
override;
413 ostream(
cstring_view path,
const detail::ostream_params& params)
414 : file_(path, params.oflag) {
415 set(
new char[params.buffer_size], params.buffer_size);
419 ostream(ostream&& other)
421 file_(
std::move(other.file_)) {
423 other.set(
nullptr, 0);
431 if (
size() == 0)
return;
436 template <
typename... T>
437 friend ostream output_file(
cstring_view path, T... params);
449 vformat_to(detail::buffer_appender<char>(*
this), fmt,
469template <
typename... T>
470inline ostream output_file(
cstring_view path, T... params) {
471 return {path, detail::ostream_params(params...)};
then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file
Definition: ThirdPartyNotices.txt:195
\rst A reference to a null-terminated string.
Definition: os.h:101
basic_cstring_view(const std::basic_string< Char > &s)
\rst Constructs a string reference from an std::string object.
Definition: os.h:114
basic_cstring_view(const Char *s)
Constructs a string reference object from a C string.
Definition: os.h:107
const Char * c_str() const
Returns the pointer to a C string.
Definition: os.h:117
\rst A dynamically growing memory buffer for trivially copyable/constructible types with the first SI...
Definition: format.h:819
An implementation of std::basic_string_view for pre-C++17.
Definition: core.h:430
void clear()
Clears this buffer.
Definition: core.h:914
void vprint(string_view format_str, format_args args)
Definition: os.h:265
void operator=(const buffered_file &)=delete
FMT_API int descriptor() const
FMT_API ~buffered_file() noexcept
friend class file
Definition: os.h:228
FILE * get() const noexcept
Definition: os.h:261
buffered_file() noexcept
Definition: os.h:237
FMT_API buffered_file(cstring_view filename, cstring_view mode)
buffered_file(const buffered_file &)=delete
void print(string_view format_str, const Args &... args)
Definition: os.h:270
buffered_file & operator=(buffered_file &&other)
Definition: os.h:247
basic_string_view< char > string_view
Definition: core.h:520
typename detail::char_t_impl< S >::type char_t
String's character type.
Definition: core.h:644
#define FMT_END_DETAIL_NAMESPACE
Definition: core.h:227
#define FMT_MODULE_EXPORT_BEGIN
Definition: core.h:224
constexpr auto count() -> size_t
Definition: core.h:1204
constexpr auto make_format_args(Args &&... args) -> format_arg_store< Context, remove_cvref_t< Args >... >
\rst Constructs a ~fmtformat_arg_store object that contains references to arguments and can be implic...
Definition: core.h:1916
#define FMT_CONSTEXPR
Definition: core.h:106
#define FMT_BEGIN_NAMESPACE
Definition: core.h:214
#define FMT_BEGIN_DETAIL_NAMESPACE
Definition: core.h:226
#define FMT_API
Definition: core.h:246
#define FMT_END_NAMESPACE
Definition: core.h:217
#define FMT_MODULE_EXPORT_END
Definition: core.h:225
static constexpr T convert(const T &value) noexcept
converts a value from one type to another.
Definition: base.h:1648
FMT_BEGIN_NAMESPACE void vprint(wpi::raw_ostream &os, string_view format_str, fmt::format_args args)
Definition: raw_ostream.h:13
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: PacketMath.h:646
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
auto write(OutputIt out, const std::tm &time, const std::locale &loc, char format, char modifier=0) -> OutputIt
Definition: chrono.h:426
Definition: StdDeque.h:50
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Definition: Endian.h:65
#define FMT_POSIX(call)
Definition: os.h:43
const std::error_category & system_category() noexcept
Definition: os.h:210
Definition: format.h:1544
#define S(label, offset, message)
Definition: Errors.h:118
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:87
auto vformat_to(OutputIt out, const S &format_str, basic_format_args< buffer_context< type_identity_t< Char > > > args) -> OutputIt
Definition: xchar.h:124