Tweak/Wontfix a few tests that we could care less about.
[chromium-blink-merge.git] / base / sys_info_posix.cc
blobb2526ba691b6887d2225dfc0d2669f15bc9e45e5
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/sys_info.h"
7 #include <errno.h>
8 #include <string.h>
9 #include <sys/param.h>
10 #include <sys/statvfs.h>
11 #include <sys/sysctl.h>
12 #include <sys/utsname.h>
13 #include <unistd.h>
15 #if !defined(OS_MACOSX)
16 #include <gdk/gdk.h>
17 #endif
19 #include "base/basictypes.h"
20 #include "base/file_util.h"
21 #include "base/logging.h"
22 #include "base/utf_string_conversions.h"
24 namespace base {
26 #if !defined(OS_OPENBSD)
27 int SysInfo::NumberOfProcessors() {
28 // It seems that sysconf returns the number of "logical" processors on both
29 // Mac and Linux. So we get the number of "online logical" processors.
30 long res = sysconf(_SC_NPROCESSORS_ONLN);
31 if (res == -1) {
32 NOTREACHED();
33 return 1;
36 return static_cast<int>(res);
38 #endif
40 // static
41 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
42 struct statvfs stats;
43 if (statvfs(path.value().c_str(), &stats) != 0) {
44 return -1;
46 return static_cast<int64>(stats.f_bavail) * stats.f_frsize;
49 // static
50 bool SysInfo::HasEnvVar(const wchar_t* var) {
51 std::string var_utf8 = WideToUTF8(std::wstring(var));
52 return getenv(var_utf8.c_str()) != NULL;
55 // static
56 std::wstring SysInfo::GetEnvVar(const wchar_t* var) {
57 std::string var_utf8 = WideToUTF8(std::wstring(var));
58 char* value = getenv(var_utf8.c_str());
59 if (!value) {
60 return std::wstring();
61 } else {
62 return UTF8ToWide(value);
66 // static
67 std::string SysInfo::OperatingSystemName() {
68 utsname info;
69 if (uname(&info) < 0) {
70 NOTREACHED();
71 return "";
73 return std::string(info.sysname);
76 // static
77 std::string SysInfo::OperatingSystemVersion() {
78 utsname info;
79 if (uname(&info) < 0) {
80 NOTREACHED();
81 return "";
83 return std::string(info.release);
86 // static
87 std::string SysInfo::CPUArchitecture() {
88 utsname info;
89 if (uname(&info) < 0) {
90 NOTREACHED();
91 return "";
93 return std::string(info.machine);
96 #if !defined(OS_MACOSX)
97 // static
98 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) {
99 // Note that Bad Things Happen if this isn't called from the UI thread,
100 // but also that there's no way to check that from here. :(
101 GdkScreen* screen = gdk_screen_get_default();
102 if (width)
103 *width = gdk_screen_get_width(screen);
104 if (height)
105 *height = gdk_screen_get_height(screen);
108 // static
109 int SysInfo::DisplayCount() {
110 // Note that Bad Things Happen if this isn't called from the UI thread,
111 // but also that there's no way to check that from here. :(
113 // This query is kinda bogus for Linux -- do we want number of X screens?
114 // The number of monitors Xinerama has? We'll just use whatever GDK uses.
115 GdkScreen* screen = gdk_screen_get_default();
116 return gdk_screen_get_n_monitors(screen);
118 #endif
120 // static
121 size_t SysInfo::VMAllocationGranularity() {
122 return getpagesize();
125 } // namespace base