diff options
author | Joseph W. Joshua <joejoshw@gmail.com> | 2014-06-15 00:22:21 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-14 14:46:42 -0700 |
commit | f59b30ca5ad78d378270e455e86a25b4b4a4f047 (patch) | |
tree | f0c899fbc2113deee1819b73729bbd7c44385b6a | |
parent | 8bd535d092430b6df721a91404849755dff042ba (diff) | |
download | subsurface-f59b30ca5ad78d378270e455e86a25b4b4a4f047.tar.gz |
OS Detection: Use QFile when reading /etc/os-release
Improves and simplifies reading of /etc/os-release on
linux system to read the PRETTY_NAME value. The previously
used method is unnecessarily lengthy and too complicated.
Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | subsurfacesysinfo.cpp | 74 |
1 files changed, 9 insertions, 65 deletions
diff --git a/subsurfacesysinfo.cpp b/subsurfacesysinfo.cpp index 9855af819..f6577ede2 100644 --- a/subsurfacesysinfo.cpp +++ b/subsurfacesysinfo.cpp @@ -1,6 +1,8 @@ #include "subsurfacesysinfo.h" #include <QString> #include "qplatformdefs.h" +#include <QFile> +#include <QSettings> #ifdef Q_OS_UNIX #include <sys/utsname.h> @@ -318,73 +320,15 @@ static QString unquote(const char *begin, const char *end) static bool readEtcOsRelease(QUnixOSVersion &v) { - // we're avoiding QFile here - - int fd = QT_OPEN("/etc/os-release", O_RDONLY); - if (fd == -1) - return false; - - QT_STATBUF sbuf; - if (QT_FSTAT(fd, &sbuf) == -1) { - QT_CLOSE(fd); - return false; - } - - QString partialIdentifier; - QByteArray buffer(sbuf.st_size, Qt::Uninitialized); - buffer.resize(QT_READ(fd, buffer.data(), sbuf.st_size)); - QT_CLOSE(fd); - - const char *ptr = buffer.constData(); - const char *end = buffer.constEnd(); - const char *eol; - for ( ; ptr != end; ptr = eol + 1) { - static const char idString[] = "ID="; - static const char prettyNameString[] = "PRETTY_NAME="; - static const char versionIdString[] = "VERSION_ID="; - - // find the end of the line after ptr - eol = static_cast<const char *>(memchr(ptr, '\n', end - ptr)); - if (!eol) - eol = end - 1; - - int cmp = strncmp(ptr, idString, strlen(idString)); - if (cmp < 0) - continue; - if (cmp == 0) { - ptr += strlen(idString); - QString id = unquote(ptr, eol); - if (partialIdentifier.isNull()) - partialIdentifier = id; - else - v.versionIdentifier = id + QLatin1Char('_') + partialIdentifier; - continue; - } - - cmp = strncmp(ptr, prettyNameString, strlen(prettyNameString)); - if (cmp < 0) - continue; - if (cmp == 0) { - ptr += strlen(prettyNameString); - v.versionText = unquote(ptr, eol); - continue; - } - - cmp = strncmp(ptr, versionIdString, strlen(versionIdString)); - if (cmp < 0) - continue; - if (cmp == 0) { - ptr += strlen(versionIdString); - QString id = unquote(ptr, eol); - if (partialIdentifier.isNull()) - partialIdentifier = id; - else - v.versionIdentifier = partialIdentifier + QLatin1Char('_') + id; - continue; + QFile osRelease("/etc/os-release"); + if (osRelease.exists()) { + QSettings parse("/etc/os-release", QSettings::IniFormat); + if (parse.contains("PRETTY_NAME")) { + v.versionText = parse.value("PRETTY_NAME").toString(); } + return true; } - - return true; + return false; } #endif // USE_ETC_OS_RELEASE |