]> granicus.if.org Git - taglib/commitdiff
Assume that SetFilePointerEx() and GetFileSizeEx() are always available.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Sun, 30 Oct 2016 13:36:18 +0000 (22:36 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sun, 30 Oct 2016 13:36:18 +0000 (22:36 +0900)
This drops support for Windows 9x and NT 4.0 or older.

taglib/toolkit/tfilestream.cpp

index 507e87849aeeee74149a08b56f23b104ad2b47ee..478f09a0bd1ca63cc76a24588a13b8a13dbf5a96 100644 (file)
@@ -362,12 +362,12 @@ void FileStream::seek(long offset, Position p)
     return;
   }
 
-  SetLastError(NO_ERROR);
-  SetFilePointer(d->file, offset, NULL, whence);
+  LARGE_INTEGER liOffset;
+  liOffset.QuadPart = offset;
 
-  const int lastError = GetLastError();
-  if(lastError != NO_ERROR && lastError != ERROR_NEGATIVE_SEEK)
+  if(!SetFilePointerEx(d->file, liOffset, NULL, whence)) {
     debug("FileStream::seek() -- Failed to set the file pointer.");
+  }
 
 #else
 
@@ -409,10 +409,11 @@ long FileStream::tell() const
 {
 #ifdef _WIN32
 
-  SetLastError(NO_ERROR);
-  const DWORD position = SetFilePointer(d->file, 0, NULL, FILE_CURRENT);
-  if(GetLastError() == NO_ERROR) {
-    return static_cast<long>(position);
+  const LARGE_INTEGER zero = {};
+  LARGE_INTEGER position;
+
+  if(SetFilePointerEx(d->file, zero, &position, FILE_CURRENT) && position.QuadPart <= LONG_MAX) {
+    return static_cast<long>(position.QuadPart);
   }
   else {
     debug("FileStream::tell() -- Failed to get the file pointer.");
@@ -435,15 +436,9 @@ long FileStream::length()
 
 #ifdef _WIN32
 
-  SetLastError(NO_ERROR);
-#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)
   LARGE_INTEGER fileSize;
-  GetFileSizeEx(d->file, &fileSize);
-#else
-  ULARGE_INTEGER fileSize;
-  fileSize.LowPart = GetFileSize(d->file, &fileSize.HighPart);
-#endif
-  if(GetLastError() == NO_ERROR && fileSize.QuadPart <= LONG_MAX) {
+
+  if(GetFileSizeEx(d->file, &fileSize) && fileSize.QuadPart <= LONG_MAX) {
     return static_cast<long>(fileSize.QuadPart);
   }
   else {
@@ -477,9 +472,7 @@ void FileStream::truncate(long length)
 
   seek(length);
 
-  SetLastError(NO_ERROR);
-  SetEndOfFile(d->file);
-  if(GetLastError() != NO_ERROR) {
+  if(!SetEndOfFile(d->file)) {
     debug("FileStream::truncate() -- Failed to truncate the file.");
   }