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/resource.h>
11 #include <sys/utsname.h>
14 #include "base/basictypes.h"
15 #include "base/file_util.h"
16 #include "base/lazy_instance.h"
17 #include "base/logging.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/sys_info_internal.h"
20 #include "base/threading/thread_restrictions.h"
22 #if defined(OS_ANDROID)
24 #define statvfs statfs // Android uses a statvfs-like statfs struct and call.
26 #include <sys/statvfs.h>
31 #if !defined(OS_OPENBSD)
32 int NumberOfProcessors() {
33 // It seems that sysconf returns the number of "logical" processors on both
34 // Mac and Linux. So we get the number of "online logical" processors.
35 long res
= sysconf(_SC_NPROCESSORS_ONLN
);
41 return static_cast<int>(res
);
45 base::internal::LazySysInfoValue
<int, NumberOfProcessors
> >::Leaky
46 g_lazy_number_of_processors
= LAZY_INSTANCE_INITIALIZER
;
49 int64
AmountOfVirtualMemory() {
51 int result
= getrlimit(RLIMIT_DATA
, &limit
);
56 return limit
.rlim_cur
== RLIM_INFINITY
? 0 : limit
.rlim_cur
;
60 base::internal::LazySysInfoValue
<int64
, AmountOfVirtualMemory
> >::Leaky
61 g_lazy_virtual_memory
= LAZY_INSTANCE_INITIALIZER
;
67 #if !defined(OS_OPENBSD)
68 int SysInfo::NumberOfProcessors() {
69 return g_lazy_number_of_processors
.Get().value();
74 int64
SysInfo::AmountOfVirtualMemory() {
75 return g_lazy_virtual_memory
.Get().value();
79 int64
SysInfo::AmountOfFreeDiskSpace(const FilePath
& path
) {
80 base::ThreadRestrictions::AssertIOAllowed();
83 if (HANDLE_EINTR(statvfs(path
.value().c_str(), &stats
)) != 0)
85 return static_cast<int64
>(stats
.f_bavail
) * stats
.f_frsize
;
88 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
90 std::string
SysInfo::OperatingSystemName() {
92 if (uname(&info
) < 0) {
96 return std::string(info
.sysname
);
100 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
102 std::string
SysInfo::OperatingSystemVersion() {
104 if (uname(&info
) < 0) {
106 return std::string();
108 return std::string(info
.release
);
113 std::string
SysInfo::OperatingSystemArchitecture() {
115 if (uname(&info
) < 0) {
117 return std::string();
119 std::string
arch(info
.machine
);
120 if (arch
== "i386" || arch
== "i486" || arch
== "i586" || arch
== "i686") {
122 } else if (arch
== "amd64") {
129 size_t SysInfo::VMAllocationGranularity() {
130 return getpagesize();