diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2010-10-08 15:23:55 (GMT) |
---|---|---|
committer | Shane Kearns <shane.kearns@accenture.com> | 2010-10-12 12:56:22 (GMT) |
commit | 8ee99ee22729b4d9603fe83929116259956b81ce (patch) | |
tree | 4afec3539ce1eba54daf25875225c88e2cf2b94c /src | |
parent | bb66cbc4287d17a3f368d3e46e98ca026a5332c7 (diff) | |
download | Qt-8ee99ee22729b4d9603fe83929116259956b81ce.zip Qt-8ee99ee22729b4d9603fe83929116259956b81ce.tar.gz Qt-8ee99ee22729b4d9603fe83929116259956b81ce.tar.bz2 |
Use QSystemError to return errors from QFileSystemEngine
Testing done:
win32-msvc2008 and Mac OS X - qfile, qfileinfo, qdir, qdiriterator,
qtemporaryfile autotests
symbian-sbsv2 - qtcore, qtgui, qtxml autotests
win32-g++ - compilation test for qmake
Reviewed-By: Thomas Zander
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qfilesystemengine_p.h | 14 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_symbian.cpp | 83 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 20 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_win.cpp | 22 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_p.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 40 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 16 | ||||
-rw-r--r-- | src/corelib/kernel/qsystemerror.cpp | 40 | ||||
-rw-r--r-- | src/tools/bootstrap/bootstrap.pro | 3 |
9 files changed, 104 insertions, 138 deletions
diff --git a/src/corelib/io/qfilesystemengine_p.h b/src/corelib/io/qfilesystemengine_p.h index f4d942a..1f4aad0 100644 --- a/src/corelib/io/qfilesystemengine_p.h +++ b/src/corelib/io/qfilesystemengine_p.h @@ -56,6 +56,7 @@ #include "qfile.h" #include "qfilesystementry_p.h" #include "qfilesystemmetadata_p.h" +#include <QtCore/private/qsystemerror_p.h> QT_BEGIN_NAMESPACE @@ -91,9 +92,6 @@ public: static QString owner(const QFileSystemEntry &entry, QAbstractFileEngine::FileOwner own); static QString nativeAbsoluteFilePath(const QString &path); #endif -#ifdef Q_OS_SYMBIAN - static QString errorString(int errorcode); -#endif //homePath, rootPath and tempPath shall return clean paths static QString homePath(); static QString rootPath(); @@ -102,13 +100,13 @@ public: static bool createDirectory(const QFileSystemEntry &entry, bool createParents); static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents); - static bool createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString); + static bool createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error); - static bool copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString); - static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString); - static bool removeFile(const QFileSystemEntry &entry, QString &errorString); + static bool copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error); + static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error); + static bool removeFile(const QFileSystemEntry &entry, QSystemError &error); - static bool setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QString &errorString, + static bool setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data = 0); static bool setCurrentPath(const QFileSystemEntry &entry); diff --git a/src/corelib/io/qfilesystemengine_symbian.cpp b/src/corelib/io/qfilesystemengine_symbian.cpp index 318a5fd..877ea7a 100644 --- a/src/corelib/io/qfilesystemengine_symbian.cpp +++ b/src/corelib/io/qfilesystemengine_symbian.cpp @@ -88,7 +88,8 @@ static QString symbianCleanAbsolutePath(const QString& path) //static QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data) { - return link; // TODO implement + Q_UNUSED(data); + return link; } //static @@ -283,16 +284,16 @@ bool QFileSystemEngine::removeDirectory(const QFileSystemEntry &entry, bool remo } //static -bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) +bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { Q_UNUSED(source) Q_UNUSED(target) - errorString = QLatin1String("not supported"); + error = QSystemError(KErrNotSupported, QSystemError::NativeError); return false; } //static -bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) +bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { //CFileMan is allocated each time because it is not thread-safe CFileMan *fm = 0; @@ -302,12 +303,12 @@ bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSyst delete fm; return true; } - errorString = QFileSystemEngine::errorString(err); + error = QSystemError(err, QSystemError::NativeError); return false; } //static -bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) +bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { QString sourcepath = absoluteName(source).nativeFilePath(); QString targetpath = absoluteName(target).nativeFilePath(); @@ -315,24 +316,24 @@ bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSy TInt err = fs.Rename(qt_QString2TPtrC(sourcepath), qt_QString2TPtrC(targetpath)); if (err == KErrNone) return true; - errorString = QFileSystemEngine::errorString(err); + error = QSystemError(err, QSystemError::NativeError); return false; } //static -bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QString &errorString) +bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QSystemError &error) { QString targetpath = absoluteName(entry).nativeFilePath(); RFs& fs(qt_s60GetRFs()); TInt err = fs.Delete(qt_QString2TPtrC(targetpath)); if (err == KErrNone) return true; - errorString = QFileSystemEngine::errorString(err); + error = QSystemError(err, QSystemError::NativeError); return false; } //static -bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QString &errorString, QFileSystemMetaData *data) +bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data) { QString targetpath = absoluteName(entry).nativeFilePath(); TUint setmask = 0; @@ -350,7 +351,7 @@ bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Per } if (err == KErrNone) return true; - errorString = QFileSystemEngine::errorString(err); + error = QSystemError(err, QSystemError::NativeError); return false; } @@ -416,64 +417,4 @@ QFileSystemEntry QFileSystemEngine::currentPath() return ret; } -QString QFileSystemEngine::errorString(int errorcode) -{ - switch (errorcode) { - case KErrNotFound: - return QLatin1String("not found"); - case KErrCancel: - return QLatin1String("cancelled"); - case KErrNoMemory: - return QLatin1String("out of memory"); - case KErrNotSupported: - return QLatin1String("not supported"); - case KErrBadHandle: - return QLatin1String("bad handle"); //KERN-EXEC 0 panic is more likely - case KErrAlreadyExists: - return QLatin1String("already exists"); - case KErrPathNotFound: - return QLatin1String("path not found"); - case KErrInUse: - return QLatin1String("in use"); - case KErrNotReady: - return QLatin1String("not ready (e.g. FS dismounted, no memory card)"); - case KErrCorrupt: - return QLatin1String("corrupt"); - case KErrAccessDenied: - return QLatin1String("access denied"); - case KErrLocked: - return QLatin1String("locked"); - case KErrWrite: - return QLatin1String("incomplete write error"); - case KErrDisMounted: - return QLatin1String("file system dismounted during operation"); //i.e. a forcible dismount was done while we had files open - case KErrEof: - return QLatin1String("end of file"); - case KErrDiskFull: - return QLatin1String("no space in file system"); - case KErrBadName: - return QLatin1String("invalid filename"); - case KErrTimedOut: - return QLatin1String("timed out"); - case KErrBadDescriptor: - return QLatin1String("bad descriptor (passed address on stack to async call?)"); - case KErrAbort: - return QLatin1String("aborted"); - case KErrTooBig: - return QLatin1String("too big"); //e.g. trying to open a >2GB file with 32 bit API - case KErrBadPower: - return QLatin1String("insufficient power"); - case KErrDirFull: - return QLatin1String("no space in directory table"); - case KErrHardwareNotAvailable: - return QLatin1String("hardware not available"); - case KErrSessionClosed: - return QLatin1String("session closed"); - case KErrPermissionDenied: - return QLatin1String("permission denied"); - default: - return QString(QLatin1String("symbian error %d")).arg(errorcode); - } -} - QT_END_NAMESPACE diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 213fdc3..dc6888d 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -572,45 +572,45 @@ bool QFileSystemEngine::removeDirectory(const QFileSystemEntry &entry, bool remo } //static -bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) +bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { if (::symlink(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) return true; - errorString = qt_error_string(errno); + error = QSystemError(errno, QSystemError::StandardLibraryError); return false; } //static -bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) +bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { Q_UNUSED(source); Q_UNUSED(target); // # we can implement this using sendfile(2) - errorString = QLatin1String("Not implemented!"); + //when this function returns false, block copy is used in QFile which sets the error code. return false; } //static -bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) +bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { if (::rename(source.nativeFilePath().constData(), target.nativeFilePath().constData()) == 0) return true; - errorString = qt_error_string(errno); + error = QSystemError(errno, QSystemError::StandardLibraryError); return false; } //static -bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QString &errorString) +bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QSystemError &error) { if (unlink(entry.nativeFilePath().constData()) == 0) return true; - errorString = qt_error_string(errno); + error = QSystemError(errno, QSystemError::StandardLibraryError); return false; } //static -bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QString &errorString, QFileSystemMetaData *data) +bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data) { mode_t mode = 0; if (permissions & QFile::ReadOwner) @@ -645,7 +645,7 @@ bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Per data->knownFlagsMask |= QFileSystemMetaData::Permissions; } if (!success) - errorString = qt_error_string(errno); + error = QSystemError(errno, QSystemError::StandardLibraryError); return success; } diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index 5cc7395..53b9e43 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -1115,43 +1115,43 @@ QFileSystemEntry QFileSystemEngine::currentPath() } //static -bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) +bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { - errorString = QLatin1String("not implemented"); - return false; // TODO implement; + Q_ASSERT(false); + return false; // TODO implement; - code needs to be moved from qfsfileengine_win.cpp } //static -bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) +bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { bool ret = ::CopyFile((wchar_t*)source.nativeFilePath().utf16(), (wchar_t*)target.nativeFilePath().utf16(), true) != 0; if(!ret) - errorString = qt_error_string(::GetLastError()); + error = QSystemError(::GetLastError(), QSystemError::NativeError); return ret; } //static -bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QString &errorString) +bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { bool ret = ::MoveFile((wchar_t*)source.nativeFilePath().utf16(), (wchar_t*)target.nativeFilePath().utf16()) != 0; if(!ret) - errorString = qt_error_string(::GetLastError()); + error = QSystemError(::GetLastError(), QSystemError::NativeError); return ret; } //static -bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QString &errorString) +bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QSystemError &error) { bool ret = ::DeleteFile((wchar_t*)entry.nativeFilePath().utf16()) != 0; if(!ret) - errorString = qt_error_string(::GetLastError()); + error = QSystemError(::GetLastError(), QSystemError::NativeError); return ret; } //static -bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QString &errorString, +bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data) { Q_UNUSED(data); @@ -1169,7 +1169,7 @@ bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Per bool ret = (::_wchmod((wchar_t*)entry.nativeFilePath().utf16(), mode) == 0); if(!ret) - errorString = qt_error_string(errno); + error = QSystemError(errno, QSystemError::StandardLibraryError); return ret; } diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index 14a8938..715b46f 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -185,10 +185,6 @@ public: int sysOpen(const QString &, int flags); #endif -#ifdef Q_OS_SYMBIAN - void setSymbianError(int symbianError, QFile::FileError defaultError, QString defaultString); -#endif - protected: QFSFileEnginePrivate(); diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index a64f8dc..caf5f4c 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -239,7 +239,7 @@ bool QFSFileEnginePrivate::nativeOpen(QIODevice::OpenMode openMode) } if (r != KErrNone) { - q->setError(QFile::OpenError, QFileSystemEngine::errorString(r)); + q->setError(QFile::OpenError, QSystemError(r, QSystemError::NativeError).toString()); symbianFile.Close(); return false; } @@ -385,7 +385,7 @@ qint64 QFSFileEnginePrivate::nativeRead(char *data, qint64 len) TInt r = symbianFile.Read(ptr); if (r != KErrNone) { - q->setError(QFile::ReadError, QFileSystemEngine::errorString(r)); + q->setError(QFile::ReadError, QSystemError(r, QSystemError::NativeError).toString()); return -1; } return qint64(ptr.Length()); @@ -470,7 +470,7 @@ qint64 QFSFileEnginePrivate::nativeWrite(const char *data, qint64 len) TInt r = symbianFile.Write(ptr); if (r != KErrNone) { - q->setError(QFile::WriteError, QFileSystemEngine::errorString(r)); + q->setError(QFile::WriteError, QSystemError(r, QSystemError::NativeError).toString()); return -1; } return len; @@ -494,7 +494,7 @@ qint64 QFSFileEnginePrivate::nativePos() const #endif TInt err = symbianFile.Seek(ESeekCurrent, pos); if(err != KErrNone) { - const_cast<QFSFileEngine*>(q)->setError(QFile::PositionError, QFileSystemEngine::errorString(err)); + const_cast<QFSFileEngine*>(q)->setError(QFile::PositionError, QSystemError(err, QSystemError::NativeError).toString()); return -1; } return pos; @@ -523,7 +523,7 @@ bool QFSFileEnginePrivate::nativeSeek(qint64 pos) #endif if (r != KErrNone) { - q->setError(QFile::PositionError, QFileSystemEngine::errorString(r)); + q->setError(QFile::PositionError, QSystemError(r, QSystemError::NativeError).toString()); return false; } return true; @@ -555,11 +555,11 @@ bool QFSFileEnginePrivate::nativeIsSequential() const bool QFSFileEngine::remove() { Q_D(QFSFileEngine); - QString errorString; - bool ret = QFileSystemEngine::removeFile(d->fileEntry, errorString); + QSystemError error; + bool ret = QFileSystemEngine::removeFile(d->fileEntry, error); d->metaData.clear(); if (!ret) { - setError(QFile::RemoveError, errorString); + setError(QFile::RemoveError, error.toString()); } return ret; } @@ -567,10 +567,10 @@ bool QFSFileEngine::remove() bool QFSFileEngine::copy(const QString &newName) { Q_D(QFSFileEngine); - QString error; + QSystemError error; bool ret = QFileSystemEngine::copyFile(d->fileEntry, QFileSystemEntry(newName), error); if (!ret) { - setError(QFile::CopyError, error); + setError(QFile::CopyError, error.toString()); } return ret; } @@ -578,11 +578,11 @@ bool QFSFileEngine::copy(const QString &newName) bool QFSFileEngine::rename(const QString &newName) { Q_D(QFSFileEngine); - QString error; + QSystemError error; bool ret = QFileSystemEngine::renameFile(d->fileEntry, QFileSystemEntry(newName), error); if (!ret) { - setError(QFile::RenameError, error); + setError(QFile::RenameError, error.toString()); } return ret; @@ -591,10 +591,10 @@ bool QFSFileEngine::rename(const QString &newName) bool QFSFileEngine::link(const QString &newName) { Q_D(QFSFileEngine); - QString error; + QSystemError error; bool ret = QFileSystemEngine::createLink(d->fileEntry, QFileSystemEntry(newName), error); if (!ret) { - setError(QFile::RenameError, error); + setError(QFile::RenameError, error.toString()); } return ret; } @@ -611,7 +611,7 @@ qint64 QFSFileEnginePrivate::nativeSize() const #endif TInt err = symbianFile.Size(size); if(err != KErrNone) { - const_cast<QFSFileEngine*>(q)->setError(QFile::PositionError, QFileSystemEngine::errorString(err)); + const_cast<QFSFileEngine*>(q)->setError(QFile::PositionError, QSystemError(err, QSystemError::NativeError).toString()); return 0; } return size; @@ -850,9 +850,9 @@ QString QFSFileEngine::owner(FileOwner own) const bool QFSFileEngine::setPermissions(uint perms) { Q_D(QFSFileEngine); - QString error; + QSystemError error; if (!QFileSystemEngine::setPermissions(d->fileEntry, QFile::Permissions(perms), error, 0)) { - setError(QFile::PermissionsError, error); + setError(QFile::PermissionsError, error.toString()); return false; } return true; @@ -884,10 +884,12 @@ bool QFSFileEngine::setSize(qint64 size) ret = (err == KErrNone); } if (!ret) { + QSystemError error; if (err) - setError(QFile::ResizeError, QFileSystemEngine::errorString(err)); + error = QSystemError(err, QSystemError::NativeError); else - setError(QFile::ResizeError, qt_error_string(errno)); + error = QSystemError(errno, QSystemError::StandardLibraryError); + setError(QFile::ResizeError, error.toString()); } return ret; } diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 63f2a9f..cf83c07 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -503,30 +503,30 @@ bool QFSFileEnginePrivate::nativeIsSequential() const bool QFSFileEngine::remove() { Q_D(QFSFileEngine); - QString error; + QSystemError error; bool ret = QFileSystemEngine::removeFile(d->fileEntry, error); if (!ret) - setError(QFile::RemoveError, error); + setError(QFile::RemoveError, error.toString()); return ret; } bool QFSFileEngine::copy(const QString ©Name) { Q_D(QFSFileEngine); - QString error; + QSystemError error; bool ret = QFileSystemEngine::copyFile(d->fileEntry, QFileSystemEntry(copyName), error); if (!ret) - setError(QFile::CopyError, error); + setError(QFile::CopyError, error.toString()); return ret; } bool QFSFileEngine::rename(const QString &newName) { Q_D(QFSFileEngine); - QString error; + QSystemError error; bool ret = QFileSystemEngine::renameFile(d->fileEntry, QFileSystemEntry(newName), error); if (!ret) - setError(QFile::RenameError, error); + setError(QFile::RenameError, error.toString()); return ret; } @@ -854,10 +854,10 @@ QString QFSFileEngine::owner(FileOwner own) const bool QFSFileEngine::setPermissions(uint perms) { Q_D(QFSFileEngine); - QString error; + QSystemError error; bool ret = QFileSystemEngine::setPermissions(d->fileEntry, QFile::Permissions(perms), error); if (!ret) - setError(QFile::PermissionsError, error); + setError(QFile::PermissionsError, error.toString()); return ret; } diff --git a/src/corelib/kernel/qsystemerror.cpp b/src/corelib/kernel/qsystemerror.cpp index 065014a..d2350b5 100644 --- a/src/corelib/kernel/qsystemerror.cpp +++ b/src/corelib/kernel/qsystemerror.cpp @@ -39,8 +39,40 @@ ** ****************************************************************************/ +#include <qglobal.h> #include "qsystemerror_p.h" -#include <errno.h> +#if !defined(Q_OS_WINCE) +# include <errno.h> +# if defined(Q_CC_MSVC) +# include <crtdbg.h> +# endif +#endif +#ifdef Q_OS_WIN +#include <windows.h> +#endif + +#if !defined(Q_OS_WIN) && !defined(QT_NO_THREAD) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) && \ + defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L +namespace { + // There are two incompatible versions of strerror_r: + // a) the XSI/POSIX.1 version, which returns an int, + // indicating success or not + // b) the GNU version, which returns a char*, which may or may not + // be the beginning of the buffer we used + // The GNU libc manpage for strerror_r says you should use the the XSI + // version in portable code. However, it's impossible to do that if + // _GNU_SOURCE is defined so we use C++ overloading to decide what to do + // depending on the return type + static inline QString fromstrerror_helper(int, const QByteArray &buf) + { + return QString::fromLocal8Bit(buf); + } + static inline QString fromstrerror_helper(const char *str, const QByteArray &) + { + return QString::fromLocal8Bit(str); + } +} +#endif static QString standardLibraryErrorString(int errorCode) { @@ -166,23 +198,19 @@ QString QSystemError::toString() switch(errorScope) { case NativeError: #if defined (Q_OS_WIN) - errorString = windowsErrorString(errorCode); - break; + return windowsErrorString(errorCode); #elif defined (Q_OS_SYMBIAN) return symbianErrorString(errorCode); - break; #else //unix: fall through as native and standard library are the same #endif case StandardLibraryError: return standardLibraryErrorString(errorCode); - break; default: qWarning("invalid error scope"); //fall through case NoError: return QLatin1String("No error"); - break; } } diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro index 6531a83..9e5845c 100644 --- a/src/tools/bootstrap/bootstrap.pro +++ b/src/tools/bootstrap/bootstrap.pro @@ -69,6 +69,7 @@ SOURCES += \ ../../corelib/io/qurl.cpp \ ../../corelib/kernel/qmetatype.cpp \ ../../corelib/kernel/qvariant.cpp \ + ../../corelib/kernel/qsystemerror.cpp \ ../../corelib/tools/qbitarray.cpp \ ../../corelib/tools/qbytearray.cpp \ ../../corelib/tools/qbytearraymatcher.cpp \ @@ -83,7 +84,7 @@ SOURCES += \ ../../corelib/tools/qvector.cpp \ ../../corelib/tools/qvsnprintf.cpp \ ../../corelib/xml/qxmlutils.cpp \ - ../../corelib/xml/qxmlstream.cpp \ + ../../corelib/xml/qxmlstream.cpp \ ../../xml/dom/qdom.cpp \ ../../xml/sax/qxml.cpp |