summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfsfileengine.cpp
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2010-12-01 16:38:59 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2010-12-20 11:52:34 (GMT)
commitb98e374e94e81b66be0dc009356a729e9b97dce8 (patch)
treecacfd6737f8a0434d02f6a81e7e9ebe6e692fc99 /src/corelib/io/qfsfileengine.cpp
parent64e1f888586f2c988b08bcc93579990e970b7206 (diff)
downloadQt-b98e374e94e81b66be0dc009356a729e9b97dce8.zip
Qt-b98e374e94e81b66be0dc009356a729e9b97dce8.tar.gz
Qt-b98e374e94e81b66be0dc009356a729e9b97dce8.tar.bz2
QFile API: add API to specify if adopted file handles should be closed
QFile behaviour has been to not close file handles adopted by open(FILE*, OpenMode) and open(int fd, OpenMode) functions. This is inconvenient for frameworks which want to return an opened QFile to the user. In this case it would be better to transfer ownership of the handle to the QFile. New overloads are added which take an additional parameter from the QFile::FileHandleFlags flags. Currently only one bit is used to provide the AutoCloseHandle option, but it is extensible. The AutoCloseHandle option tells the QFile backend that it should close the handle when close() is called, rather than the default behaviour which remains to flush the handle and leave it open. The DontCloseHandle option is the inverse of this, specifying the old behaviour of flushing but not closing the file handle. Symbian OS file handles are not compatible with int, they are an opaque data type which contains two integers. The first identifies to the kernel the file server session The second identifies to the file server the subsession object (the file) The reason for this is that it has a microkernel architecture, the kernel has no support for files - all files and file systems are handled by a user mode process called the "file server". So for symbian, a new QFile::open() overload is added for adopting a symbian RFile handle. The API mirrors the existing API for POSIX file handles, but takes an RFile reference rather than an integer file descriptor. Task-number: QT-2924 Reviewed-by: joao Reviewed-by: mread Reviewed-by: Oswald Buddenhagen
Diffstat (limited to 'src/corelib/io/qfsfileengine.cpp')
-rw-r--r--src/corelib/io/qfsfileengine.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index ae301f7..f1d3db5 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -230,6 +230,11 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode)
*/
bool QFSFileEngine::open(QIODevice::OpenMode openMode, FILE *fh)
{
+ return open(openMode, fh, QFile::DontCloseHandle);
+}
+
+bool QFSFileEngine::open(QIODevice::OpenMode openMode, FILE *fh, QFile::FileHandleFlags handleFlags)
+{
Q_D(QFSFileEngine);
// Append implies WriteOnly.
@@ -242,7 +247,7 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode, FILE *fh)
d->openMode = openMode;
d->lastFlushFailed = false;
- d->closeFileHandle = false;
+ d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle);
d->fileEntry.clear();
d->tried_stat = 0;
d->fd = -1;
@@ -286,6 +291,11 @@ bool QFSFileEnginePrivate::openFh(QIODevice::OpenMode openMode, FILE *fh)
*/
bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd)
{
+ return open(openMode, fd, QFile::DontCloseHandle);
+}
+
+bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd, QFile::FileHandleFlags handleFlags)
+{
Q_D(QFSFileEngine);
// Append implies WriteOnly.
@@ -298,7 +308,7 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd)
d->openMode = openMode;
d->lastFlushFailed = false;
- d->closeFileHandle = false;
+ d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle);
d->fileEntry.clear();
d->fh = 0;
d->fd = -1;