1 // Copyright (c) 2011 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/utsname.h>
13 #include "base/basictypes.h"
14 #include "base/file_util.h"
15 #include "base/logging.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "base/threading/thread_restrictions.h"
19 #if defined(OS_ANDROID)
21 #define statvfs statfs // Android uses a statvfs-like statfs struct and call.
23 #include <sys/statvfs.h>
28 #if !defined(OS_OPENBSD)
29 int SysInfo::NumberOfProcessors() {
30 // It seems that sysconf returns the number of "logical" processors on both
31 // Mac and Linux. So we get the number of "online logical" processors.
32 long res = sysconf(_SC_NPROCESSORS_ONLN);
38 return static_cast<int>(res);
43 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
44 base::ThreadRestrictions::AssertIOAllowed();
47 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0)
49 return static_cast<int64>(stats.f_bavail) * stats.f_frsize;
52 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
54 std::string SysInfo::OperatingSystemName() {
56 if (uname(&info) < 0) {
60 return std::string(info.sysname);
64 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
66 std::string SysInfo::OperatingSystemVersion() {
68 if (uname(&info) < 0) {
72 return std::string(info.release);
77 std::string SysInfo::OperatingSystemArchitecture() {
79 if (uname(&info) < 0) {
83 std::string arch(info.machine);
84 if (arch == "i386" || arch == "i486" || arch == "i586" || arch == "i686") {
86 } else if (arch == "amd64") {
93 size_t SysInfo::VMAllocationGranularity() {