Detect micro version for Unix-like systems in wxGetOsVersion

Check the result of running uname -r for a micro version and use it if
available, otherwise return a micro version of 0.
This commit is contained in:
Dimitri Schoolwerth
2015-06-24 06:45:56 +04:00
committed by Tobias Taschner
parent b1a9c6e79e
commit 427750e744
2 changed files with 16 additions and 10 deletions

View File

@@ -851,9 +851,10 @@ wxString wxGetOsDescription();
On systems where only the micro version can't be detected or doesn't make On systems where only the micro version can't be detected or doesn't make
sense such as Windows, it will have a value of 0. sense such as Windows, it will have a value of 0.
For Unix-like systems (@c wxOS_UNIX) the major and minor version integers will For Unix-like systems (@c wxOS_UNIX) the major, minor, and micro version
contain the kernel major and minor version numbers (as returned by the integers will contain the kernel's major, minor, and micro version
'uname -r' command); e.g. "4" and "1" if the machine is using kernel 4.1.4. numbers (as returned by the 'uname -r' command); e.g. "4", "1", and "4" if
the machine is using kernel 4.1.4.
For OS X systems (@c wxOS_MAC) the major and minor version integers are the For OS X systems (@c wxOS_MAC) the major and minor version integers are the
natural version numbers associated with the OS; e.g. "10", "11" and "2" if natural version numbers associated with the OS; e.g. "10", "11" and "2" if

View File

@@ -1117,14 +1117,19 @@ wxLinuxDistributionInfo wxGetLinuxDistributionInfo()
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro) wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro)
{ {
// get OS version // get OS version
int major, minor; int major = -1, minor = -1, micro = -1;
wxString release = wxGetCommandOutput(wxT("uname -r")); wxString release = wxGetCommandOutput(wxT("uname -r"));
if ( release.empty() || if ( !release.empty() )
wxSscanf(release.c_str(), wxT("%d.%d"), &major, &minor) != 2 )
{ {
// failed to get version string or unrecognized format if ( wxSscanf(release.c_str(), wxT("%d.%d.%d"), &major, &minor, &micro ) != 3 )
major = {
minor = -1; micro = 0;
if ( wxSscanf(release.c_str(), wxT("%d.%d"), &major, &minor ) != 2 )
{
// failed to get version string or unrecognized format
major = minor = micro = -1;
}
}
} }
if ( verMaj ) if ( verMaj )
@@ -1132,7 +1137,7 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro)
if ( verMin ) if ( verMin )
*verMin = minor; *verMin = minor;
if ( verMicro ) if ( verMicro )
*verMicro = (major == -1) ? -1 : 0; *verMicro = micro;
// try to understand which OS are we running // try to understand which OS are we running
wxString kernel = wxGetCommandOutput(wxT("uname -s")); wxString kernel = wxGetCommandOutput(wxT("uname -s"));