17# include <system_error>
19# if FMT_HAS_INCLUDE(<xlocale.h>)
26# if FMT_HAS_INCLUDE("winapifamily.h")
27# include <winapifamily.h>
29# if (FMT_HAS_INCLUDE(<fcntl.h>) || defined(__APPLE__) || \
30 defined(__linux__)) && \
31 (!defined(WINAPI_FAMILY) || \
32 (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) && \
35# define FMT_USE_FCNTL 1
37# 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_HAS_SYSTEM
53# define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
55# define FMT_SYSTEM(call) ::call
58# define FMT_POSIX_CALL(call) ::_##call
60# define FMT_POSIX_CALL(call) ::call
67# define FMT_RETRY_VAL(result, expression, error_result) \
69 (result) = (expression); \
70 } while ((result) == (error_result) && errno == EINTR)
72# define FMT_RETRY_VAL(result, expression, error_result) result = (expression)
75#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
108 auto c_str() const -> const Char* {
return data_; }
118FMT_API void format_windows_error(buffer<char>& out,
int error_code,
119 const char* message)
noexcept;
150template <
typename... T>
151auto windows_error(
int error_code,
string_view message,
const T&... args)
152 -> std::system_error {
153 return vwindows_error(error_code, message,
vargs<T...>{{args...}});
158FMT_API void report_windows_error(
int error_code,
const char* message)
noexcept;
161 return std::system_category();
167template <
typename S,
typename... Args,
typename Char = char_t<S>>
168void say(
const S& fmt, Args&&... args) {
169 std::system(
format(
"say \"{}\"",
format(fmt, args...)).c_str());
194 other.file_ =
nullptr;
200 other.file_ =
nullptr;
211 inline auto get() const noexcept -> FILE* {
return file_; }
215 template <typename... T>
217 fmt::vargs<T...>
vargs = {{args...}};
219 : fmt::vprint(file_, fmt,
vargs);
236 explicit file(
int fd) : fd_(fd) {}
252 inline file() noexcept : fd_(-1) {}
258 file(
const file&) =
delete;
259 void operator=(
const file&) =
delete;
261 inline file(file&& other) noexcept : fd_(other.fd_) { other.fd_ = -1; }
264 inline auto operator=(file&& other) -> file& {
275 inline auto descriptor() const noexcept ->
int {
return fd_; }
282 auto size() const ->
long long;
285 auto read(
void* buffer,
size_t count) ->
size_t;
288 auto write(const
void* buffer,
size_t count) ->
size_t;
292 static auto dup(
int fd) -> file;
300 void dup2(
int fd,
std::error_code& ec) noexcept;
306# if defined(_WIN32) && !defined(__MINGW32__)
309 static file open_windows_file(
wcstring_view path,
int oflag);
323auto getpagesize() -> long;
328 constexpr buffer_size() =
default;
330 FMT_CONSTEXPR auto operator=(
size_t val)
const -> buffer_size {
331 auto bs = buffer_size();
337struct ostream_params {
338 int oflag = file::WRONLY | file::CREATE | file::TRUNC;
339 size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768;
341 constexpr ostream_params() {}
343 template <
typename... T>
344 ostream_params(T... params,
int new_oflag) : ostream_params(params...) {
348 template <
typename... T>
349 ostream_params(T... params, detail::buffer_size bs)
350 : ostream_params(params...) {
351 this->buffer_size = bs.value;
356# if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 2000
357 ostream_params(
int new_oflag) : oflag(new_oflag) {}
358 ostream_params(detail::buffer_size bs) : buffer_size(bs.value) {}
372 ostream(
cstring_view path,
const detail::ostream_params& params);
374 static void grow(buffer<char>& buf,
size_t);
377 ostream(ostream&& other)
noexcept;
385 inline void flush() {
386 if (size() == 0)
return;
387 file_.write(data(), size() *
sizeof(data()[0]));
391 template <
typename... T>
392 friend auto output_file(
cstring_view path, T... params) -> ostream;
394 inline void close() {
419template <
typename... T>
420inline auto output_file(
cstring_view path, T... params) -> ostream {
421 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:204
#define FMT_END_EXPORT
Definition base.h:264
typename fstring< T... >::t format_string
Definition base.h:2779
basic_appender< char > appender
Definition base.h:616
#define FMT_CONSTEXPR
Definition base.h:113
#define FMT_BEGIN_NAMESPACE
Definition base.h:253
#define FMT_API
Definition base.h:283
#define FMT_BEGIN_EXPORT
Definition base.h:263
#define FMT_END_NAMESPACE
Definition base.h:256
A reference to a null-terminated string.
Definition os.h:96
basic_cstring_view(const std::basic_string< Char > &s)
Constructs a string reference from an std::string object.
Definition os.h:105
basic_cstring_view(const Char *s)
Constructs a string reference object from a C string.
Definition os.h:102
auto c_str() const -> const Char *
Returns the pointer to a C string.
Definition os.h:108
void operator=(const buffered_file &)=delete
auto operator=(buffered_file &&other) -> buffered_file &
Definition os.h:197
FMT_API ~buffered_file() noexcept
auto get() const noexcept -> FILE *
Definition os.h:211
buffered_file() noexcept
Definition os.h:187
FMT_API auto descriptor() const -> int
void print(string_view fmt, const T &... args)
Definition os.h:216
FMT_API buffered_file(cstring_view filename, cstring_view mode)
buffered_file(const buffered_file &)=delete
A contiguous memory buffer with an optional growing ability.
Definition base.h:1763
Converts a string literal into a format string that will be parsed at compile time and converted into...
Definition printf.h:50
FMT_CONSTEXPR auto is_locking() -> bool
Definition base.h:2428
Definition PointerIntPair.h:280
#define FMT_POSIX(call)
Definition os.h:46
auto system_category() noexcept -> const std::error_category &
Definition os.h:160
#define S(label, offset, message)
Definition Errors.h:113
void print(FILE *f, text_style ts, format_string< T... > fmt, T &&... args)
Formats a string and prints it to the specified file stream using ANSI escape sequences to specify te...
Definition color.h:513