: _path(path)
{
#ifdef LIBDCP_WINDOWS
+ SetLastError(0);
std::wstring mode_wide(mode.begin(), mode.end());
/* c_str() here should give a UTF-16 string */
_file = _wfopen(fix_long_path(path).c_str(), mode_wide.c_str());
+ if (!_file) {
+ _open_error = GetLastError();
+ }
#else
_file = fopen(path.c_str(), mode.c_str());
+ if (!_file) {
+ _open_error = errno;
+ }
#endif
}
File::File(File&& other)
: _path(other._path)
, _file(other._file)
+ , _open_error(other._open_error)
{
other._file = nullptr;
}
if (*this != other) {
close();
_file = other._file;
+ _open_error = other._open_error;
other._file = nullptr;
}
return *this;
return _file;
}
+ /** @return Error returned by the fopen / _wfopen call;
+ * errno on POSIX, GetLastError() on Windows.
+ */
+ int open_error() const {
+ return _open_error;
+ }
+
private:
boost::filesystem::path _path;
FILE* _file = nullptr;
+ int _open_error = 0;
};