From 291437eed640673c37c7db61bc29b9f6e2bea838 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 20 May 2014 06:58:08 -0700 Subject: [PATCH] Handle ftruncate failures --- libaegisub/common/file_mapping.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libaegisub/common/file_mapping.cpp b/libaegisub/common/file_mapping.cpp index 1ef81203f..eec8e38ca 100644 --- a/libaegisub/common/file_mapping.cpp +++ b/libaegisub/common/file_mapping.cpp @@ -147,8 +147,16 @@ temp_file_mapping::temp_file_mapping(fs::path const& filename, uint64_t size) SetFilePointerEx(handle, li, nullptr, FILE_BEGIN); SetEndOfFile(handle); #else - ftruncate(handle, size); unlink(filename.string().c_str()); + if (ftruncate(handle, size) == -1) { + switch (errno) { + case EBADF: throw InternalError("Error opening file " + filename.string() + " not handled", nullptr); + case EFBIG: throw fs::DriveFull(filename); + case EINVAL: throw InternalError("File opened incorrectly: " + filename.string(), nullptr); + case EROFS: throw fs::WriteDenied(filename); + default: throw fs::FileSystemUnknownError("Unknown error opening file: " + filename.string()); + } + } #endif }