ensure qt_error_string() uses XSI/POSIX.1 version of strerror_r()

fixes QProcess test failures

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-09-06 14:18:07 +03:00
parent 88cc7f4429
commit 440e9a9993
4 changed files with 57 additions and 19 deletions

View file

@ -298,6 +298,7 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/concurrent/qthreadpool.cpp
${CMAKE_CURRENT_SOURCE_DIR}/global/qglobal.cpp
${CMAKE_CURRENT_SOURCE_DIR}/global/qlibraryinfo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/global/qt_error_string.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io/qabstractfileengine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io/qbuffer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io/qdatastream.cpp
@ -422,6 +423,10 @@ if(WITH_EXECINFO AND EXECINFO_FOUND)
include_directories(${EXECINFO_INCLUDES})
endif()
katie_unity_exclude(
${CMAKE_CURRENT_SOURCE_DIR}/global/qt_error_string.cpp
)
katie_generate_misc("${CORE_HEADERS}" QtCore)
katie_generate_public("${CORE_PUBLIC_HEADERS}" QtCore)
katie_generate_package(KtCore "")

View file

@ -1106,25 +1106,6 @@ void qt_check_pointer(const char *file, int line)
static QtMsgHandler handler = 0; // pointer to debug handler
QString qt_error_string(int errorCode)
{
// 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.
#if !defined(QT_NO_THREAD)
QSTACKARRAY(char, errbuf, 1024);
::strerror_r(errorCode, errbuf, sizeof(errbuf));
return QString::fromLocal8Bit(errbuf);
#else
return QString::fromLocal8Bit(::strerror(errorCode));
#endif
}
/*!
\fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler)
\relates <QtGlobal>

View file

@ -0,0 +1,51 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016 Ivailo Monev
**
** This file is part of the QtCore module of the Katie Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
// 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.
//
// to get the XSI/POSIX.1 version _GNU_SOURCE must not be defined
#undef _GNU_SOURCE
#include "qcorecommon_p.h"
#include <string.h>
#include <errno.h>
QT_BEGIN_NAMESPACE
QString qt_error_string(int errorCode)
{
#if !defined(QT_NO_THREAD)
QSTACKARRAY(char, errbuf, 1024);
strerror_r(errorCode, errbuf, sizeof(errbuf));
return QString::fromLocal8Bit(errbuf);
#else
return QString::fromLocal8Bit(::strerror(errorCode));
#endif
}
QT_END_NAMESPACE

View file

@ -51,6 +51,7 @@ endif()
set(BOOTSTRAP_SOURCES
${CMAKE_SOURCE_DIR}/src/core/codecs/qicucodec.cpp
${CMAKE_SOURCE_DIR}/src/core/global/qglobal.cpp
${CMAKE_SOURCE_DIR}/src/core/global/qt_error_string.cpp
${CMAKE_SOURCE_DIR}/src/core/io/qabstractfileengine.cpp
${CMAKE_SOURCE_DIR}/src/core/io/qbuffer.cpp
${CMAKE_SOURCE_DIR}/src/core/io/qdir.cpp