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.cpp69
1 files changed, 52 insertions, 17 deletions
diff --git a/src/corelib/global/qsysinfo.cpp b/src/corelib/global/qsysinfo.cpp
index 0502e77177..0ca04154e6 100644
--- a/src/corelib/global/qsysinfo.cpp
+++ b/src/corelib/global/qsysinfo.cpp
@@ -224,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
@@ -235,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
@@ -279,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;
}
}
@@ -352,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)
@@ -368,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;
@@ -709,7 +709,8 @@ QString QSysInfo::kernelType()
Returns the release version of the operating system kernel. On Windows, it
returns the version of the NT kernel. On Unix systems, including
Android and \macos, it returns the same as the \c{uname -r}
- command would return.
+ command would return. On VxWorks, it returns the numeric part of the string
+ reported by kernelVersion().
If the version could not be determined, this function may return an empty
string.
@@ -724,8 +725,17 @@ QString QSysInfo::kernelVersion()
osver.majorVersion(), osver.minorVersion(), osver.microVersion());
#else
struct utsname u;
- if (uname(&u) == 0)
+ if (uname(&u) == 0) {
+# ifdef Q_OS_VXWORKS
+ // The string follows the pattern "Core Kernel version: w.x.y.z"
+ auto versionStr = QByteArrayView(u.kernelversion);
+ if (auto lastSpace = versionStr.lastIndexOf(' '); lastSpace != -1) {
+ return QString::fromLatin1(versionStr.sliced(lastSpace + 1));
+ }
+# else
return QString::fromLatin1(u.release);
+# endif
+ }
return QString();
#endif
}
@@ -762,6 +772,8 @@ QString QSysInfo::kernelVersion()
\b{Windows note}: this function return "windows"
+ \b{VxWorks note}: this function return "vxworks"
+
For other Unix-type systems, this function usually returns "unknown".
\sa QFileSelector, kernelType(), kernelVersion(), productVersion(), prettyProductName()
@@ -784,12 +796,16 @@ 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(Q_OS_VXWORKS)
+ return QStringLiteral("vxworks");
#elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX
QUnixOSVersion unixOsVersion;
@@ -806,7 +822,7 @@ QString QSysInfo::productType()
Returns the product version of the operating system in string form. If the
version could not be determined, this function returns "unknown".
- It will return the Android, iOS, \macos, Windows full-product
+ It will return the Android, iOS, \macos, VxWorks, Windows full-product
versions on those systems.
Typical returned values are (note: list not exhaustive):
@@ -819,6 +835,7 @@ QString QSysInfo::productType()
\li "8.6" (watchOS 8.6)
\li "11" (Windows 11)
\li "Server 2022" (Windows Server 2022)
+ \li "24.03" (VxWorks 7 - 24.03)
\endlist
On Linux systems, it will try to determine the distribution version and will
@@ -847,6 +864,12 @@ QString QSysInfo::productVersion()
}
// fall through
+#elif defined(Q_OS_VXWORKS)
+ utsname u;
+ if (uname(&u) == 0)
+ return QString::fromLatin1(u.releaseversion);
+ // fall through
+
#elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX
QUnixOSVersion unixOsVersion;
findUnixOsVersion(unixOsVersion);
@@ -938,13 +961,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
@@ -979,8 +1015,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);