13 #pragma GCC system_header
17 #pragma clang system_header
23 #include <system_error>
25 #if defined __APPLE__ || defined(__FreeBSD__)
33 #if FMT_HAS_INCLUDE("winapifamily.h")
34 #include <winapifamily.h>
36 #if (FMT_HAS_INCLUDE(<fcntl.h>) || defined(__APPLE__) || \
37 defined(__linux__)) && \
38 (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
40 #define FMT_USE_FCNTL 1
42 #define FMT_USE_FCNTL 0
47 #if defined(_WIN32) && !defined(__MINGW32__)
49 #define FMT_POSIX(call) _##call
51 #define FMT_POSIX(call) call
57 #define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
59 #define FMT_SYSTEM(call) ::call
62 #define FMT_POSIX_CALL(call) ::_##call
64 #define FMT_POSIX_CALL(call) ::call
71 #define FMT_RETRY_VAL(result, expression, error_result) \
73 (result) = (expression); \
74 } while ((result) == (error_result) && errno == EINTR)
76 #define FMT_RETRY_VAL(result, expression, error_result) result = (expression)
79 #define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
82 FMT_MODULE_EXPORT_BEGIN
125 const Char *
c_str()
const {
return data_; }
132 FMT_API
const std::error_category &system_category() noexcept;
134 FMT_BEGIN_DETAIL_NAMESPACE
137 class utf16_to_utf8 {
145 size_t size()
const {
return buffer_.size() - 1; }
146 const char *c_str()
const {
return &buffer_[0]; }
147 std::string str()
const {
return std::string(&buffer_[0], size()); }
155 FMT_API
void format_windows_error(
buffer<char> &out,
int error_code,
156 const char *message) noexcept;
157 FMT_END_DETAIL_NAMESPACE
159 FMT_API std::system_error vwindows_error(
int error_code,
string_view format_str,
190 template <
typename... Args>
191 std::system_error windows_error(
int error_code,
string_view message,
192 const Args &...args) {
193 return vwindows_error(error_code, message, fmt::make_format_args(args...));
198 FMT_API
void report_windows_error(
int error_code,
const char *message) noexcept;
200 inline const std::error_category &system_category() noexcept {
201 return std::system_category();
207 template <
typename S,
typename... Args,
typename Char = char_t<S>>
208 void say(
const S &format_str, Args &&...args) {
209 std::system(format(
"say \"{}\"", format(format_str, args...)).c_str());
214 class buffered_file {
220 explicit buffered_file(FILE *f) : file_(
f) {}
223 buffered_file(
const buffered_file &) =
delete;
224 void operator=(
const buffered_file &) =
delete;
227 buffered_file() noexcept : file_(
nullptr) {}
230 FMT_API ~buffered_file() noexcept;
233 buffered_file(buffered_file &&other) noexcept : file_(other.file_) {
234 other.file_ =
nullptr;
237 buffered_file &operator=(buffered_file &&other) {
240 other.file_ =
nullptr;
248 FMT_API
void close();
251 FILE *get() const noexcept {
return file_; }
253 FMT_API
int descriptor()
const;
256 fmt::vprint(file_, format_str, args);
259 template <
typename... Args>
260 inline void print(
string_view format_str,
const Args &...args) {
261 vprint(format_str, fmt::make_format_args(args...));
277 explicit file(
int fd) : fd_(fd) {}
282 RDONLY = FMT_POSIX(O_RDONLY),
283 WRONLY = FMT_POSIX(O_WRONLY),
284 RDWR = FMT_POSIX(O_RDWR),
285 CREATE = FMT_POSIX(O_CREAT),
286 APPEND = FMT_POSIX(O_APPEND),
287 TRUNC = FMT_POSIX(O_TRUNC)
291 file() noexcept : fd_(-1) {}
297 file(
const file &) =
delete;
298 void operator=(
const file &) =
delete;
300 file(file &&other) noexcept : fd_(other.fd_) { other.fd_ = -1; }
303 file &operator=(file &&other) {
314 int descriptor() const noexcept {
return fd_; }
321 long long size()
const;
324 size_t read(
void *
buffer,
size_t count);
327 size_t write(
const void *
buffer,
size_t count);
331 static file dup(
int fd);
339 void dup2(
int fd, std::error_code &ec) noexcept;
343 static void pipe(file &read_end, file &write_end);
347 buffered_file fdopen(
const char *mode);
353 FMT_BEGIN_DETAIL_NAMESPACE
356 buffer_size() =
default;
358 buffer_size operator=(
size_t val)
const {
359 auto bs = buffer_size();
365 struct ostream_params {
366 int oflag = file::WRONLY | file::CREATE | file::TRUNC;
367 size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768;
371 template <
typename... T>
372 ostream_params(T... params,
int new_oflag) : ostream_params(params...) {
376 template <
typename... T>
377 ostream_params(T... params, detail::buffer_size bs)
378 : ostream_params(params...) {
379 this->buffer_size = bs.value;
384 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 2000
385 ostream_params(
int new_oflag) : oflag(new_oflag) {}
386 ostream_params(detail::buffer_size bs) : buffer_size(bs.value) {}
390 class file_buffer final :
public buffer<char> {
393 FMT_API
void grow(
size_t)
override;
396 FMT_API file_buffer(
cstring_view path,
const ostream_params ¶ms);
397 FMT_API file_buffer(file_buffer &&other);
398 FMT_API ~file_buffer();
413 FMT_END_DETAIL_NAMESPACE
417 constexpr detail::buffer_size buffer_size{};
420 class FMT_API ostream {
422 FMT_MSC_WARNING(suppress : 4251)
423 detail::file_buffer buffer_;
425 ostream(
cstring_view path,
const detail::ostream_params ¶ms)
426 : buffer_(path, params) {}
429 ostream(ostream &&other) : buffer_(std::move(other.buffer_)) {}
433 void flush() { buffer_.flush(); }
435 template <
typename... T>
436 friend ostream output_file(
cstring_view path, T... params);
438 void close() { buffer_.close(); }
445 vformat_to(detail::buffer_appender<char>(buffer_), fmt,
446 fmt::make_format_args(args...));
465 template <
typename... T>
466 inline ostream output_file(
cstring_view path, T... params) {
467 return {path, detail::ostream_params(params...)};
471 FMT_MODULE_EXPORT_END
basic_cstring_view(const std::basic_string< Char > &s)
Definition: os.h:122
const Char * c_str() const
Definition: os.h:125
basic_cstring_view(const Char *s)
Definition: os.h:115
void clear()
Definition: core.h:951
FMT_CONSTEXPR auto data() noexcept -> T *
Definition: core.h:945
virtual FMT_CONSTEXPR20 void grow(size_t capacity)=0
constexpr auto size() const noexcept -> size_t
Definition: core.h:939
double f(RaB r, PrincipalQN n, DiracQN k, Zeff z, AlphaFS a)
Upper radial component.
Definition: DiracHydrogen.cpp:71