Bug 1284167 - /proc is unreliable on non-Linux. r?milan
MozReview-Commit-ID: 1B9bxjuRj6k
--- a/xpcom/base/nsSystemInfo.cpp
+++ b/xpcom/base/nsSystemInfo.cpp
@@ -27,16 +27,19 @@
#ifdef XP_MACOSX
#include "MacHelpers.h"
#endif
#ifdef MOZ_WIDGET_GTK
#include <gtk/gtk.h>
#include <dlfcn.h>
+#endif
+
+#if defined (XP_LINUX) && !defined (ANDROID)
#include <unistd.h>
#include <fstream>
#include "mozilla/Tokenizer.h"
#include "nsCharSeparatedTokenizer.h"
#include <map>
#include <string>
#endif
@@ -68,17 +71,17 @@ NS_EXPORT int android_sdk_version;
// Slot for NS_InitXPCOM2 to pass information to nsSystemInfo::Init.
// Only set to nonzero (potentially) if XP_UNIX. On such systems, the
// system call to discover the appropriate value is not thread-safe,
// so we must call it before going multithreaded, but nsSystemInfo::Init
// only happens well after that point.
uint32_t nsSystemInfo::gUserUmask = 0;
-#if defined (MOZ_WIDGET_GTK)
+#if defined (XP_LINUX) && !defined (ANDROID)
static void
SimpleParseKeyValuePairs(const std::string& aFilename,
std::map<nsCString, nsCString>& aKeyValuePairs)
{
std::ifstream input(aFilename.c_str());
for (std::string line; std::getline(input, line); ) {
nsAutoCString key, value;
@@ -492,17 +495,17 @@ nsSystemInfo::Init()
MOZ_ASSERT(sizeof(sysctlValue32) == len);
len = sizeof(sysctlValue32);
if (!sysctlbyname("machdep.cpu.stepping", &sysctlValue32, &len, NULL, 0)) {
cpuStepping = static_cast<int>(sysctlValue32);
}
MOZ_ASSERT(sizeof(sysctlValue32) == len);
-#elif defined (MOZ_WIDGET_GTK)
+#elif defined (XP_LINUX) && !defined (ANDROID)
// Get vendor, family, model, stepping, physical cores, L3 cache size
// from /proc/cpuinfo file
{
std::map<nsCString, nsCString> keyValuePairs;
SimpleParseKeyValuePairs("/proc/cpuinfo", keyValuePairs);
// cpuVendor from "vendor_id"
cpuVendor.Assign(keyValuePairs[NS_LITERAL_CSTRING("vendor_id")]);