summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-11-04 20:28:55 +0100
committerJoão Abecasis <joao@abecasis.name>2009-11-04 21:40:28 +0100
commit6b448660f0d967d2749a520b49aa6946e46bff6b (patch)
tree61920fcb63b40f8f4ada3f80e6b4dbb558f2ad5e
parent764d195bfa252775702bffc93989a35d0c19f035 (diff)
Further fixes to file size handling on Windows with fd and FILE*
filelength is not available on Windows CE instead, we must fallback to fseek/ftell as was being done previously. Still on Windows CE, we still don't report the file size for file descriptors, but we also won't set a random error string. Changed qt_error_string calls to use errno when errors come from CRT functions. Also, if we're using filelength on FILE* streams, there's no reason not to use it for file descriptors, instead of requesting a native handle. Reviewed-by: Olivier Goffart
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index 9fc4500bb0..a6cb5a9f7a 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -497,11 +497,30 @@ qint64 QFSFileEnginePrivate::nativeSize() const
// ### Don't flush; for buffered files, we should get away with ftell.
thatQ->flush();
+#if !defined(Q_OS_WINCE)
+ // stdlib/stdio mode.
+ if (fh || fd != -1) {
+ qint64 fileSize = _filelengthi64(fh ? QT_FILENO(fh) : fd);
+ if (fileSize == -1) {
+ fileSize = 0;
+ thatQ->setError(QFile::UnspecifiedError, qt_error_string(errno));
+ }
+ return fileSize;
+ }
+#else // Q_OS_WINCE
// Buffered stdlib mode.
if (fh) {
- qint64 fileSize = _filelengthi64(QT_FILENO(fh));
- return (fileSize == -1) ? 0 : fileSize;
+ QT_OFF_T oldPos = QT_FTELL(fh);
+ QT_FSEEK(fh, 0, SEEK_END);
+ qint64 fileSize = (qint64)QT_FTELL(fh);
+ QT_FSEEK(fh, oldPos, SEEK_SET);
+ if (fileSize == -1) {
+ fileSize = 0;
+ thatQ->setError(QFile::UnspecifiedError, qt_error_string(errno));
+ }
+ return fileSize;
}
+#endif
// Not-open mode, where the file name is known: We'll check the
// file system directly.
@@ -541,23 +560,13 @@ qint64 QFSFileEnginePrivate::nativeSize() const
return 0;
}
- // Unbuffed stdio mode.
- if(fd != -1) {
-#if !defined(Q_OS_WINCE)
- HANDLE handle = (HANDLE)_get_osfhandle(fd);
- if (handle != INVALID_HANDLE_VALUE) {
- BY_HANDLE_FILE_INFORMATION fileInfo;
- if (GetFileInformationByHandle(handle, &fileInfo)) {
- qint64 size = fileInfo.nFileSizeHigh;
- size <<= 32;
- size += fileInfo.nFileSizeLow;
- return size;
- }
- }
-#endif
- thatQ->setError(QFile::UnspecifiedError, qt_error_string());
+#if defined(Q_OS_WINCE)
+ // Unbuffed stdio mode
+ if (fd != -1) {
+ thatQ->setError(QFile::UnspecifiedError, QLatin1String("Not implemented!"));
return 0;
}
+#endif
// Windows native mode.
if (fileHandle == INVALID_HANDLE_VALUE)