summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r--src/corelib/global/qglobal.cpp55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index a8ed8ca6fd..2b1a40cf4c 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -52,6 +52,7 @@
#include <private/qlocale_tools_p.h>
#include <qmutex.h>
+#include <QtCore/private/qlocking_p.h>
#include <stdlib.h>
#include <limits.h>
@@ -88,6 +89,11 @@
# include <sys/systeminfo.h>
#endif
+#if defined(Q_OS_DARWIN) && QT_HAS_INCLUDE(<IOKit/IOKitLib.h>)
+# include <IOKit/IOKitLib.h>
+# include <private/qcore_mac_p.h>
+#endif
+
#ifdef Q_OS_UNIX
#include <sys/utsname.h>
#include <private/qcore_unix_p.h>
@@ -1194,11 +1200,14 @@ bool qSharedBuild() noexcept
the application is compiled (32 or 64).
*/
+#if QT_DEPRECATED_SINCE(5, 9)
/*!
\deprecated
\variable QSysInfo::WindowsVersion
\brief the version of the Windows operating system on which the
application is run.
+
+ Use QOperatingSystemVersion::current() instead.
*/
/*!
@@ -1206,6 +1215,8 @@ bool qSharedBuild() noexcept
\fn QSysInfo::WindowsVersion QSysInfo::windowsVersion()
\since 4.4
+ Use QOperatingSystemVersion::current() instead.
+
Returns the version of the Windows operating system on which the
application is run, or WV_None if the operating system is not
Windows.
@@ -1216,16 +1227,21 @@ bool qSharedBuild() noexcept
\variable QSysInfo::MacintoshVersion
\brief the version of the Macintosh operating system on which
the application is run.
+
+ Use QOperatingSystemVersion::current() instead.
*/
/*!
\deprecated
\fn QSysInfo::MacVersion QSysInfo::macVersion()
+ Use QOperatingSystemVersion::current() instead.
+
Returns the version of Darwin (\macos or iOS) on which the
application is run, or MV_None if the operating system
is not a version of Darwin.
*/
+#endif
/*!
\enum QSysInfo::Endian
@@ -1236,10 +1252,13 @@ bool qSharedBuild() noexcept
the platform's byte order.
*/
+#if QT_DEPRECATED_SINCE(5, 9)
/*!
\deprecated
\enum QSysInfo::WinVersion
+ Use the versions defined in QOperatingSystemVersion instead.
+
This enum provides symbolic names for the various versions of the
Windows operating system. On Windows, the
QSysInfo::WindowsVersion variable gives the version of the system
@@ -1297,6 +1316,8 @@ bool qSharedBuild() noexcept
\deprecated
\enum QSysInfo::MacVersion
+ Use the versions defined in QOperatingSystemVersion instead.
+
This enum provides symbolic names for the various versions of the
Darwin operating system, covering both \macos and iOS. The
QSysInfo::MacintoshVersion variable gives the version of the
@@ -1367,6 +1388,7 @@ bool qSharedBuild() noexcept
\sa WinVersion
*/
+#endif
/*!
\macro Q_OS_DARWIN
@@ -2996,20 +3018,19 @@ enum {
*/
QByteArray QSysInfo::machineUniqueId()
{
-#ifdef Q_OS_BSD4
+#if defined(Q_OS_DARWIN) && QT_HAS_INCLUDE(<IOKit/IOKitLib.h>)
+ char uuid[UuidStringLen + 1];
+ io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
+ QCFString stringRef = (CFStringRef)IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
+ CFStringGetCString(stringRef, uuid, sizeof(uuid), kCFStringEncodingMacRoman);
+ return QByteArray(uuid);
+#elif defined(Q_OS_BSD4) && defined(KERN_HOSTUUID)
char uuid[UuidStringLen + 1];
size_t uuidlen = sizeof(uuid);
-# ifdef KERN_HOSTUUID
int name[] = { CTL_KERN, KERN_HOSTUUID };
if (sysctl(name, sizeof name / sizeof name[0], &uuid, &uuidlen, nullptr, 0) == 0
&& uuidlen == sizeof(uuid))
return QByteArray(uuid, uuidlen - 1);
-
-# else
- // Darwin: no fixed value, we need to search by name
- if (sysctlbyname("kern.uuid", uuid, &uuidlen, nullptr, 0) == 0 && uuidlen == sizeof(uuid))
- return QByteArray(uuid, uuidlen - 1);
-# endif
#elif defined(Q_OS_UNIX)
// The modern name on Linux is /etc/machine-id, but that path is
// unlikely to exist on non-Linux (non-systemd) systems. The old
@@ -3347,7 +3368,7 @@ static QBasicMutex environmentMutex;
*/
void qTzSet()
{
- QMutexLocker locker(&environmentMutex);
+ const auto locker = qt_scoped_lock(environmentMutex);
#if defined(Q_OS_WIN)
_tzset();
#else
@@ -3361,7 +3382,7 @@ void qTzSet()
*/
time_t qMkTime(struct tm *when)
{
- QMutexLocker locker(&environmentMutex);
+ const auto locker = qt_scoped_lock(environmentMutex);
return mktime(when);
}
@@ -3393,7 +3414,7 @@ time_t qMkTime(struct tm *when)
*/
QByteArray qgetenv(const char *varName)
{
- QMutexLocker locker(&environmentMutex);
+ const auto locker = qt_scoped_lock(environmentMutex);
#ifdef Q_CC_MSVC
size_t requiredSize = 0;
QByteArray buffer;
@@ -3461,7 +3482,7 @@ QByteArray qgetenv(const char *varName)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
{
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
- QMutexLocker locker(&environmentMutex);
+ const auto locker = qt_scoped_lock(environmentMutex);
QVarLengthArray<wchar_t, 32> wname(int(strlen(varName)) + 1);
for (int i = 0; i < wname.size(); ++i) // wname.size() is correct: will copy terminating null
wname[i] = uchar(varName[i]);
@@ -3509,7 +3530,7 @@ QString qEnvironmentVariable(const char *varName)
*/
bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
{
- QMutexLocker locker(&environmentMutex);
+ const auto locker = qt_scoped_lock(environmentMutex);
#ifdef Q_CC_MSVC
// we provide a buffer that can only hold the empty string, so
// when the env.var isn't empty, we'll get an ERANGE error (buffer
@@ -3548,7 +3569,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept
static const int MaxDigitsForOctalInt =
(std::numeric_limits<uint>::digits + NumBinaryDigitsPerOctalDigit - 1) / NumBinaryDigitsPerOctalDigit;
- QMutexLocker locker(&environmentMutex);
+ const auto locker = qt_scoped_lock(environmentMutex);
#ifdef Q_CC_MSVC
// we provide a buffer that can hold any int value:
char buffer[MaxDigitsForOctalInt + 2]; // +1 for NUL +1 for optional '-'
@@ -3613,7 +3634,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept
*/
bool qEnvironmentVariableIsSet(const char *varName) noexcept
{
- QMutexLocker locker(&environmentMutex);
+ const auto locker = qt_scoped_lock(environmentMutex);
#ifdef Q_CC_MSVC
size_t requiredSize = 0;
(void)getenv_s(&requiredSize, 0, 0, varName);
@@ -3643,7 +3664,7 @@ bool qEnvironmentVariableIsSet(const char *varName) noexcept
*/
bool qputenv(const char *varName, const QByteArray& value)
{
- QMutexLocker locker(&environmentMutex);
+ const auto locker = qt_scoped_lock(environmentMutex);
#if defined(Q_CC_MSVC)
return _putenv_s(varName, value.constData()) == 0;
#elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_HAIKU)
@@ -3674,7 +3695,7 @@ bool qputenv(const char *varName, const QByteArray& value)
*/
bool qunsetenv(const char *varName)
{
- QMutexLocker locker(&environmentMutex);
+ const auto locker = qt_scoped_lock(environmentMutex);
#if defined(Q_CC_MSVC)
return _putenv_s(varName, "") == 0;
#elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_BSD4) || defined(Q_OS_HAIKU)