7#include <QtCore/qbytearray.h>
8#include <QtCore/qoperatingsystemversion.h>
9#include <QtCore/qstring.h>
11#include <private/qoperatingsystemversion_p.h>
14# include <sys/utsname.h>
15# include <private/qcore_unix_p.h>
19#include <QtCore/private/qjnihelpers_p.h>
23#if defined(Q_OS_SOLARIS)
24# include <sys/systeminfo.h>
27#if defined(Q_OS_DARWIN)
29# include <private/qcore_mac_p.h>
30# if __has_include(<IOKit/IOKitLib.h>)
31# include <IOKit/IOKitLib.h>
36# include <sys/sysctl.h>
39#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
41# include "private/qwinregistry_p.h"
89#if defined(Q_OS_DARWIN)
94 if (version.majorVersion() == 13)
96 if (version.majorVersion() == 12)
101 if (version.majorVersion() == 10) {
102 switch (version.minorVersion()) {
112 return "High Sierra";
126#elif defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
128# ifndef QT_BOOTSTRAPPED
129class QWindowsSockInit
137QWindowsSockInit::QWindowsSockInit()
144 if (WSAStartup(MAKEWORD(2, 0), &wsadata) != 0) {
145 qWarning(
"QTcpSocketAPI: WinSock v2.0 initialization failed.");
151QWindowsSockInit::~QWindowsSockInit()
158static QString readVersionRegistryString(
const wchar_t *subKey)
160 return QWinRegistryKey(HKEY_LOCAL_MACHINE, LR
"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)")
164static inline QString windowsDisplayVersion()
169 return readVersionRegistryString(L
"DisplayVersion");
171 return readVersionRegistryString(L
"ReleaseId");
177 const qint16 major = osv.wServicePackMajor;
180 const qint16 minor = osv.wServicePackMinor;
193 const bool workstation = osver.wProductType == VER_NT_WORKSTATION;
195#define Q_WINVER(major, minor) (major << 8 | minor)
196 switch (Q_WINVER(osver.dwMajorVersion, osver.dwMinorVersion)) {
197 case Q_WINVER(10, 0):
199 if (osver.dwBuildNumber >= 22000)
204 if (osver.dwBuildNumber >= 20348)
205 return "Server 2022";
206 if (osver.dwBuildNumber >= 17763)
207 return "Server 2019";
208 return "Server 2016";
216#if defined(Q_OS_UNIX)
217# if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || defined(Q_OS_FREEBSD)
218# define USE_ETC_OS_RELEASE
243static QByteArray getEtcFileContent(
const char *filename)
251 if (QT_FSTAT(
fd, &sbuf) == -1) {
262static bool readEtcFile(QUnixOSVersion &
v,
const char *filename,
276 eol =
static_cast<const char *
>(memchr(
ptr,
'\n',
end -
ptr));
288 ptr += prettyNameKey.size();
294 ptr += versionKey.size();
303static bool readOsRelease(QUnixOSVersion &
v)
314 return readEtcFile(
v,
"/etc/os-release",
id, versionId, prettyName) ||
315 readEtcFile(
v,
"/usr/lib/os-release",
id, versionId, prettyName);
318static bool readEtcLsbRelease(QUnixOSVersion &
v)
322 if (
ok && (
v.prettyName.isEmpty() ||
v.prettyName ==
v.productType)) {
331 if (QT_FSTAT(
fd, &sbuf) != -1 && sbuf.st_size >
v.prettyName.size()) {
345 return ok && !(
v.productType.isEmpty() &&
v.productVersion.isEmpty());
348#if defined(Q_OS_LINUX)
359static bool readEtcRedHatRelease(QUnixOSVersion &
v)
370 const char keyword[] =
"release ";
375 spaceIndex > -1 ? spaceIndex - releaseIndex -
int(strlen(keyword)) : -1));
379static bool readEtcDebianVersion(QUnixOSVersion &
v)
394static bool findUnixOsVersion(QUnixOSVersion &
v)
396 if (readOsRelease(
v))
398 if (readEtcLsbRelease(
v))
400#if defined(Q_OS_LINUX)
401 if (readEtcRedHatRelease(
v))
403 if (readEtcDebianVersion(
v))
430 return "Gingerbread";
437 return "Ice Cream Sandwich";
449 return "Marshmallow";
550 GetNativeSystemInfo(&
info);
551 switch (
info.wProcessorArchitecture) {
552# ifdef PROCESSOR_ARCHITECTURE_AMD64
553 case PROCESSOR_ARCHITECTURE_AMD64:
556# ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
557 case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
559 case PROCESSOR_ARCHITECTURE_IA64:
562#elif defined(Q_OS_DARWIN) && !defined(Q_OS_MACOS)
564 return buildCpuArchitecture();
565#elif defined(Q_OS_UNIX)
569# if defined(Q_OS_SOLARIS)
576 ret = sysinfo(SI_ARCHITECTURE_64, u.machine,
sizeof u.machine);
586# if defined(Q_PROCESSOR_ARM) || defined(QT_BUILD_INTERNAL)
587 if (strcmp(u.machine,
"aarch64") == 0)
589 if (strncmp(u.machine,
"armv", 4) == 0)
592# if defined(Q_PROCESSOR_POWER) || defined(QT_BUILD_INTERNAL)
594 if (strncmp(u.machine,
"ppc", 3) == 0)
596 if (strncmp(u.machine,
"powerpc", 7) == 0)
598 if (strcmp(u.machine,
"Power Macintosh") == 0)
601# if defined(Q_PROCESSOR_SPARC) || defined(QT_BUILD_INTERNAL)
604 if (strcmp(u.machine,
"sun4u") == 0 || strcmp(u.machine,
"sparc64") == 0)
606 if (strcmp(u.machine,
"sparc32") == 0)
609# if defined(Q_PROCESSOR_X86) || defined(QT_BUILD_INTERNAL)
611 if (strlen(u.machine) == 4 && u.machine[0] ==
'i'
612 && u.machine[2] ==
'8' && u.machine[3] ==
'6')
614 if (strcmp(u.machine,
"amd64") == 0)
620 return buildCpuArchitecture();
698#elif defined(Q_OS_UNIX)
724 osver.majorVersion(), osver.minorVersion(), osver.microVersion());
775#elif defined(Q_OS_QNX)
778#elif defined(Q_OS_ANDROID)
781#elif defined(Q_OS_IOS)
783#elif defined(Q_OS_TVOS)
785#elif defined(Q_OS_WATCHOS)
787#elif defined(Q_OS_VISIONOS)
789#elif defined(Q_OS_MACOS)
791#elif defined(Q_OS_DARWIN)
793#elif defined(Q_OS_WASM)
796#elif defined(USE_ETC_OS_RELEASE)
797 QUnixOSVersion unixOsVersion;
798 findUnixOsVersion(unixOsVersion);
799 if (!unixOsVersion.productType.isEmpty())
800 return unixOsVersion.productType;
841#if defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN)
843 return QString::asprintf(
"%d.%d", version.majorVersion(), version.minorVersion());
844#elif defined(Q_OS_WIN)
845 const char *version = osVer_helper();
848 return QString::fromLatin1(version).remove(spaceChar).toLower() + winSp_helper().remove(spaceChar).toLower();
852#elif defined(USE_ETC_OS_RELEASE)
853 QUnixOSVersion unixOsVersion;
854 findUnixOsVersion(unixOsVersion);
855 if (!unixOsVersion.productVersion.isEmpty())
856 return unixOsVersion.productVersion;
879#if defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN) || defined(Q_OS_WIN)
881 const int majorVersion = version.majorVersion();
884 const char *
name = osVer_helper(version);
886 return result + versionString;
888# if !defined(Q_OS_WIN)
889 return result +
" ("_L1 + versionString + u
')';
892 const auto displayVersion = windowsDisplayVersion();
893 if (!displayVersion.isEmpty())
894 result +=
" Version "_L1 + displayVersion;
897#elif defined(Q_OS_HAIKU)
898 return "Haiku "_L1 + productVersion();
899#elif defined(Q_OS_UNIX)
900# ifdef USE_ETC_OS_RELEASE
901 QUnixOSVersion unixOsVersion;
902 findUnixOsVersion(unixOsVersion);
903 if (!unixOsVersion.prettyName.isEmpty())
904 return unixOsVersion.prettyName;
913#ifndef QT_BOOTSTRAPPED
932#if defined(Q_OS_LINUX)
945 unsigned long len = hostName.
size();
946 BOOL
res = GetComputerNameEx(ComputerNameDnsHostname,
947 reinterpret_cast<wchar_t *
>(
const_cast<quint16 *
>(hostName.
utf16())), &
len);
950 GetComputerNameEx(ComputerNameDnsHostname,
951 reinterpret_cast<wchar_t *
>(
const_cast<quint16 *
>(hostName.
utf16())), &
len);
958 if (gethostname(hostName,
sizeof(hostName)) == -1)
960 hostName[
sizeof(hostName) - 1] =
'\0';
968 UuidStringLen =
sizeof(
"00000000-0000-0000-0000-000000000000") - 1
995#if defined(Q_OS_DARWIN) && __has_include(<IOKit/IOKitLib.h>)
997 io_service_t service = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching(
"IOPlatformExpertDevice"));
998 QCFString stringRef = (CFStringRef)IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
999 CFStringGetCString(stringRef, uuid,
sizeof(uuid), kCFStringEncodingMacRoman);
1001#elif defined(Q_OS_BSD4) && defined(KERN_HOSTUUID)
1003 size_t uuidlen =
sizeof(uuid);
1004 int name[] = { CTL_KERN, KERN_HOSTUUID };
1005 if (sysctl(
name,
sizeof name /
sizeof name[0], &uuid, &uuidlen,
nullptr, 0) == 0
1006 && uuidlen ==
sizeof(uuid))
1008#elif defined(Q_OS_UNIX)
1012 static const char fullfilename[] =
"/usr/local/var/lib/dbus/machine-id";
1013 const char *firstfilename = fullfilename +
sizeof(
"/usr/local") - 1;
1015 if (
fd == -1 && errno == ENOENT)
1026#elif defined(Q_OS_WIN)
1030 if (!machineGuid.isEmpty())
1053 int fd =
qt_safe_open(
"/proc/sys/kernel/random/boot_id", O_RDONLY);
1061#elif defined(Q_OS_DARWIN)
1064 size_t uuidlen =
sizeof(uuid);
1065 if (sysctlbyname(
"kern.bootsessionuuid", uuid, &uuidlen,
nullptr, 0) == 0
1066 && uuidlen ==
sizeof(uuid))
QByteArray toLower() const &
static Q_CORE_EXPORT QOperatingSystemVersionBase current()
static constexpr QOperatingSystemVersionBase Windows10_20H2
\variable QOperatingSystemVersion::Windows10_20H2
static constexpr QOperatingSystemVersionBase MacOSBigSur
\variable QOperatingSystemVersion::MacOSBigSur
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString sliced(qsizetype pos) const &
QString chopped(qsizetype n) const &
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
void truncate(qsizetype pos)
Truncates the string at the given position index.
QString mid(qsizetype position, qsizetype n=-1) const &
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString & setRawData(const QChar *unicode, qsizetype size)
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
void resize(qsizetype size)
Sets the size of the string to size characters.
static QString currentCpuArchitecture()
static QByteArray bootUniqueId()
static QString buildAbi()
static QByteArray machineUniqueId()
static QString kernelVersion()
static QString machineHostName()
static QString productType()
static QString kernelType()
static QString buildCpuArchitecture()
static QString productVersion()
static QString prettyProductName()
QString stringValue(QStringView subKey) const
Combined button and popup list for selecting options.
Q_CORE_EXPORT jint androidSdkVersion()
constexpr Initialization Uninitialized
#define QByteArrayLiteral(str)
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
static int qt_safe_close(int fd)
static QString unquote(QStringView str)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static ControlElement< T > * ptr(QWidget *widget)
GLsizei const GLfloat * v
[13]
OSVERSIONINFOEX qWindowsVersionInfo()
#define QStringLiteral(str)
static QString unknownText()
if(qFloatDistance(a, b)<(1<< 7))
[0]
\inmodule QtCore \reentrant