From 106bab644a5d55f136d223fadc1440e07cd41872 Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Wed, 24 Aug 2011 09:03:02 +0300 Subject: Fix qsystemerror for WinCE Windows CE does not have strerror(_r), so lets use string formatting provided by windowsErrorString function. In order to use windowsErrorString it was moved before standardLibraryErrorString function. Task-number: QTBUG-22498 Change-Id: Ifa20c4ac314ac8a26de6b0c5b67ced96b262c2b4 Reviewed-by: Andreas Holzammer Reviewed-by: Shane Kearns --- src/corelib/kernel/qsystemerror.cpp | 58 +++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 25 deletions(-) (limited to 'src/corelib/kernel/qsystemerror.cpp') diff --git a/src/corelib/kernel/qsystemerror.cpp b/src/corelib/kernel/qsystemerror.cpp index eabb20001c..708eba89a6 100644 --- a/src/corelib/kernel/qsystemerror.cpp +++ b/src/corelib/kernel/qsystemerror.cpp @@ -46,6 +46,10 @@ # if defined(Q_CC_MSVC) # include # endif +#else +# if (_WIN32_WCE >= 0x700) +# include +# endif #endif #ifdef Q_OS_WIN #include @@ -76,6 +80,27 @@ namespace { } #endif +#ifdef Q_OS_WIN +static QString windowsErrorString(int errorCode) +{ + QString ret; + wchar_t *string = 0; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errorCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPWSTR)&string, + 0, + NULL); + ret = QString::fromWCharArray(string); + LocalFree((HLOCAL)string); + + if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND) + ret = QString::fromLatin1("The specified module could not be found."); + return ret; +} +#endif + static QString standardLibraryErrorString(int errorCode) { const char *s = 0; @@ -96,11 +121,15 @@ static QString standardLibraryErrorString(int errorCode) s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device"); break; default: { - #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) - QByteArray buf(1024, '\0'); - ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf); + #ifdef Q_OS_WINCE + ret = windowsErrorString(errorCode); #else - ret = QString::fromLocal8Bit(strerror(errorCode)); + #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) + QByteArray buf(1024, '\0'); + ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf); + #else + ret = QString::fromLocal8Bit(strerror(errorCode)); + #endif #endif break; } } @@ -112,27 +141,6 @@ static QString standardLibraryErrorString(int errorCode) return ret.trimmed(); } -#ifdef Q_OS_WIN -static QString windowsErrorString(int errorCode) -{ - QString ret; - wchar_t *string = 0; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - errorCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPWSTR)&string, - 0, - NULL); - ret = QString::fromWCharArray(string); - LocalFree((HLOCAL)string); - - if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND) - ret = QString::fromLatin1("The specified module could not be found."); - return ret; -} -#endif - #ifdef Q_OS_SYMBIAN static QString symbianErrorString(int errorCode) { -- cgit v1.2.3