diff options
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qdatastream.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qdebug.cpp | 257 | ||||
-rw-r--r-- | src/corelib/io/qdir.cpp | 47 | ||||
-rw-r--r-- | src/corelib/io/qdiriterator.cpp | 38 | ||||
-rw-r--r-- | src/corelib/io/qfile.cpp | 22 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_inotify.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 13 | ||||
-rw-r--r-- | src/corelib/io/qprocess.cpp | 34 | ||||
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 8 | ||||
-rw-r--r-- | src/corelib/io/qsettings.cpp | 4 | ||||
-rw-r--r-- | src/corelib/io/qsettings_win.cpp | 51 | ||||
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 275 | ||||
-rw-r--r-- | src/corelib/io/qtextstream.cpp | 8 |
15 files changed, 540 insertions, 225 deletions
diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index 9990696..b203899 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -514,7 +514,7 @@ void QDataStream::setByteOrder(ByteOrder bo) \value Qt_4_2 Version 8 (Qt 4.2) \value Qt_4_3 Version 9 (Qt 4.3) \value Qt_4_4 Version 10 (Qt 4.4) - \value Qt_4_5 Version 10 (Qt 4.5) + \value Qt_4_5 Version 11 (Qt 4.5) \omitvalue Qt_4_6 \sa setVersion(), version() diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 0fa31f8..611b19a 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -49,3 +49,260 @@ #include "qdebug.h" // This file is needed to force compilation of QDebug into the kernel library. + +/*! + \class QDebug + \ingroup io + \mainclass + \brief The QDebug class provides an output stream for debugging information. + + QDebug is used whenever the developer needs to write out debugging or tracing + information to a device, file, string or console. + + \section1 Basic Use + + In the common case, it is useful to call the qDebug() function to obtain a + default QDebug object to use for writing debugging information. + + \snippet doc/src/snippets/qdebug/qdebugsnippet.cpp 1 + + This constructs a QDebug object using the constructor that accepts a QtMsgType + value of QtDebugMsg. Similarly, the qWarning(), qCritical() and qFatal() + functions also return QDebug objects for the corresponding message types. + + The class also provides several constructors for other situations, including + a constructor that accepts a QFile or any other QIODevice subclass that is + used to write debugging information to files and other devices. The constructor + that accepts a QString is used to write to a string for display or serialization. + + \section1 Writing Custom Types to a Stream + + Many standard types can be written to QDebug objects, and Qt provides support for + most Qt value types. To add support for custom types, you need to implement a + streaming operator, as in the following example: + + \snippet doc/src/snippets/qdebug/qdebugsnippet.cpp 0 + + This is described in the \l{Debugging Techniques} and + \l{Creating Custom Qt Types#Making the Type Printable}{Creating Custom Qt Types} + documents. +*/ + +/*! + \fn QDebug::QDebug(QIODevice *device) + + Constructs a debug stream that writes to the given \a device. +*/ + +/*! + \fn QDebug::QDebug(QString *string) + + Constructs a debug stream that writes to the given \a string. +*/ + +/*! + \fn QDebug::QDebug(QtMsgType type) + + Constructs a debug stream that writes to the handler for the message type specified by \a type. +*/ + +/*! + \fn QDebug::QDebug(const QDebug &other) + + Constructs a copy of the \a other debug stream. +*/ + +/*! + \fn QDebug &QDebug::operator=(const QDebug &other) + + Assigns the \a other debug stream to this stream and returns a reference to + this stream. +*/ + +/*! + \fn QDebug::~QDebug() + + Flushes any pending data to be written and destroys the debug stream. +*/ + +/*! + \fn QDebug &QDebug::space() + + Writes a space character to the debug stream and returns a reference to + the stream. + + The stream will record that the last character sent to the stream was a + space. + + \sa nospace(), maybeSpace() +*/ + +/*! + \fn QDebug &QDebug::nospace() + + Clears the stream's internal flag that records whether the last character + was a space and returns a reference to the stream. + + \sa space(), maybeSpace() +*/ + +/*! + \fn QDebug &QDebug::maybeSpace() + + Writes a space character to the debug stream, depending on the last + character sent to the stream, and returns a reference to the stream. + + If the last character was a space character, this function writes a space + character to the stream; otherwise, no characters are written to the stream. + + \sa space(), nospace() +*/ + +/*! + \fn QDebug &QDebug::operator<<(QChar t) + + Writes the character, \a t, to the stream and returns a reference to the + stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(QBool t) + \internal + + Writes the boolean value, \a t, to the stream and returns a reference to the + stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(bool t) + + Writes the boolean value, \a t, to the stream and returns a reference to the + stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(char t) + + Writes the character, \a t, to the stream and returns a reference to the + stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(signed short i) + + Writes the signed short integer, \a i, to the stream and returns a reference + to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(unsigned short i) + + Writes then unsigned short integer, \a i, to the stream and returns a + reference to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(signed int i) + + Writes the signed integer, \a i, to the stream and returns a reference + to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(unsigned int i) + + Writes then unsigned integer, \a i, to the stream and returns a reference to + the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(signed long l) + + Writes the signed long integer, \a l, to the stream and returns a reference + to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(unsigned long l) + + Writes then unsigned long integer, \a l, to the stream and returns a reference + to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(qint64 i) + + Writes the signed 64-bit integer, \a i, to the stream and returns a reference + to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(quint64 i) + + Writes then unsigned 64-bit integer, \a i, to the stream and returns a + reference to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(float f) + + Writes the 32-bit floating point number, \a f, to the stream and returns a + reference to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(double f) + + Writes the 64-bit floating point number, \a f, to the stream and returns a + reference to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(const char *s) + + Writes the '\0'-terminated string, \a s, to the stream and returns a + reference to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(const QString &s) + + Writes the string, \a s, to the stream and returns a reference to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(const QStringRef &s) + + Writes the string reference, \a s, to the stream and returns a reference to + the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(const QLatin1String &s) + + Writes the Latin1-encoded string, \a s, to the stream and returns a reference + to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(const QByteArray &b) + + Writes the byte array, \a b, to the stream and returns a reference to the + stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(const void *p) + + Writes a pointer, \a p, to the stream and returns a reference to the stream. +*/ + +/*! + \fn QDebug &QDebug::operator<<(QTextStreamFunction f) + \internal +*/ + +/*! + \fn QDebug &QDebug::operator<<(QTextStreamManipulator m) + \internal +*/ diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 6d75c59..b7861ba 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -50,6 +50,7 @@ #include "qstring.h" #include "qregexp.h" #include "qvector.h" +#include "qalgorithms.h" #ifdef QT_BUILD_CORE_LIB # include "qresource.h" #endif @@ -190,32 +191,28 @@ QDirPrivate::~QDirPrivate() /* For sorting */ struct QDirSortItem { - QString filename_cache; - QString suffix_cache; + mutable QString filename_cache; + mutable QString suffix_cache; QFileInfo item; }; -static int qt_cmp_si_sort_flags; -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif -#ifdef Q_OS_WINCE -static int __cdecl qt_cmp_si(const void *n1, const void *n2) -#else -static int qt_cmp_si(const void *n1, const void *n2) -#endif -{ - if (!n1 || !n2) - return 0; +class QDirSortItemComparator { + int qt_cmp_si_sort_flags; +public: + QDirSortItemComparator(int flags) : qt_cmp_si_sort_flags(flags) {} + bool operator()(const QDirSortItem &, const QDirSortItem &); +}; - QDirSortItem* f1 = (QDirSortItem*)n1; - QDirSortItem* f2 = (QDirSortItem*)n2; +bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortItem &n2) +{ + const QDirSortItem* f1 = &n1; + const QDirSortItem* f2 = &n2; if ((qt_cmp_si_sort_flags & QDir::DirsFirst) && (f1->item.isDir() != f2->item.isDir())) - return f1->item.isDir() ? -1 : 1; + return f1->item.isDir(); if ((qt_cmp_si_sort_flags & QDir::DirsLast) && (f1->item.isDir() != f2->item.isDir())) - return f1->item.isDir() ? 1 : -1; + return !f1->item.isDir(); int r = 0; int sortBy = (qt_cmp_si_sort_flags & QDir::SortByMask) @@ -264,18 +261,11 @@ static int qt_cmp_si(const void *n1, const void *n2) : f1->filename_cache.compare(f2->filename_cache); } - if (r == 0) // Enforce an order - the order the items appear in the array - r = (char*)n1 - (char*)n2; - if (qt_cmp_si_sort_flags & QDir::Reversed) - return -r; - return r; + return r > 0; + return r < 0; } -#if defined(Q_C_CALLBACKS) -} -#endif - inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QStringList &l, QStringList *names, QFileInfoList *infos) const { @@ -292,9 +282,8 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QStringList &l, path += QLatin1Char('/'); si[i].item = QFileInfo(path + l.at(i)); } - qt_cmp_si_sort_flags = sort; if ((sort & QDir::SortByMask) != QDir::Unsorted) - qsort(si, i, sizeof(si[0]), qt_cmp_si); + qStableSort(si, si+i, QDirSortItemComparator(sort)); // put them back in the list(s) for (int j = 0; j<i; j++) { if(infos) diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp index 46c7dd8..b14f436 100644 --- a/src/corelib/io/qdiriterator.cpp +++ b/src/corelib/io/qdiriterator.cpp @@ -116,7 +116,9 @@ public: QAbstractFileEngine *engine; QStack<QAbstractFileEngineIterator *> fileEngineIterators; QString path; - QFileInfo fileInfo; + QFileInfo nextFileInfo; + //This fileinfo is the current that we will return from the public API + QFileInfo currentFileInfo; QString currentFilePath; QDirIterator::IteratorFlags iteratorFlags; QDir::Filters filters; @@ -140,8 +142,8 @@ QDirIteratorPrivate::QDirIteratorPrivate(const QString &path, const QStringList this->filters = filters; this->nameFilters = nameFilters; - fileInfo.setFile(path); - pushSubDirectory(fileInfo.isSymLink() ? fileInfo.canonicalFilePath() : path, + nextFileInfo.setFile(path); + pushSubDirectory(nextFileInfo.isSymLink() ? nextFileInfo.canonicalFilePath() : path, nameFilters, filters); } @@ -160,12 +162,12 @@ void QDirIteratorPrivate::pushSubDirectory(const QString &path, const QStringLis QDir::Filters filters) { if (iteratorFlags & QDirIterator::FollowSymlinks) { - if (fileInfo.filePath() != path) - fileInfo.setFile(path); - if (fileInfo.isSymLink()) { - visitedLinks << fileInfo.canonicalFilePath(); + if (nextFileInfo.filePath() != path) + nextFileInfo.setFile(path); + if (nextFileInfo.isSymLink()) { + visitedLinks << nextFileInfo.canonicalFilePath(); } else { - visitedLinks << fileInfo.absoluteFilePath(); + visitedLinks << nextFileInfo.absoluteFilePath(); } } @@ -199,8 +201,8 @@ void QDirIteratorPrivate::advance() QString subDir = it->currentFilePath(); #ifdef Q_OS_WIN - if (fileInfo.isSymLink()) - subDir = fileInfo.canonicalFilePath(); + if (currentFileInfo.isSymLink()) + subDir = currentFileInfo.canonicalFilePath(); #endif pushSubDirectory(subDir, it->nameFilters(), it->filters()); } @@ -213,15 +215,16 @@ void QDirIteratorPrivate::advance() while (it->hasNext()) { it->next(); if (matchesFilters(it)) { - fileInfo = it->currentFileInfo(); + currentFileInfo = nextFileInfo; + nextFileInfo = it->currentFileInfo(); // Signal that we want to follow this entry. - followNextDir = shouldFollowDirectory(fileInfo); - + followNextDir = shouldFollowDirectory(nextFileInfo); //We found a matching entry. return; } else if (iteratorFlags & QDirIterator::Subdirectories) { QFileInfo fileInfo = it->currentFileInfo(); + if (!shouldFollowDirectory(fileInfo)) continue; QString subDir = it->currentFilePath(); @@ -238,6 +241,7 @@ void QDirIteratorPrivate::advance() if (!foundDirectory) delete fileEngineIterators.pop(); } + currentFileInfo = nextFileInfo; done = true; } @@ -518,9 +522,7 @@ bool QDirIterator::hasNext() const */ QString QDirIterator::fileName() const { - if (d->fileInfo.path() != d->currentFilePath) - d->fileInfo.setFile(d->currentFilePath); - return d->fileInfo.fileName(); + return d->currentFileInfo.fileName(); } /*! @@ -543,9 +545,7 @@ QString QDirIterator::filePath() const */ QFileInfo QDirIterator::fileInfo() const { - if (d->fileInfo.filePath() != d->currentFilePath) - d->fileInfo.setFile(d->currentFilePath); - return d->fileInfo; + return d->currentFileInfo; } /*! diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index d8f08c9..d7da800 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -712,6 +712,9 @@ QFile::rename(const QString &newName) if(error() == QFile::NoError) { if (fileEngine()->rename(newName)) { unsetError(); + // engine was able to handle the new name so we just reset it + fileEngine()->setFileName(newName); + d->fileName = newName; return true; } @@ -731,10 +734,18 @@ QFile::rename(const QString &newName) } if (read == -1) { d->setError(QFile::RenameError, in.errorString()); - return true; + error = true; + } + if(!error) { + if (!in.remove()) { + d->setError(QFile::RenameError, tr("Cannot remove source file")); + error = true; + } } - if(!error) - in.remove(); + if (error) + out.remove(); + else + setFileName(newName); return !error; } } @@ -889,7 +900,10 @@ QFile::copy(const QString &newName) error = true; d->setError(QFile::CopyError, tr("Cannot create %1 for output").arg(newName)); } -#ifndef QT_NO_TEMPORARYFILE +#ifdef QT_NO_TEMPORARYFILE + if (error) + out.remove(); +#else if (!error) out.setAutoRemove(false); #endif diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index a062317..96e0f82 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -145,7 +145,7 @@ void QFileInfoPrivate::initFileEngine(const QString &file) bool QFileInfoPrivate::hasAccess(Access access) const { - if (!(data->fileEngine->fileFlags() & QAbstractFileEngine::LocalDiskFlag)) { + if (!(getFileFlags(QAbstractFileEngine::FileInfoAll) & QAbstractFileEngine::LocalDiskFlag)) { switch (access) { case ReadAccess: return getFileFlags(QAbstractFileEngine::ReadUserPerm); diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index 4445e3c..fa44531 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -316,7 +316,7 @@ void QInotifyFileSystemWatcherEngine::readFromInotify() // qDebug() << "QInotifyFileSystemWatcherEngine::readFromInotify"; int buffSize = 0; - ioctl(inotifyFd, FIONREAD, &buffSize); + ioctl(inotifyFd, FIONREAD, (char *) &buffSize); QVarLengthArray<char, 4096> buffer(buffSize); buffSize = read(inotifyFd, buffer.data(), buffSize); const char *at = buffer.data(); diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 0d88b06..18b92e2 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -780,7 +780,7 @@ QString QFSFileEngine::fileName(FileName file) const #endif if (len > 0) { QString ret; - if (S_ISDIR(d->st.st_mode) && s[0] != '/') { + if (d->doStat() && S_ISDIR(d->st.st_mode) && s[0] != '/') { QDir parent(d->filePath); parent.cdUp(); ret = parent.path(); diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 612f916..63506c2 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -346,8 +346,15 @@ bool QFSFileEnginePrivate::uncListSharesOnServer(const QString &server, QStringL static bool isUncRoot(const QString &server) { QString localPath = QDir::toNativeSeparators(server); - QStringList parts = localPath.split(QLatin1Char('\\'), QString::SkipEmptyParts); - return localPath.startsWith(QLatin1String("\\\\")) && parts.count() <= 1; + if (!localPath.startsWith(QLatin1String("\\\\"))) + return false; + + int idx = localPath.indexOf(QLatin1Char('\\'), 2); + if (idx == -1 || idx + 1 == localPath.length()) + return true; + + localPath = localPath.right(localPath.length() - idx - 1).trimmed(); + return localPath.isEmpty(); } static bool isUncPath(const QString &path) @@ -485,7 +492,7 @@ QString QFSFileEnginePrivate::longFileName(const QString &path) QString absPath = nativeAbsoluteFilePath(path); #if !defined(Q_OS_WINCE) QString prefix = QLatin1String("\\\\?\\"); - if (isUncPath(path)) { + if (isUncPath(absPath)) { prefix = QLatin1String("\\\\?\\UNC\\"); absPath.remove(0, 2); } diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index a9d8ee2..a128482 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1476,11 +1476,15 @@ QByteArray QProcess::readAllStandardError() } /*! - Starts the program \a program in a new process, passing the - command line arguments in \a arguments. The OpenMode is set to \a - mode. QProcess will immediately enter the Starting state. If the - process starts successfully, QProcess will emit started(); - otherwise, error() will be emitted. + Starts the program \a program in a new process, if one is not already + running, passing the command line arguments in \a arguments. The OpenMode + is set to \a mode. + + The QProcess object will immediately enter the Starting state. If the + process starts successfully, QProcess will emit started(); otherwise, + error() will be emitted. If the QProcess object is already running a + process, a warning may be printed at the console, and the existing + process will continue running. Note that arguments that contain spaces are not passed to the process as separate arguments. @@ -1577,10 +1581,10 @@ static QStringList parseCombinedArgString(const QString &program) /*! \overload - Starts the program \a program in a new process. \a program is a - single string of text containing both the program name and its - arguments. The arguments are separated by one or more - spaces. For example: + Starts the program \a program in a new process, if one is not already + running. \a program is a single string of text containing both the + program name and its arguments. The arguments are separated by one or + more spaces. For example: \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 5 @@ -1589,6 +1593,9 @@ static QStringList parseCombinedArgString(const QString &program) \snippet doc/src/snippets/code/src_corelib_io_qprocess.cpp 6 + If the QProcess object is already running a process, a warning may be + printed at the console, and the existing process will continue running. + Note that, on Windows, quotes need to be both escaped and quoted. For example, the above code would be specified in the following way to ensure that \c{"My Documents"} is used as the argument to @@ -1601,6 +1608,13 @@ static QStringList parseCombinedArgString(const QString &program) void QProcess::start(const QString &program, OpenMode mode) { QStringList args = parseCombinedArgString(program); + if (args.isEmpty()) { + Q_D(QProcess); + d->processError = QProcess::FailedToStart; + setErrorString(tr("No program defined")); + emit error(d->processError); + return; + } QString prog = args.first(); args.removeFirst(); @@ -1769,6 +1783,8 @@ bool QProcess::startDetached(const QString &program, bool QProcess::startDetached(const QString &program) { QStringList args = parseCombinedArgString(program); + if (args.isEmpty()) + return false; QString prog = args.first(); args.removeFirst(); diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 37173c8..33d4a47 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -850,10 +850,10 @@ bool QProcessPrivate::processStarted() qint64 QProcessPrivate::bytesAvailableFromStdout() const { - size_t nbytes = 0; + int nbytes = 0; qint64 available = 0; if (::ioctl(stdoutChannel.pipe[0], FIONREAD, (char *) &nbytes) >= 0) - available = (qint64) *((int *) &nbytes); + available = (qint64) nbytes; #if defined (QPROCESS_DEBUG) qDebug("QProcessPrivate::bytesAvailableFromStdout() == %lld", available); #endif @@ -862,10 +862,10 @@ qint64 QProcessPrivate::bytesAvailableFromStdout() const qint64 QProcessPrivate::bytesAvailableFromStderr() const { - size_t nbytes = 0; + int nbytes = 0; qint64 available = 0; if (::ioctl(stderrChannel.pipe[0], FIONREAD, (char *) &nbytes) >= 0) - available = (qint64) *((int *) &nbytes); + available = (qint64) nbytes; #if defined (QPROCESS_DEBUG) qDebug("QProcessPrivate::bytesAvailableFromStderr() == %lld", available); #endif diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 62b4ed5..484e79a 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -2330,6 +2330,10 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, \o \c{HKEY_LOCAL_MACHINE\Software\MySoft} \endlist + \note On Windows, for 32-bit programs running in WOW64 mode, settings are + stored in the following registry path: + \c{HKEY_LOCAL_MACHINE\Software\WOW6432node}. + If the file format is IniFormat, the following files are used on Unix and Mac OS X: diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 67d2eeb..a08c969 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -548,12 +548,13 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa case REG_EXPAND_SZ: case REG_SZ: { QString s; - QT_WA( { - s = QString::fromUtf16(((const ushort*)data.constData())); - }, { - s = QString::fromLocal8Bit(data.constData()); - } ); - + if (dataSize) { + QT_WA( { + s = QString::fromUtf16(((const ushort*)data.constData())); + }, { + s = QString::fromLocal8Bit(data.constData()); + } ); + } if (value != 0) *value = stringToVariant(s); break; @@ -561,19 +562,21 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa case REG_MULTI_SZ: { QStringList l; - int i = 0; - for (;;) { - QString s; - QT_WA( { - s = QString::fromUtf16((const ushort*)data.constData() + i); - }, { - s = QString::fromLocal8Bit(data.constData() + i); - } ); - i += s.length() + 1; + if (dataSize) { + int i = 0; + for (;;) { + QString s; + QT_WA( { + s = QString::fromUtf16((const ushort*)data.constData() + i); + }, { + s = QString::fromLocal8Bit(data.constData() + i); + } ); + i += s.length() + 1; - if (s.isEmpty()) - break; - l.append(s); + if (s.isEmpty()) + break; + l.append(s); + } } if (value != 0) *value = stringListToVariantList(l); @@ -583,11 +586,13 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa case REG_NONE: case REG_BINARY: { QString s; - QT_WA( { - s = QString::fromUtf16((const ushort*)data.constData(), data.size()/2); - }, { - s = QString::fromLocal8Bit(data.constData(), data.size()); - } ); + if (dataSize) { + QT_WA( { + s = QString::fromUtf16((const ushort*)data.constData(), data.size()/2); + }, { + s = QString::fromLocal8Bit(data.constData(), data.size()); + } ); + } if (value != 0) *value = stringToVariant(s); break; diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 3cfce83..6a9125c 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -105,100 +105,100 @@ QT_BEGIN_NAMESPACE */ static int _gettemp(char *path, int *doopen, int domkdir, int slen) { - char *start, *trv, *suffp; - QT_STATBUF sbuf; - int rval; + char *start, *trv, *suffp; + QT_STATBUF sbuf; + int rval; #if defined(Q_OS_WIN) int pid; #else - pid_t pid; + pid_t pid; #endif - if (doopen && domkdir) { - errno = EINVAL; - return(0); - } - - for (trv = path; *trv; ++trv) - ; - trv -= slen; - suffp = trv; - --trv; - if (trv < path) { - errno = EINVAL; - return (0); - } + if (doopen && domkdir) { + errno = EINVAL; + return 0; + } + + for (trv = path; *trv; ++trv) + ; + trv -= slen; + suffp = trv; + --trv; + if (trv < path) { + errno = EINVAL; + return 0; + } #if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400 - pid = _getpid(); + pid = _getpid(); #else - pid = getpid(); + pid = getpid(); #endif - while (trv >= path && *trv == 'X' && pid != 0) { - *trv-- = (pid % 10) + '0'; - pid /= 10; - } + while (trv >= path && *trv == 'X' && pid != 0) { + *trv-- = (pid % 10) + '0'; + pid /= 10; + } #ifndef S_ISDIR -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif - while (trv >= path && *trv == 'X') { - char c; - - // CHANGE arc4random() -> random() - pid = (qrand() & 0xffff) % (26+26); - if (pid < 26) - c = pid + 'A'; - else - c = (pid - 26) + 'a'; - *trv-- = c; - } - start = trv + 1; - - /* - * check the target directory; if you have six X's and it - * doesn't exist this runs for a *very* long time. - */ - if (doopen || domkdir) { - for (;; --trv) { - if (trv <= path) - break; - if (*trv == '/') { - *trv = '\0'; + while (trv >= path && *trv == 'X') { + char c; + + // CHANGE arc4random() -> random() + pid = (qrand() & 0xffff) % (26+26); + if (pid < 26) + c = pid + 'A'; + else + c = (pid - 26) + 'a'; + *trv-- = c; + } + start = trv + 1; + + /* + * check the target directory; if you have six X's and it + * doesn't exist this runs for a *very* long time. + */ + if (doopen || domkdir) { + for (;; --trv) { + if (trv <= path) + break; + if (*trv == '/') { + *trv = '\0'; #if defined (Q_OS_WIN) && !defined(Q_OS_WINCE) - if (trv - path == 2 && path[1] == ':') { - // Special case for Windows drives - // (e.g., "C:" => "C:\"). - // ### Better to use a Windows - // call for this. - char drive[] = "c:\\"; - drive[0] = path[0]; - rval = QT_STAT(drive, &sbuf); - } else + if (trv - path == 2 && path[1] == ':') { + // Special case for Windows drives + // (e.g., "C:" => "C:\"). + // ### Better to use a Windows + // call for this. + char drive[] = "c:\\"; + drive[0] = path[0]; + rval = QT_STAT(drive, &sbuf); + } else #endif - rval = QT_STAT(path, &sbuf); - *trv = '/'; - if (rval != 0) - return(0); - if (!S_ISDIR(sbuf.st_mode)) { - errno = ENOTDIR; - return(0); - } - break; - } - } - } - - for (;;) { - if (doopen) { + rval = QT_STAT(path, &sbuf); + *trv = '/'; + if (rval != 0) + return 0; + if (!S_ISDIR(sbuf.st_mode)) { + errno = ENOTDIR; + return 0; + } + break; + } + } + } + + for (;;) { + if (doopen) { #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && defined(_MSC_VER) && _MSC_VER >= 1400 - if (_sopen_s(doopen, path, QT_OPEN_CREAT|O_EXCL|QT_OPEN_RDWR|QT_OPEN_BINARY -#ifdef QT_LARGEFILE_SUPPORT - |QT_OPEN_LARGEFILE -#endif - , _SH_DENYNO, _S_IREAD | _S_IWRITE)== 0) -#else -#if defined(Q_OS_WINCE) + if (_sopen_s(doopen, path, QT_OPEN_CREAT|O_EXCL|QT_OPEN_RDWR|QT_OPEN_BINARY +# ifdef QT_LARGEFILE_SUPPORT + |QT_OPEN_LARGEFILE +# endif + , _SH_DENYNO, _S_IREAD | _S_IWRITE)== 0) +#else // WIN && !CE +# if defined(Q_OS_WINCE) QString targetPath; if (QDir::isAbsolutePath(QString::fromLatin1(path))) targetPath = QLatin1String(path); @@ -207,72 +207,84 @@ static int _gettemp(char *path, int *doopen, int domkdir, int slen) if ((*doopen = QT_OPEN(targetPath.toLocal8Bit(), O_CREAT|O_EXCL|O_RDWR -#else - if ((*doopen = - open(path, QT_OPEN_CREAT|O_EXCL|QT_OPEN_RDWR -#endif -#ifdef QT_LARGEFILE_SUPPORT - |QT_OPEN_LARGEFILE -#endif +# else // CE + if ((*doopen = + open(path, QT_OPEN_CREAT|O_EXCL|QT_OPEN_RDWR +# endif +# ifdef QT_LARGEFILE_SUPPORT + |QT_OPEN_LARGEFILE +# endif # if defined(Q_OS_WINCE) - |_O_BINARY + |_O_BINARY # elif defined(Q_OS_WIN) - |O_BINARY + |O_BINARY +# endif +# ifdef O_CLOEXEC + // supported on Linux >= 2.6.23; avoids one extra system call + // and avoids a race condition: if another thread forks, we could + // end up leaking a file descriptor... + |O_CLOEXEC # endif - , 0600)) >= 0) + , 0600)) >= 0) +#endif // WIN && !CE + { +#if defined(Q_OS_UNIX) && !defined(O_CLOEXEC) + fcntl(*doopen, F_SETFD, FD_CLOEXEC); #endif - - return(1); - if (errno != EEXIST) - return(0); - } else if (domkdir) { + return 1; + } + if (errno != EEXIST) + return 0; + } else if (domkdir) { #ifdef Q_OS_WIN - if (QT_MKDIR(path) == 0) + if (QT_MKDIR(path) == 0) #else - if (mkdir(path, 0700) == 0) + if (mkdir(path, 0700) == 0) #endif - return(1); - if (errno != EEXIST) - return(0); - } + return 1; + if (errno != EEXIST) + return 0; + } #ifndef Q_OS_WIN - else if (QT_LSTAT(path, &sbuf)) - return(errno == ENOENT ? 1 : 0); + else if (QT_LSTAT(path, &sbuf)) + return (errno == ENOENT) ? 1 : 0; #else - if (!QFileInfo(QLatin1String(path)).exists()) - return 1; + if (!QFileInfo(QLatin1String(path)).exists()) + return 1; #endif - /* tricky little algorwwithm for backward compatibility */ - for (trv = start;;) { - if (!*trv) - return (0); - if (*trv == 'Z') { - if (trv == suffp) - return (0); - *trv++ = 'a'; - } else { - if (isdigit(*trv)) - *trv = 'a'; - else if (*trv == 'z') /* inc from z to A */ - *trv = 'A'; - else { - if (trv == suffp) - return (0); - ++*trv; - } - break; - } + /* tricky little algorwwithm for backward compatibility */ + for (trv = start;;) { + if (!*trv) + return 0; + if (*trv == 'Z') { + if (trv == suffp) + return 0; + *trv++ = 'a'; + } else { + if (isdigit(*trv)) + *trv = 'a'; + else if (*trv == 'z') /* inc from z to A */ + *trv = 'A'; + else { + if (trv == suffp) + return 0; + ++*trv; } + break; + } } - /*NOTREACHED*/ + } + /*NOTREACHED*/ } +#ifndef Q_WS_WIN static int qt_mkstemps(char *path, int slen) { - int fd = 0; - return (_gettemp(path, &fd, 0, slen) ? fd : -1); + int fd = 0; + return (_gettemp(path, &fd, 0, slen) ? fd : -1); } +#endif //************* QTemporaryFileEngine class QTemporaryFileEngine : public QFSFileEngine @@ -282,6 +294,8 @@ public: QTemporaryFileEngine(const QString &file) : QFSFileEngine(file) { } ~QTemporaryFileEngine(); + void setFileName(const QString &file); + bool open(QIODevice::OpenMode flags); bool remove(); bool close(); @@ -292,6 +306,13 @@ QTemporaryFileEngine::~QTemporaryFileEngine() QFSFileEngine::close(); } +void QTemporaryFileEngine::setFileName(const QString &file) +{ + // Really close the file, so we don't leak + QFSFileEngine::close(); + QFSFileEngine::setFileName(file); +} + bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) { Q_D(QFSFileEngine); diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp index 5227d4f..1167671 100644 --- a/src/corelib/io/qtextstream.cpp +++ b/src/corelib/io/qtextstream.cpp @@ -67,8 +67,10 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384; \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 1 Note that you cannot use QTextStream::atEnd(), which returns true when you - have reached the end of the data stream, with stdin. - + have reached the end of the data stream, with stdin. The reason for this is + that as long as stdin doesn't give any input to the QTextStream, \c atEnd() + will return true even if the stdin is open and waiting for more characters. + Besides using QTextStream's constructors, you can also set the device or string QTextStream operates on by calling setDevice() or setString(). You can seek to a position by calling seek(), and @@ -1370,7 +1372,7 @@ QTextStream::FieldAlignment QTextStream::fieldAlignment() const \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 5 - Output: + The string \c s contains: \snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 6 |