diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-04-26 09:02:45 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-04-26 09:09:19 (GMT) |
commit | e3894396b663ff674c4af19b87b34bdf688c19b2 (patch) | |
tree | de8c4403eb6de27da7bffc232b55a0bf4cfe60fa /src/corelib/global | |
parent | b80af86c2917ab3cdcbeb790c2bd41b11c03f837 (diff) | |
download | Qt-e3894396b663ff674c4af19b87b34bdf688c19b2.zip Qt-e3894396b663ff674c4af19b87b34bdf688c19b2.tar.gz Qt-e3894396b663ff674c4af19b87b34bdf688c19b2.tar.bz2 |
Fix the use of strerror_r on GNU libc systems.
Task-number: QTBUG-10014
Reviewed-By: Olivier Goffart
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index c8f836a..66519be 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2074,7 +2074,28 @@ static void mac_default_handler(const char *msg) } #endif // Q_CC_MWERKS && Q_OS_MACX - +#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 QString qt_error_string(int errorCode) { @@ -2117,12 +2138,9 @@ QString qt_error_string(int errorCode) if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND) ret = QString::fromLatin1("The specified module could not be found."); - #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) - QByteArray buf(1024, '\0'); - strerror_r(errorCode, buf.data(), buf.size()); - ret = QString::fromLocal8Bit(buf.constData()); + ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf); #else ret = QString::fromLocal8Bit(strerror(errorCode)); #endif |