summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-10-23 11:44:23 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-10-23 13:06:37 (GMT)
commitf808fe435dc00398775fe8040d3c811aed6332a9 (patch)
tree1d4dfcea0af1f422952407ae5221d88d4573ecca /src/corelib/io
parentb402b8c4216ebb2d7db1e7e6cd33a45d1af422e9 (diff)
downloadQt-f808fe435dc00398775fe8040d3c811aed6332a9.zip
Qt-f808fe435dc00398775fe8040d3c811aed6332a9.tar.gz
Qt-f808fe435dc00398775fe8040d3c811aed6332a9.tar.bz2
Fix QFile::isSequential on Windows
When not using native HANDLEs, the return of isSequential was hardcoded to true for files with a fd, and for the standard FILE* streams stdin, stdout and stderr; false for all other FILE* streams. We now use the native GetFileType call for all files by obtaining a native handle where required. We also treat files of type FILE_TYPE_CHAR as sequential, as is the case for the standard streams in console applications. When standard streams are redirected to/from files, GetFileType will return FILE_TYPE_DISK for them and they won't be considered sequential. This is alright since in this mode they behave like regular files and QFile::seek() will work for random offsets. Reviewed-by: Marius Storm-Olsen
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp29
1 files changed, 10 insertions, 19 deletions
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index b8a16fa..9fc4500 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -789,27 +789,18 @@ int QFSFileEnginePrivate::nativeHandle() const
bool QFSFileEnginePrivate::nativeIsSequential() const
{
#if !defined(Q_OS_WINCE)
- // stdlib / Windows native mode.
- if (fh || fileHandle != INVALID_HANDLE_VALUE) {
- if (fh == stdin || fh == stdout || fh == stderr)
- return true;
-
- HANDLE handle = fileHandle;
- if (fileHandle == INVALID_HANDLE_VALUE) {
- // Rare case: using QFile::open(FILE*) to open a pipe.
- handle = (HANDLE)_get_osfhandle(QT_FILENO(fh));
- return false;
- }
-
- DWORD fileType = GetFileType(handle);
- return fileType == FILE_TYPE_PIPE;
- }
+ HANDLE handle = fileHandle;
+ if (fh || fd != -1)
+ handle = (HANDLE)_get_osfhandle(fh ? QT_FILENO(fh) : fd);
+ if (handle == INVALID_HANDLE_VALUE)
+ return false;
- // stdio mode.
- if (fd != -1)
- return isSequentialFdFh();
-#endif
+ DWORD fileType = GetFileType(handle);
+ return (fileType == FILE_TYPE_CHAR)
+ || (fileType == FILE_TYPE_PIPE);
+#else
return false;
+#endif
}
bool QFSFileEngine::remove()