X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8bb6b2c057edbcc5b87f00a8af6ac70f6fd69727..85a94ef07bc7b67ce7c418bb672c51a0a54d6f73:/src/unix/utilsunx.cpp diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index d14a33a5e6..67a97b734a 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -891,12 +891,29 @@ bool wxGetUserName(wxChar *buf, int sz) return false; } +bool wxIsPlatform64Bit() +{ + wxString machine = wxGetCommandOutput(wxT("uname -m")); + + // NOTE: these tests are not 100% reliable! + return machine.Contains(wxT("AMD64")) || + machine.Contains(wxT("IA64")) || + machine.Contains(wxT("x64")) || + machine.Contains(wxT("X64")) || + machine.Contains(wxT("alpha")) || + machine.Contains(wxT("hppa64")) || + machine.Contains(wxT("ppc64")); +} + +// these functions are in mac/utils.cpp for wxMac +#ifndef __WXMAC__ + wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) { // get OS version int major, minor; wxString release = wxGetCommandOutput(wxT("uname -r")); - if ( !release.empty() && wxSscanf(release, "%d.%d", &major, &minor) != 2 ) + if ( !release.empty() && wxSscanf(release, wxT("%d.%d"), &major, &minor) != 2 ) { // unrecognized uname string format major = @@ -919,23 +936,6 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) return wxPlatformInfo::GetOperatingSystemId(kernel); } -bool wxIsPlatform64Bit() -{ - wxString machine = wxGetCommandOutput(wxT("uname -m")); - - // NOTE: these tests are not 100% reliable! - return machine.Contains(wxT("AMD64")) || - machine.Contains(wxT("IA64")) || - machine.Contains(wxT("x64")) || - machine.Contains(wxT("X64")) || - machine.Contains(wxT("alpha")) || - machine.Contains(wxT("hppa64")) || - machine.Contains(wxT("ppc64")); -} - -// this function is in mac/utils.cpp for wxMac -#ifndef __WXMAC__ - wxString wxGetOsDescription() { return wxGetCommandOutput(wxT("uname -s -r -m")); @@ -960,8 +960,31 @@ wxMemorySize wxGetFreeMemory() char buf[1024]; if ( fgets(buf, WXSIZEOF(buf), fp) && fgets(buf, WXSIZEOF(buf), fp) ) { - long memTotal, memUsed; - sscanf(buf, "Mem: %ld %ld %ld", &memTotal, &memUsed, &memFree); + // /proc/meminfo changed its format in kernel 2.6 + if ( wxPlatformInfo().CheckOSVersion(2, 6) ) + { + unsigned long cached, buffers; + sscanf(buf, "MemFree: %ld", &memFree); + + fgets(buf, WXSIZEOF(buf), fp); + sscanf(buf, "Buffers: %lu", &buffers); + + fgets(buf, WXSIZEOF(buf), fp); + sscanf(buf, "Cached: %lu", &cached); + + // add to "MemFree" also the "Buffers" and "Cached" values as + // free(1) does as otherwise the value never makes sense: for + // kernel 2.6 it's always almost 0 + memFree += buffers + cached; + + // values here are always expressed in kB and we want bytes + memFree *= 1024; + } + else // Linux 2.4 (or < 2.6, anyhow) + { + long memTotal, memUsed; + sscanf(buf, "Mem: %ld %ld %ld", &memTotal, &memUsed, &memFree); + } } fclose(fp);