diff options
author | João Abecasis <joao@abecasis.name> | 2009-11-04 19:28:55 (GMT) |
---|---|---|
committer | João Abecasis <joao@abecasis.name> | 2009-11-04 20:40:28 (GMT) |
commit | 6b448660f0d967d2749a520b49aa6946e46bff6b (patch) | |
tree | 61920fcb63b40f8f4ada3f80e6b4dbb558f2ad5e /src/corelib/io | |
parent | 764d195bfa252775702bffc93989a35d0c19f035 (diff) | |
download | Qt-6b448660f0d967d2749a520b49aa6946e46bff6b.zip Qt-6b448660f0d967d2749a520b49aa6946e46bff6b.tar.gz Qt-6b448660f0d967d2749a520b49aa6946e46bff6b.tar.bz2 |
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
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 9fc4500..a6cb5a9 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) |