29 #ifndef _CRT_SECURE_NO_WARNINGS 30 # define _CRT_SECURE_NO_WARNINGS 36 #include <sys/types.h> 45 # define O_CREAT _O_CREAT 46 # define O_TRUNC _O_TRUNC 49 # define S_IRUSR _S_IREAD 53 # define S_IWUSR _S_IWRITE 57 # define _SH_DENYNO 0x40 73 inline unsigned convert_rwcount(std::size_t count) {
74 return count <= UINT_MAX ? static_cast<unsigned>(count) : UINT_MAX;
78 typedef ssize_t RWResult;
80 inline std::size_t convert_rwcount(std::size_t count) {
return count; }
93 throw SystemError(errno,
"cannot open file {}", filename);
111 throw SystemError(errno,
"cannot get file descriptor");
116 int mode = S_IRUSR | S_IWUSR;
117 #if defined(_WIN32) && !defined(__MINGW32__) 124 throw SystemError(errno,
"cannot open file {}", path);
150 DWORD size_upper = 0;
151 HANDLE handle =
reinterpret_cast<HANDLE
>(_get_osfhandle(fd_));
152 DWORD size_lower =
FMT_SYSTEM(GetFileSize(handle, &size_upper));
153 if (size_lower == INVALID_FILE_SIZE) {
154 DWORD error = GetLastError();
155 if (error != NO_ERROR)
156 throw WindowsError(GetLastError(),
"cannot get file size");
159 return (long_size <<
sizeof(DWORD) * CHAR_BIT) | size_lower;
161 typedef struct stat Stat;
162 Stat file_stat = Stat();
164 throw SystemError(errno,
"cannot get file attributes");
166 "return type of File::size is not large enough");
167 return file_stat.st_size;
192 throw SystemError(errno,
"cannot duplicate file descriptor {}", fd);
201 "cannot duplicate file descriptor {} to {}", fd_, fd);
220 enum { DEFAULT_CAPACITY = 65536 };
221 int result =
FMT_POSIX_CALL(pipe(fds, DEFAULT_CAPACITY, _O_BINARY));
231 read_end =
File(fds[0]);
232 write_end =
File(fds[1]);
239 throw SystemError(errno,
"cannot associate stream with file descriptor");
249 return si.dwPageSize;
253 throw SystemError(errno,
"cannot get memory page size");
#define FMT_STATIC_ASSERT(cond, message)
const Char * c_str() const
FMT_GCC_EXTENSION typedef unsigned long long ULongLong
void write(const mValue &value, std::ostream &os, unsigned int options=0)
#define FMT_RETRY_VAL(result, expression, error_result)
std::size_t write(const void *buffer, std::size_t count)
#define FMT_RETRY(result, expression)
MakeUnsigned< Int >::Type to_unsigned(Int value)
FMT_API void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT
BufferedFile() FMT_NOEXCEPT
bool read(const std::string &s, mValue &value)
static void pipe(File &read_end, File &write_end)
BufferedFile fdopen(const char *mode)
std::size_t read(void *buffer, std::size_t count)
~BufferedFile() FMT_NOEXCEPT
#define FMT_POSIX_CALL(call)
FMT_GCC_EXTENSION typedef long long LongLong