diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-12-23 20:14:59 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-12-23 20:14:59 +0100 |
| commit | a19fe8260a4e1f4cb9d523f5b2cb41eae0a61acd (patch) | |
| tree | 75c53f48321131706c171213a4a873255f20dc53 /src | |
| parent | d512af5646b85289293858fc98dd7e1f2864fb7d (diff) | |
Add File::open_error().
Diffstat (limited to 'src')
| -rw-r--r-- | src/file.cc | 9 | ||||
| -rw-r--r-- | src/file.h | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/file.cc b/src/file.cc index b79051a3..e13954bd 100644 --- a/src/file.cc +++ b/src/file.cc @@ -51,11 +51,18 @@ File::File(boost::filesystem::path path, std::string mode) : _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 } @@ -63,6 +70,7 @@ File::File(boost::filesystem::path path, std::string mode) File::File(File&& other) : _path(other._path) , _file(other._file) + , _open_error(other._open_error) { other._file = nullptr; } @@ -74,6 +82,7 @@ File::operator=(File&& other) if (*this != other) { close(); _file = other._file; + _open_error = other._open_error; other._file = nullptr; } return *this; @@ -101,9 +101,17 @@ public: 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; }; |
