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_; }
127FMT_API void format_windows_error(buffer<char>& out,
int error_code,
128 const char* message)
noexcept;
162template <
typename... Args>
164 const Args&... args) {
170FMT_API void report_windows_error(
int error_code,
const char* message)
noexcept;
179template <
typename S,
typename... Args,
typename Char =
char_t<S>>
180void say(
const S& format_str, Args&&... args) {
181 std::system(
format(
"say \"{}\"",
format(format_str, args...)).c_str());
206 other.file_ =
nullptr;
212 other.file_ =
nullptr;
223 FILE*
get() const noexcept {
return file_; }
231 template <
typename... Args>
249 explicit file(
int fd) : fd_(fd) {}
263 file() noexcept : fd_(-1) {}
270 void operator=(
const file&) =
delete;
272 file(
file&& other) noexcept : fd_(other.fd_) { other.fd_ = -1; }
286 int descriptor() const noexcept {
return fd_; }
293 long long size()
const;
299 size_t write(
const void* buffer,
size_t count);
303 static file dup(
int fd);
311 void dup2(
int fd, std::error_code& ec)
noexcept;
315 static void pipe(
file& read_end,
file& write_end);
321# if defined(_WIN32) && !defined(__MINGW32__)
334 buffer_size() =
default;
336 buffer_size operator=(
size_t val)
const {
337 auto bs = buffer_size();
343struct ostream_params {
344 int oflag = file::WRONLY | file::CREATE | file::TRUNC;
345 size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768;
349 template <
typename... T>
350 ostream_params(T... params,
int new_oflag) : ostream_params(params...) {
354 template <
typename... T>
355 ostream_params(T... params, detail::buffer_size bs)
356 : ostream_params(params...) {
357 this->buffer_size = bs.value;
362# if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 2000
363 ostream_params(
int new_oflag) : oflag(new_oflag) {}
364 ostream_params(detail::buffer_size bs) : buffer_size(bs.
value) {}
368class file_buffer final :
public buffer<char> {
371 FMT_API void grow(
size_t)
override;
375 FMT_API file_buffer(file_buffer&& other);
379 if (size() == 0)
return;
380 file_.write(data(), size() *
sizeof(data()[0]));
394constexpr detail::buffer_size buffer_size{};
400 detail::file_buffer buffer_;
402 ostream(
cstring_view path,
const detail::ostream_params& params)
403 : buffer_(path, params) {}
406 ostream(ostream&& other) : buffer_(
std::move(other.buffer_)) {}
410 void flush() { buffer_.flush(); }
412 template <
typename... T>
413 friend ostream output_file(
cstring_view path, T... params);
415 void close() { buffer_.close(); }
442template <
typename... T>
443inline ostream output_file(
cstring_view path, T... params) {
444 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:192
\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
void vprint(string_view format_str, format_args args)
Definition: os.h:227
void operator=(const buffered_file &)=delete
FMT_API int descriptor() const
FMT_API ~buffered_file() noexcept
friend class file
Definition: os.h:190
FILE * get() const noexcept
Definition: os.h:223
buffered_file() noexcept
Definition: os.h:199
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:232
buffered_file & operator=(buffered_file &&other)
Definition: os.h:209
#define FMT_END_EXPORT
Definition: core.h:185
typename detail::char_t_impl< S >::type char_t
String's character type.
Definition: core.h:646
#define FMT_BEGIN_NAMESPACE
Definition: core.h:174
#define FMT_API
Definition: core.h:202
constexpr auto make_format_args(T &... args) -> format_arg_store< Context, remove_cvref_t< T >... >
\rst Constructs a ~fmtformat_arg_store object that contains references to arguments and can be implic...
Definition: core.h:1824
#define FMT_BEGIN_EXPORT
Definition: core.h:184
#define FMT_MSC_WARNING(...)
Definition: core.h:58
#define FMT_END_NAMESPACE
Definition: core.h:177
void print(wpi::raw_ostream &os, const S &format_str, Args &&... args)
Prints formatted data to the stream os.
Definition: raw_ostream.h:25
FMT_BEGIN_NAMESPACE void vprint(wpi::raw_ostream &os, string_view format_str, fmt::format_args args)
Definition: raw_ostream.h:14
detail namespace with internal helper functions
Definition: xchar.h:20
auto write(OutputIt out, const std::tm &time, const std::locale &loc, char format, char modifier=0) -> OutputIt
Definition: chrono.h:419
@ value
the parser finished reading a JSON value
constexpr auto count() -> size_t
Definition: core.h:1203
conditional_t< std::is_same< T, char >::value, appender, std::back_insert_iterator< buffer< T > > > buffer_appender
Definition: core.h:1113
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:172
#define S(label, offset, message)
Definition: Errors.h:119
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:108
auto vformat_to(OutputIt out, const S &format_str, basic_format_args< buffer_context< type_identity_t< Char > > > args) -> OutputIt
Definition: xchar.h:144