From 395743eb49493a97d99c7c9d59be402c9c1285fd Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 28 Apr 2013 09:14:37 +0900 Subject: [PATCH] Add some error handling to tfilestream.cpp --- taglib/toolkit/tfilestream.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index a8de32aa..2ce5ab41 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -426,6 +426,9 @@ void FileStream::seek(long offset, Position p) } SetFilePointer(d->file, offset, NULL, whence); + if(GetLastError() != NO_ERROR) { + debug("File::seek() -- Failed to set the file size."); + } #else @@ -467,7 +470,14 @@ long FileStream::tell() const { #ifdef _WIN32 - return (long)SetFilePointer(d->file, 0, NULL, FILE_CURRENT); + const DWORD position = SetFilePointer(d->file, 0, NULL, FILE_CURRENT); + if(GetLastError() == NO_ERROR) { + return static_cast(position); + } + else { + debug("File::tell() -- Failed to get the file pointer."); + return 0; + } #else @@ -491,7 +501,7 @@ long FileStream::length() #ifdef _WIN32 const DWORD fileSize = GetFileSize(d->file, NULL); - if(GetLastError() != ERROR_SUCCESS) { + if(GetLastError() == NO_ERROR) { d->size = static_cast(fileSize); return d->size; } @@ -528,6 +538,9 @@ void FileStream::truncate(long length) seek(length); SetEndOfFile(d->file); + if(GetLastError() != NO_ERROR) { + debug("File::truncate() -- Failed to truncate the file."); + } seek(currentPos);