WebKit roll 98705:98715
[chromium-blink-merge.git] / base / sys_info_posix.cc
blob4d7cc4e311231b5d24e794d4d83394f923718b66
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"
7 #include <errno.h>
8 #include <string.h>
9 #include <sys/param.h>
10 #include <sys/utsname.h>
11 #include <unistd.h>
13 #include "base/basictypes.h"
14 #include "base/file_util.h"
15 #include "base/logging.h"
16 #include "base/utf_string_conversions.h"
18 #if defined(OS_ANDROID)
19 #include <sys/vfs.h>
20 #define statvfs statfs // Android uses a statvfs-like statfs struct and call.
21 #else
22 #include <sys/statvfs.h>
23 #endif
25 namespace base {
27 #if !defined(OS_OPENBSD)
28 int SysInfo::NumberOfProcessors() {
29 // It seems that sysconf returns the number of "logical" processors on both
30 // Mac and Linux. So we get the number of "online logical" processors.
31 long res = sysconf(_SC_NPROCESSORS_ONLN);
32 if (res == -1) {
33 NOTREACHED();
34 return 1;
37 return static_cast<int>(res);
39 #endif
41 // static
42 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
43 struct statvfs stats;
44 if (statvfs(path.value().c_str(), &stats) != 0) {
45 return -1;
47 return static_cast<int64>(stats.f_bavail) * stats.f_frsize;
50 #if !defined(OS_MACOSX)
51 // static
52 std::string SysInfo::OperatingSystemName() {
53 struct utsname info;
54 if (uname(&info) < 0) {
55 NOTREACHED();
56 return "";
58 return std::string(info.sysname);
61 // static
62 std::string SysInfo::OperatingSystemVersion() {
63 struct utsname info;
64 if (uname(&info) < 0) {
65 NOTREACHED();
66 return "";
68 return std::string(info.release);
70 #endif
72 // static
73 std::string SysInfo::CPUArchitecture() {
74 struct utsname info;
75 if (uname(&info) < 0) {
76 NOTREACHED();
77 return "";
79 return std::string(info.machine);
82 // static
83 size_t SysInfo::VMAllocationGranularity() {
84 return getpagesize();
87 } // namespace base