summaryrefslogtreecommitdiff
path: root/src/corelib/io/qtemporaryfile.cpp
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-05-18 13:01:52 +0200
committerJoão Abecasis <joao@abecasis.name>2009-05-22 14:33:44 +0200
commit5cb1ed45ba55dbc9752e0f6f47cc6d1525464646 (patch)
treedd0445b74fd26b466fda8d259874362f3e029552 /src/corelib/io/qtemporaryfile.cpp
parent70f616238e77d866420f2c6e12afe04b529fe808 (diff)
downloadqt4-tools-5cb1ed45ba55dbc9752e0f6f47cc6d1525464646.tar.gz
QTemporaryFile: handle failures from QFSFileEngine::open(mode, fd)
For now, this only happens if Append mode is requested and we're unable to seek to the end of the file. Theoretically, this could change in the future so it's better to err on the safe side. Reviewed-by: Thiago
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index e83d7e90fb..b6eff94d77 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -322,7 +322,6 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
qfilename += QLatin1String(".XXXXXX");
int suffixLength = qfilename.length() - (qfilename.lastIndexOf(QLatin1String("XXXXXX"), -1, Qt::CaseSensitive) + 6);
- d->closeFileHandle = true;
char *filename = qstrdup(qfilename.toLocal8Bit());
#ifndef Q_WS_WIN
@@ -330,16 +329,19 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
if (fd != -1) {
// First open the fd as an external file descriptor to
// initialize the engine properly.
- QFSFileEngine::open(openMode, fd);
+ if (QFSFileEngine::open(openMode, fd)) {
- // Allow the engine to close the handle even if it's "external".
- d->closeFileHandle = true;
+ // Allow the engine to close the handle even if it's "external".
+ d->closeFileHandle = true;
- // Restore the file names (open() resets them).
- d->filePath = QString::fromLocal8Bit(filename); //changed now!
- d->nativeInitFileName();
- delete [] filename;
- return true;
+ // Restore the file names (open() resets them).
+ d->filePath = QString::fromLocal8Bit(filename); //changed now!
+ d->nativeInitFileName();
+ delete [] filename;
+ return true;
+ }
+
+ QT_CLOSE(fd);
}
delete [] filename;
setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));