summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfsfileengine_win.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-06 22:55:48 +0100
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-06 22:55:48 +0100
commit360a51d64c607f5efae7a4f25a9a519424399b69 (patch)
tree874eb46ab469865ce9d9b58b9d1cf86d49e5bd1c /src/corelib/io/qfsfileengine_win.cpp
parent7359baee83f6691c31a0a14ffd6f6cc147ed71fd (diff)
parent2b91557c93354b766c78cbc4ab48bcd58207bf1a (diff)
Merge remote branch 'mainline/4.6' into 4.6
Diffstat (limited to 'src/corelib/io/qfsfileengine_win.cpp')
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp153
1 files changed, 64 insertions, 89 deletions
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index 898447cc2e..a6cb5a9f7a 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -455,17 +455,10 @@ bool QFSFileEnginePrivate::nativeClose()
// Windows native mode.
bool ok = true;
- if ((fileHandle == INVALID_HANDLE_VALUE || !CloseHandle(fileHandle))
-#ifdef Q_USE_DEPRECATED_MAP_API
- && (fileMapHandle == INVALID_HANDLE_VALUE || !CloseHandle(fileMapHandle))
-#endif
- ) {
+ if ((fileHandle == INVALID_HANDLE_VALUE || !::CloseHandle(fileHandle))) {
q->setError(QFile::UnspecifiedError, qt_error_string());
ok = false;
}
-#ifdef Q_USE_DEPRECATED_MAP_API
- fileMapHandle = INVALID_HANDLE_VALUE;
-#endif
fileHandle = INVALID_HANDLE_VALUE;
cachedFd = -1; // gets closed by CloseHandle above
@@ -504,14 +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) {
QT_OFF_T oldPos = QT_FTELL(fh);
QT_FSEEK(fh, 0, SEEK_END);
- QT_OFF_T fileSize = QT_FTELL(fh);
+ qint64 fileSize = (qint64)QT_FTELL(fh);
QT_FSEEK(fh, oldPos, SEEK_SET);
- return qint64(fileSize);
+ 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.
@@ -551,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)
@@ -799,27 +798,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()
@@ -1931,42 +1921,42 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size,
return 0;
}
+ if (mapHandle == INVALID_HANDLE_VALUE) {
+ // get handle to the file
+ HANDLE handle = fileHandle;
- // get handle to the file
- HANDLE handle = fileHandle;
#ifndef Q_OS_WINCE
- if (handle == INVALID_HANDLE_VALUE && fh)
- handle = (HANDLE)_get_osfhandle(QT_FILENO(fh));
+ if (handle == INVALID_HANDLE_VALUE && fh)
+ handle = (HANDLE)::_get_osfhandle(QT_FILENO(fh));
#endif
#ifdef Q_USE_DEPRECATED_MAP_API
- if (fileMapHandle == INVALID_HANDLE_VALUE) {
nativeClose();
- fileMapHandle = CreateFileForMapping((const wchar_t*)nativeFilePath.constData(),
+ // handle automatically closed by kernel with mapHandle (below).
+ handle = ::CreateFileForMapping((const wchar_t*)nativeFilePath.constData(),
GENERIC_READ | (openMode & QIODevice::WriteOnly ? GENERIC_WRITE : 0),
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
- }
- handle = fileMapHandle;
#endif
- if (handle == INVALID_HANDLE_VALUE) {
- q->setError(QFile::PermissionsError, qt_error_string(ERROR_ACCESS_DENIED));
- return 0;
- }
+ if (handle == INVALID_HANDLE_VALUE) {
+ q->setError(QFile::PermissionsError, qt_error_string(ERROR_ACCESS_DENIED));
+ return 0;
+ }
- // first create the file mapping handle
- DWORD protection = (openMode & QIODevice::WriteOnly) ? PAGE_READWRITE : PAGE_READONLY;
- HANDLE mapHandle = ::CreateFileMapping(handle, 0, protection, 0, 0, 0);
- if (mapHandle == NULL) {
- q->setError(QFile::PermissionsError, qt_error_string());
+ // first create the file mapping handle
+ DWORD protection = (openMode & QIODevice::WriteOnly) ? PAGE_READWRITE : PAGE_READONLY;
+ mapHandle = ::CreateFileMapping(handle, 0, protection, 0, 0, 0);
+ if (mapHandle == INVALID_HANDLE_VALUE) {
+ q->setError(QFile::PermissionsError, qt_error_string());
#ifdef Q_USE_DEPRECATED_MAP_API
- mapHandleClose();
+ ::CloseHandle(handle);
#endif
- return 0;
+ return 0;
+ }
}
// setup args to map
@@ -1978,17 +1968,17 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size,
DWORD offsetLo = offset & Q_UINT64_C(0xffffffff);
SYSTEM_INFO sysinfo;
::GetSystemInfo(&sysinfo);
- int mask = sysinfo.dwAllocationGranularity - 1;
- int extra = offset & mask;
+ DWORD mask = sysinfo.dwAllocationGranularity - 1;
+ DWORD extra = offset & mask;
if (extra)
offsetLo &= ~mask;
// attempt to create the map
- LPVOID mapAddress = MapViewOfFile(mapHandle, access,
+ LPVOID mapAddress = ::MapViewOfFile(mapHandle, access,
offsetHi, offsetLo, size + extra);
if (mapAddress) {
uchar *address = extra + static_cast<uchar*>(mapAddress);
- maps[address] = QPair<int, HANDLE>(extra, mapHandle);
+ maps[address] = extra;
return address;
}
@@ -2001,10 +1991,8 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size,
default:
q->setError(QFile::UnspecifiedError, qt_error_string());
}
- CloseHandle(mapHandle);
-#ifdef Q_USE_DEPRECATED_MAP_API
- mapHandleClose();
-#endif
+
+ ::CloseHandle(mapHandle);
return 0;
}
@@ -2015,32 +2003,19 @@ bool QFSFileEnginePrivate::unmap(uchar *ptr)
q->setError(QFile::PermissionsError, qt_error_string(ERROR_ACCESS_DENIED));
return false;
}
- uchar *start = ptr - maps[ptr].first;
+ uchar *start = ptr - maps[ptr];
if (!UnmapViewOfFile(start)) {
q->setError(QFile::PermissionsError, qt_error_string());
return false;
}
- if (!CloseHandle((HANDLE)maps[ptr].second)) {
- q->setError(QFile::UnspecifiedError, qt_error_string());
- return false;
- }
maps.remove(ptr);
-
-#ifdef Q_USE_DEPRECATED_MAP_API
- mapHandleClose();
-#endif
- return true;
-}
-
-#ifdef Q_USE_DEPRECATED_MAP_API
-void QFSFileEnginePrivate::mapHandleClose()
-{
if (maps.isEmpty()) {
- CloseHandle(fileMapHandle);
- fileMapHandle = INVALID_HANDLE_VALUE;
+ ::CloseHandle(mapHandle);
+ mapHandle = INVALID_HANDLE_VALUE;
}
+
+ return true;
}
-#endif
QT_END_NAMESPACE