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"
10 #include <sys/statvfs.h>
11 #include <sys/sysctl.h>
12 #include <sys/utsname.h>
15 #if !defined(OS_MACOSX)
19 #include "base/basictypes.h"
20 #include "base/file_util.h"
21 #include "base/logging.h"
22 #include "base/utf_string_conversions.h"
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
);
36 return static_cast<int>(res
);
41 int64
SysInfo::AmountOfFreeDiskSpace(const FilePath
& path
) {
43 if (statvfs(path
.value().c_str(), &stats
) != 0) {
46 return static_cast<int64
>(stats
.f_bavail
) * stats
.f_frsize
;
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
;
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());
60 return std::wstring();
62 return UTF8ToWide(value
);
67 std::string
SysInfo::OperatingSystemName() {
69 if (uname(&info
) < 0) {
73 return std::string(info
.sysname
);
77 std::string
SysInfo::OperatingSystemVersion() {
79 if (uname(&info
) < 0) {
83 return std::string(info
.release
);
87 std::string
SysInfo::CPUArchitecture() {
89 if (uname(&info
) < 0) {
93 return std::string(info
.machine
);
96 #if !defined(OS_MACOSX)
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();
103 *width
= gdk_screen_get_width(screen
);
105 *height
= gdk_screen_get_height(screen
);
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
);
121 size_t SysInfo::VMAllocationGranularity() {
122 return getpagesize();