blob: 73a71086362ca33e60230a50f624e9fe43593a09 [file] [log] [blame]
[email protected]6e001bb2011-05-25 20:53:181// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]2a758d612008-09-17 10:09:392// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/sys_info.h"
6
7#include <errno.h>
8#include <string.h>
[email protected]e43eddf12009-12-29 00:32:529#include <sys/param.h>
[email protected]05f9b682008-09-29 22:18:0110#include <sys/utsname.h>
[email protected]2a758d612008-09-17 10:09:3911#include <unistd.h>
12
[email protected]047a03f2009-10-07 02:10:2013#include "base/basictypes.h"
14#include "base/file_util.h"
[email protected]2a758d612008-09-17 10:09:3915#include "base/logging.h"
[email protected]dda29c942012-08-21 19:50:0316#include "base/threading/thread_restrictions.h"
[email protected]047a03f2009-10-07 02:10:2017#include "base/utf_string_conversions.h"
[email protected]2a758d612008-09-17 10:09:3918
[email protected]f7d69972011-06-21 22:34:5019#if defined(OS_ANDROID)
20#include <sys/vfs.h>
21#define statvfs statfs // Android uses a statvfs-like statfs struct and call.
22#else
23#include <sys/statvfs.h>
[email protected]f7d69972011-06-21 22:34:5024#endif
25
[email protected]2a758d612008-09-17 10:09:3926namespace base {
27
[email protected]5f5ac6a2009-11-23 21:57:1128#if !defined(OS_OPENBSD)
[email protected]2a758d612008-09-17 10:09:3929int SysInfo::NumberOfProcessors() {
30 // It seems that sysconf returns the number of "logical" processors on both
[email protected]5f5ac6a2009-11-23 21:57:1131 // Mac and Linux. So we get the number of "online logical" processors.
[email protected]0203ed72009-07-02 13:59:0832 long res = sysconf(_SC_NPROCESSORS_ONLN);
[email protected]2a758d612008-09-17 10:09:3933 if (res == -1) {
34 NOTREACHED();
35 return 1;
36 }
37
38 return static_cast<int>(res);
[email protected]d632798e2008-09-17 13:10:4539}
[email protected]c8587632009-11-12 02:17:1940#endif
[email protected]d632798e2008-09-17 13:10:4541
[email protected]0e91dd22008-09-18 12:34:2442// static
[email protected]13326bb2009-10-14 00:41:5643int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
[email protected]dda29c942012-08-21 19:50:0344 base::ThreadRestrictions::AssertIOAllowed();
45
[email protected]0e91dd22008-09-18 12:34:2446 struct statvfs stats;
[email protected]13326bb2009-10-14 00:41:5647 if (statvfs(path.value().c_str(), &stats) != 0) {
[email protected]02ee34a2008-09-20 01:16:2348 return -1;
[email protected]0e91dd22008-09-18 12:34:2449 }
50 return static_cast<int64>(stats.f_bavail) * stats.f_frsize;
51}
52
[email protected]6e001bb2011-05-25 20:53:1853#if !defined(OS_MACOSX)
[email protected]05f9b682008-09-29 22:18:0154// static
[email protected]05f9b682008-09-29 22:18:0155std::string SysInfo::OperatingSystemName() {
[email protected]94f8c952011-06-25 04:54:4156 struct utsname info;
[email protected]05f9b682008-09-29 22:18:0157 if (uname(&info) < 0) {
58 NOTREACHED();
59 return "";
60 }
61 return std::string(info.sysname);
62}
63
64// static
65std::string SysInfo::OperatingSystemVersion() {
[email protected]94f8c952011-06-25 04:54:4166 struct utsname info;
[email protected]05f9b682008-09-29 22:18:0167 if (uname(&info) < 0) {
68 NOTREACHED();
69 return "";
70 }
71 return std::string(info.release);
72}
[email protected]6e001bb2011-05-25 20:53:1873#endif
[email protected]05f9b682008-09-29 22:18:0174
75// static
76std::string SysInfo::CPUArchitecture() {
[email protected]94f8c952011-06-25 04:54:4177 struct utsname info;
[email protected]05f9b682008-09-29 22:18:0178 if (uname(&info) < 0) {
79 NOTREACHED();
80 return "";
81 }
[email protected]56d0cef2012-09-26 02:49:4282 std::string arch(info.machine);
83 if (arch == "i386" || arch == "i486" || arch == "i586" || arch == "i686") {
84 arch = "x86";
85 } else if (arch == "amd64") {
86 arch = "x86_64";
87 }
88 return arch;
[email protected]05f9b682008-09-29 22:18:0189}
90
[email protected]037fce02009-01-22 01:42:1591// static
92size_t SysInfo::VMAllocationGranularity() {
93 return getpagesize();
94}
95
[email protected]2a758d612008-09-17 10:09:3996} // namespace base