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/lazy_instance.h"
16 #include "base/logging.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "base/sys_info_internal.h"
19 #include "base/threading/thread_restrictions.h"
21 #if defined(OS_ANDROID)
23 #define statvfs statfs // Android uses a statvfs-like statfs struct and call.
25 #include <sys/statvfs.h>
30 #if !defined(OS_OPENBSD)
31 int NumberOfProcessors() {
32 // It seems that sysconf returns the number of "logical" processors on both
33 // Mac and Linux. So we get the number of "online logical" processors.
34 long res
= sysconf(_SC_NPROCESSORS_ONLN
);
40 return static_cast<int>(res
);
44 base::internal::LazySysInfoValue
<int, NumberOfProcessors
> >::Leaky
45 g_lazy_number_of_processors
= LAZY_INSTANCE_INITIALIZER
;
52 #if !defined(OS_OPENBSD)
53 int SysInfo::NumberOfProcessors() {
54 return g_lazy_number_of_processors
.Get().value();
59 int64
SysInfo::AmountOfFreeDiskSpace(const FilePath
& path
) {
60 base::ThreadRestrictions::AssertIOAllowed();
63 if (HANDLE_EINTR(statvfs(path
.value().c_str(), &stats
)) != 0)
65 return static_cast<int64
>(stats
.f_bavail
) * stats
.f_frsize
;
68 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
70 std::string
SysInfo::OperatingSystemName() {
72 if (uname(&info
) < 0) {
76 return std::string(info
.sysname
);
80 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
82 std::string
SysInfo::OperatingSystemVersion() {
84 if (uname(&info
) < 0) {
88 return std::string(info
.release
);
93 std::string
SysInfo::OperatingSystemArchitecture() {
95 if (uname(&info
) < 0) {
99 std::string
arch(info
.machine
);
100 if (arch
== "i386" || arch
== "i486" || arch
== "i586" || arch
== "i686") {
102 } else if (arch
== "amd64") {
109 size_t SysInfo::VMAllocationGranularity() {
110 return getpagesize();