37 #include "filesystem.h"
39 #include <errhandlingapi.h>
53 File::File(boost::filesystem::path path, std::string mode)
58 std::wstring mode_wide(mode.begin(), mode.end());
60 _file = _wfopen(dcp::filesystem::fix_long_path(path).c_str(), mode_wide.c_str());
62 _open_error = GetLastError();
65 _file = fopen(path.c_str(), mode.c_str());
76 , _open_error(other._open_error)
78 other._file =
nullptr;
83 File::operator=(
File&& other)
88 _open_error = other._open_error;
89 other._file =
nullptr;
109 return fwrite(ptr, size, nmemb, _file);
117 return fread(ptr, size, nmemb, _file);
133 return fgets(s, size, _file);
141 return fputs(s, _file);
145 File::operator bool()
const
147 return _file !=
nullptr;
152 File::checked_write(
void const * ptr,
size_t size)
154 size_t N =
write(ptr, 1, size);
157 throw FileError(
"fwrite error", _path, errno);
159 throw FileError(
"Unexpected short write", _path, 0);
166 File::checked_read(
void* ptr,
size_t size)
168 size_t N =
read(ptr, 1, size);
171 throw FileError(
"fread error %1", _path, errno);
173 throw FileError(
"Unexpected short read", _path, 0);
192 #ifdef LIBDCP_WINDOWS
193 return _fseeki64(_file, offset, whence);
195 return fseek(_file, offset, whence);
204 #ifdef LIBDCP_WINDOWS
205 return _ftelli64(_file);
217 return ferror(_file);
An exception related to a file.
File(boost::filesystem::path, std::string mode)
char * gets(char *s, int size)
size_t write(const void *ptr, size_t size, size_t nmemb)
size_t read(void *ptr, size_t size, size_t nmemb)
int seek(int64_t offset, int whence)
Namespace for everything in libdcp.