summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-03-06 15:22:27 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-09 19:39:54 +0200
commit7a6883081ca7ce9978f4c1779eef718ec9a35d0a (patch)
tree6b36ba6c6f66e89ef66844305c921012ed3e6554 /src/corelib/global
parent171526ff8f590a40a79beb7b0c48ad695fb210df (diff)
Add QSysInfo::osKernelVersion()
Change-Id: If9a41d8b9530d36b2b574fdb93111ed556e8bdf2 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qglobal.cpp51
-rw-r--r--src/corelib/global/qsysinfo.h1
2 files changed, 46 insertions, 6 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index ca02cc1031..c24254e736 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -2028,16 +2028,19 @@ static const char *winVer_helper()
const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion();
#endif
-#if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY) && !defined(Q_OS_MAC)
+#if defined(Q_OS_UNIX)
struct QUnixOSVersion
{
// from uname(2)
QString sysName;
QString sysNameLower;
+ QString sysRelease;
+# if !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY) && !defined(Q_OS_MAC)
// from /etc/os-release:
QString versionIdentifier; // ${ID}_$VERSION_ID
QString versionText; // $PRETTY_NAME
+# endif
};
# if !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY) && !defined(Q_OS_MAC)
@@ -2058,15 +2061,22 @@ static QUnixOSVersion detectUnixVersion()
if (uname(&u) != -1) {
v.sysName = QString::fromLatin1(u.sysname);
v.sysNameLower = v.sysName.toLower();
+ v.sysRelease = QString::fromLatin1(u.release);
} else {
v.sysName = QLatin1String("Detection failed");
- // leave sysNameLower unset
+ // leave sysNameLower & sysRelease unset
}
+# if !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY) && !defined(Q_OS_MAC)
// we're avoiding QFile here
int fd = qt_safe_open("/etc/os-release", O_RDONLY);
- if (fd == -1)
+ if (fd == -1) {
+ if (!v.sysNameLower.isEmpty()) {
+ // will produce "qnx_6.5" or "sunos_5.9"
+ v.versionIdentifier = v.sysNameLower + QLatin1Char('_') + v.sysRelease;
+ }
return v;
+ }
QT_STATBUF sbuf;
if (QT_FSTAT(fd, &sbuf) == -1) {
@@ -2127,7 +2137,7 @@ static QUnixOSVersion detectUnixVersion()
continue;
}
}
-
+# endif
return v;
}
#endif
@@ -2286,9 +2296,11 @@ QString QSysInfo::osType()
detected by winVersion(), without the word "Windows". For Linux-based
systems, it will try to determine the Linux distribution and version.
- If the version could not be determined, this function returns "unknown".
+ If the version could not be determined, this function returns "unknown" for
+ Windows and a combination of the osType() and osKernelVersion() for Unix
+ systems.
- \sa prettyOsName()
+ \sa prettyOsName(), osKernelVersion()
*/
QString QSysInfo::osVersion()
{
@@ -2400,6 +2412,33 @@ QString QSysInfo::prettyOsName()
#endif
}
+/*!
+ \since 5.4
+
+ Returns the release version of the operating system. On Windows, it returns
+ the version of the kernel, which does not match the version number of the
+ OS (e.g., Windows 8 has NT kernel version 6.2). On Unix systems, including
+ Android, BlackBerry and OS X, it returns the same as the \c{uname -r}
+ command would return.
+
+ If the version could not be determined, this function may return an empty
+ string.
+
+ \sa osVersion(), prettyOsName()
+*/
+QString QSysInfo::osKernelVersion()
+{
+#ifdef Q_OS_WINRT
+ // TBD
+ return QString();
+#elif defined(Q_OS_WIN)
+ const OSVERSIONINFO osver = winOsVersion();
+ return QString::number(int(osver.dwMajorVersion)) + QLatin1Char('.') + QString::number(int(osver.dwMinorVersion))
+ + QLatin1Char('.') + QString::number(int(osver.dwBuildNumber));
+#else
+ return detectUnixVersion().sysRelease;
+#endif
+}
/*!
\macro void Q_ASSERT(bool test)
diff --git a/src/corelib/global/qsysinfo.h b/src/corelib/global/qsysinfo.h
index d384d23acc..7b41bf25ce 100644
--- a/src/corelib/global/qsysinfo.h
+++ b/src/corelib/global/qsysinfo.h
@@ -166,6 +166,7 @@ public:
static QString cpuArchitecture();
static QString fullCpuArchitecture();
static QString osType();
+ static QString osKernelVersion();
static QString osVersion();
static QString prettyOsName();
};