summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qsysinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qsysinfo.cpp')
-rw-r--r--src/corelib/global/qsysinfo.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/corelib/global/qsysinfo.cpp b/src/corelib/global/qsysinfo.cpp
index 8ddcbb0409..79cb76b236 100644
--- a/src/corelib/global/qsysinfo.cpp
+++ b/src/corelib/global/qsysinfo.cpp
@@ -91,6 +91,8 @@ using namespace Qt::StringLiterals;
static const char *osVer_helper(QOperatingSystemVersion version = QOperatingSystemVersion::current())
{
#ifdef Q_OS_MACOS
+ if (version.majorVersion() == 13)
+ return "Ventura";
if (version.majorVersion() == 12)
return "Monterey";
// Compare against predefined constant to handle 10.16/11.0
@@ -222,7 +224,7 @@ struct QUnixOSVersion
QString prettyName; // $PRETTY_NAME $DISTRIB_DESCRIPTION
};
-static QString unquote(const char *begin, const char *end)
+static QString unquote(QByteArrayView str)
{
// man os-release says:
// Variable assignment values must be enclosed in double
@@ -233,10 +235,11 @@ static QString unquote(const char *begin, const char *end)
// All strings should be in UTF-8 format, and non-printable
// characters should not be used. It is not supported to
// concatenate multiple individually quoted strings.
- if (*begin == '"')
- return QString::fromUtf8(begin + 1, end - begin - 2);
- return QString::fromUtf8(begin, end - begin);
+ if (str.size() >= 2 && str.front() == '"' && str.back() == '"')
+ str = str.sliced(1).chopped(1);
+ return QString::fromUtf8(str);
}
+
static QByteArray getEtcFileContent(const char *filename)
{
// we're avoiding QFile here
@@ -277,19 +280,19 @@ static bool readEtcFile(QUnixOSVersion &v, const char *filename,
if (line.startsWith(idKey)) {
ptr += idKey.size();
- v.productType = unquote(ptr, eol);
+ v.productType = unquote({ptr, eol});
continue;
}
if (line.startsWith(prettyNameKey)) {
ptr += prettyNameKey.size();
- v.prettyName = unquote(ptr, eol);
+ v.prettyName = unquote({ptr, eol});
continue;
}
if (line.startsWith(versionKey)) {
ptr += versionKey.size();
- v.productVersion = unquote(ptr, eol);
+ v.productVersion = unquote({ptr, eol});
continue;
}
}
@@ -350,8 +353,7 @@ static QByteArray getEtcFileFirstLine(const char *fileName)
return QByteArray();
const char *ptr = buffer.constData();
- int eol = buffer.indexOf("\n");
- return QByteArray(ptr, eol).trimmed();
+ return QByteArray(ptr, buffer.indexOf("\n")).trimmed();
}
static bool readEtcRedHatRelease(QUnixOSVersion &v)
@@ -366,9 +368,9 @@ static bool readEtcRedHatRelease(QUnixOSVersion &v)
v.prettyName = QString::fromLatin1(line);
const char keyword[] = "release ";
- int releaseIndex = line.indexOf(keyword);
+ const qsizetype releaseIndex = line.indexOf(keyword);
v.productType = QString::fromLatin1(line.mid(0, releaseIndex)).remove(u' ');
- int spaceIndex = line.indexOf(' ', releaseIndex + strlen(keyword));
+ const qsizetype spaceIndex = line.indexOf(' ', releaseIndex + strlen(keyword));
v.productVersion = QString::fromLatin1(line.mid(releaseIndex + strlen(keyword),
spaceIndex > -1 ? spaceIndex - releaseIndex - int(strlen(keyword)) : -1));
return true;
@@ -782,10 +784,14 @@ QString QSysInfo::productType()
return QStringLiteral("tvos");
#elif defined(Q_OS_WATCHOS)
return QStringLiteral("watchos");
+#elif defined(Q_OS_VISIONOS)
+ return QStringLiteral("visionos");
#elif defined(Q_OS_MACOS)
return QStringLiteral("macos");
#elif defined(Q_OS_DARWIN)
return QStringLiteral("darwin");
+#elif defined(Q_OS_WASM)
+ return QStringLiteral("wasm");
#elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX
QUnixOSVersion unixOsVersion;
@@ -934,13 +940,26 @@ QString QSysInfo::machineHostName()
# ifdef Q_OS_WIN
// Important: QtNetwork depends on machineHostName() initializing ws2_32.dll
winsockInit();
-# endif
+ QString hostName;
+ hostName.resize(512);
+ unsigned long len = hostName.size();
+ BOOL res = GetComputerNameEx(ComputerNameDnsHostname,
+ reinterpret_cast<wchar_t *>(const_cast<quint16 *>(hostName.utf16())), &len);
+ if (!res && len > 512) {
+ hostName.resize(len - 1);
+ GetComputerNameEx(ComputerNameDnsHostname,
+ reinterpret_cast<wchar_t *>(const_cast<quint16 *>(hostName.utf16())), &len);
+ }
+ hostName.truncate(len);
+ return hostName;
+# else // !Q_OS_WIN
char hostName[512];
if (gethostname(hostName, sizeof(hostName)) == -1)
return QString();
hostName[sizeof(hostName) - 1] = '\0';
return QString::fromLocal8Bit(hostName);
+# endif
#endif
}
#endif // QT_BOOTSTRAPPED
@@ -975,8 +994,7 @@ QByteArray QSysInfo::machineUniqueId()
{
#if defined(Q_OS_DARWIN) && __has_include(<IOKit/IOKitLib.h>)
char uuid[UuidStringLen + 1];
- static const mach_port_t defaultPort = 0; // Effectively kIOMasterPortDefault/kIOMainPortDefault
- io_service_t service = IOServiceGetMatchingService(defaultPort, IOServiceMatching("IOPlatformExpertDevice"));
+ io_service_t service = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
QCFString stringRef = (CFStringRef)IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
CFStringGetCString(stringRef, uuid, sizeof(uuid), kCFStringEncodingMacRoman);
return QByteArray(uuid);