summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/qsystemlibrary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/plugin/qsystemlibrary.cpp')
-rw-r--r--src/corelib/plugin/qsystemlibrary.cpp86
1 files changed, 27 insertions, 59 deletions
diff --git a/src/corelib/plugin/qsystemlibrary.cpp b/src/corelib/plugin/qsystemlibrary.cpp
index 593b0c3be7..d3dff226d9 100644
--- a/src/corelib/plugin/qsystemlibrary.cpp
+++ b/src/corelib/plugin/qsystemlibrary.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsystemlibrary_p.h"
#include <QtCore/qvarlengtharray.h>
@@ -72,52 +36,56 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
#if !defined(QT_BOOTSTRAPPED)
extern QString qAppFileName();
#endif
static QString qSystemDirectory()
{
- QVarLengthArray<wchar_t, MAX_PATH> fullPath;
-
- UINT retLen = ::GetSystemDirectory(fullPath.data(), MAX_PATH);
- if (retLen > MAX_PATH) {
- fullPath.resize(retLen);
- retLen = ::GetSystemDirectory(fullPath.data(), retLen);
- }
- // in some rare cases retLen might be 0
- return QString::fromWCharArray(fullPath.constData(), int(retLen));
+ static const QString result = []() -> QString {
+ QVarLengthArray<wchar_t, MAX_PATH> fullPath = {};
+ UINT retLen = ::GetSystemDirectoryW(fullPath.data(), MAX_PATH);
+ if (retLen > MAX_PATH) {
+ fullPath.resize(retLen);
+ retLen = ::GetSystemDirectoryW(fullPath.data(), retLen);
+ }
+ // in some rare cases retLen might be 0
+ return QString::fromWCharArray(fullPath.constData(), int(retLen));
+ }();
+ return result;
}
HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */)
{
+ if (onlySystemDirectory)
+ return ::LoadLibraryExW(libraryName, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
+
QStringList searchOrder;
#if !defined(QT_BOOTSTRAPPED)
- if (!onlySystemDirectory)
- searchOrder << QFileInfo(qAppFileName()).path();
+ searchOrder << QFileInfo(qAppFileName()).path();
#endif
searchOrder << qSystemDirectory();
- if (!onlySystemDirectory) {
- const QString PATH(QLatin1String(qgetenv("PATH").constData()));
- searchOrder << PATH.split(QLatin1Char(';'), Qt::SkipEmptyParts);
- }
- QString fileName = QString::fromWCharArray(libraryName);
- fileName.append(QLatin1String(".dll"));
+ const QString PATH(QLatin1StringView(qgetenv("PATH")));
+ searchOrder << PATH.split(u';', Qt::SkipEmptyParts);
+
+ const QString fileName = QString::fromWCharArray(libraryName);
// Start looking in the order specified
for (int i = 0; i < searchOrder.count(); ++i) {
QString fullPathAttempt = searchOrder.at(i);
- if (!fullPathAttempt.endsWith(QLatin1Char('\\'))) {
- fullPathAttempt.append(QLatin1Char('\\'));
+ if (!fullPathAttempt.endsWith(u'\\')) {
+ fullPathAttempt.append(u'\\');
}
fullPathAttempt.append(fileName);
HINSTANCE inst = ::LoadLibrary(reinterpret_cast<const wchar_t *>(fullPathAttempt.utf16()));
- if (inst != 0)
+ if (inst != nullptr)
return inst;
}
- return 0;
+ return nullptr;
}
QT_END_NAMESPACE