16 #include <system_error> 18 #if defined __APPLE__ || defined(__FreeBSD__) 25 #if FMT_HAS_INCLUDE("winapifamily.h") 26 # include <winapifamily.h> 28 #if (FMT_HAS_INCLUDE(<fcntl.h>) || defined(__APPLE__) || \ 29 defined(__linux__)) && \ 30 (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) 32 # define FMT_USE_FCNTL 1 34 # define FMT_USE_FCNTL 0 38 # if defined(_WIN32) && !defined(__MINGW32__) 40 # define FMT_POSIX(call) _##call 42 # define FMT_POSIX(call) call 48 # define FMT_POSIX_CALL(call) FMT_SYSTEM(call) 50 # define FMT_SYSTEM(call) ::call 53 # define FMT_POSIX_CALL(call) ::_##call 55 # define FMT_POSIX_CALL(call) ::call 62 # define FMT_RETRY_VAL(result, expression, error_result) \ 64 (result) = (expression); \ 65 } while ((result) == (error_result) && errno == EINTR) 67 # define FMT_RETRY_VAL(result, expression, error_result) result = (expression) 70 #define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1) 123 template <
typename ParseContext>
128 template <
typename FormatContext>
130 -> decltype(ctx.out()) {
131 auto out = ctx.out();
134 out = detail::write<Char>(out, Char(
':'));
135 out = detail::write<Char>(out, ec.value());
146 class utf16_to_utf8 {
154 size_t size()
const {
return buffer_.size() - 1; }
155 const char*
c_str()
const {
return &buffer_[0]; }
156 std::string str()
const {
return std::string(&buffer_[0],
size()); }
199 template <
typename... Args>
201 const Args&... args) {
207 FMT_API void report_windows_error(
int error_code,
217 template <
typename S,
typename... Args,
typename Char =
char_t<S>>
218 void say(
const S& format_str, Args&&... args) {
244 other.file_ =
nullptr;
250 other.file_ =
nullptr;
261 FILE*
get()
const FMT_NOEXCEPT {
return file_; }
271 template <
typename... Args>
289 explicit file(
int fd) : fd_(fd) {}
309 file(
const file&) =
delete;
310 void operator=(
const file&) =
delete;
312 file(file&& other)
FMT_NOEXCEPT : fd_(other.fd_) { other.fd_ = -1; }
315 file& operator=(file&& other) {
326 int descriptor()
const FMT_NOEXCEPT {
return fd_; }
343 FMT_API static file dup(
int fd);
368 buffer_size() =
default;
370 buffer_size operator=(
size_t val)
const {
371 auto bs = buffer_size();
377 struct ostream_params {
378 int oflag = file::WRONLY | file::CREATE | file::TRUNC;
379 size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768;
383 template <
typename... T>
384 ostream_params(T... params,
int new_oflag) : ostream_params(params...) {
388 template <
typename... T>
389 ostream_params(T... params, detail::buffer_size bs)
390 : ostream_params(params...) {
391 this->buffer_size = bs.value;
397 static constexpr detail::buffer_size buffer_size;
400 class FMT_API ostream final :
private detail::buffer<char> {
405 if (
size() == 0)
return;
410 void grow(
size_t)
override;
412 ostream(
cstring_view path,
const detail::ostream_params& params)
413 : file_(path, params.oflag) {
414 set(
new char[params.buffer_size], params.buffer_size);
418 ostream(ostream&& other)
419 : detail::buffer<char>(other.data(), other.size(), other.capacity()),
422 other.set(
nullptr, 0);
429 template <
typename... T>
430 friend ostream output_file(
cstring_view path, T... params);
442 vformat_to(detail::buffer_appender<char>(*
this), fmt,
462 template <
typename... T>
463 inline ostream output_file(
cstring_view path, T... params) {
464 return {path, detail::ostream_params(params...)};
466 #endif // FMT_USE_FCNTL 473 using locale_t = _locale_t;
475 static void freelocale(locale_t loc) { _free_locale(loc); }
477 static double strtod_l(
const char* nptr,
char** endptr, _locale_t loc) {
478 return _strtod_l(nptr, endptr, loc);
485 using type = locale_t;
486 locale(
const locale&) =
delete;
487 void operator=(
const locale&) =
delete;
491 locale_ =
FMT_SYSTEM(newlocale(LC_NUMERIC_MASK,
"C",
nullptr));
493 locale_ = _create_locale(LC_NUMERIC,
"C");
497 ~locale() { freelocale(locale_); }
499 type get()
const {
return locale_; }
503 double strtod(
const char*& str)
const {
505 double result = strtod_l(str, &end, locale_);
#define FMT_MODULE_EXPORT_END
basic_cstring_view(const Char *s)
typename detail::char_t_impl< S >::type char_t
#define FMT_BEGIN_DETAIL_NAMESPACE
#define FMT_END_DETAIL_NAMESPACE
void convert(const char *strb, const char *stre, F &&f)
void print(std::FILE *f, const text_style &ts, const S &format_str, const Args &... args)
constexpr auto make_format_args(const Args &... args) -> format_arg_store< Context, Args... >
#define FMT_END_NAMESPACE
basic_string_view< char > string_view
auto write(OutputIt out, const std::tm &time, const std::locale &loc, char format, char modifier=0) -> OutputIt
FMT_END_DETAIL_NAMESPACE void vprint(std::FILE *f, const text_style &ts, const S &format, basic_format_args< buffer_context< type_identity_t< Char >>> args)
const std::error_category & system_category() FMT_NOEXCEPT
constexpr auto count() -> size_t
buffered_file() FMT_NOEXCEPT
const T & move(const T &v)
void print(string_view format_str, const Args &... args)
buffered_file & operator=(buffered_file &&other)
basic_cstring_view(const std::basic_string< Char > &s)
void vprint(string_view format_str, format_args args)
span_constexpr std::size_t size(span< T, Extent > const &spn)
void clear(lua_State *L, int table_index)
#define FMT_BEGIN_NAMESPACE
#define FMT_MODULE_EXPORT_BEGIN
buffered_file(buffered_file &&other) FMT_NOEXCEPT
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)
const Char * c_str() const
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)