| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/sys_info.h" | 5 #include "base/sys_info.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 NOTREACHED(); | 66 NOTREACHED(); |
| 67 return 0; | 67 return 0; |
| 68 } | 68 } |
| 69 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur; | 69 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur; |
| 70 } | 70 } |
| 71 | 71 |
| 72 base::LazyInstance< | 72 base::LazyInstance< |
| 73 base::internal::LazySysInfoValue<int64_t, AmountOfVirtualMemory>>::Leaky | 73 base::internal::LazySysInfoValue<int64_t, AmountOfVirtualMemory>>::Leaky |
| 74 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; | 74 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; |
| 75 | 75 |
| 76 bool GetDiskSpaceInfo(const base::FilePath& path, |
| 77 int64_t* available_bytes, |
| 78 int64_t* total_bytes) { |
| 79 struct statvfs stats; |
| 80 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) |
| 81 return false; |
| 82 |
| 83 if (available_bytes) |
| 84 *available_bytes = static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; |
| 85 if (total_bytes) |
| 86 *total_bytes = static_cast<int64_t>(stats.f_blocks) * stats.f_frsize; |
| 87 return true; |
| 88 } |
| 89 |
| 76 } // namespace | 90 } // namespace |
| 77 | 91 |
| 78 namespace base { | 92 namespace base { |
| 79 | 93 |
| 80 #if !defined(OS_OPENBSD) | 94 #if !defined(OS_OPENBSD) |
| 81 int SysInfo::NumberOfProcessors() { | 95 int SysInfo::NumberOfProcessors() { |
| 82 return g_lazy_number_of_processors.Get().value(); | 96 return g_lazy_number_of_processors.Get().value(); |
| 83 } | 97 } |
| 84 #endif | 98 #endif |
| 85 | 99 |
| 86 // static | 100 // static |
| 87 int64_t SysInfo::AmountOfVirtualMemory() { | 101 int64_t SysInfo::AmountOfVirtualMemory() { |
| 88 return g_lazy_virtual_memory.Get().value(); | 102 return g_lazy_virtual_memory.Get().value(); |
| 89 } | 103 } |
| 90 | 104 |
| 91 // static | 105 // static |
| 92 int64_t SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { | 106 int64_t SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
| 93 base::ThreadRestrictions::AssertIOAllowed(); | 107 base::ThreadRestrictions::AssertIOAllowed(); |
| 94 | 108 |
| 95 struct statvfs stats; | 109 int64_t available; |
| 96 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) | 110 if (!GetDiskSpaceInfo(path, &available, nullptr)) |
| 97 return -1; | 111 return -1; |
| 98 return static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; | 112 return available; |
| 113 } |
| 114 |
| 115 // static |
| 116 int64_t SysInfo::AmountOfTotalDiskSpace(const FilePath& path) { |
| 117 base::ThreadRestrictions::AssertIOAllowed(); |
| 118 |
| 119 int64_t total; |
| 120 if (!GetDiskSpaceInfo(path, nullptr, &total)) |
| 121 return -1; |
| 122 return total; |
| 99 } | 123 } |
| 100 | 124 |
| 101 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 125 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 102 // static | 126 // static |
| 103 std::string SysInfo::OperatingSystemName() { | 127 std::string SysInfo::OperatingSystemName() { |
| 104 struct utsname info; | 128 struct utsname info; |
| 105 if (uname(&info) < 0) { | 129 if (uname(&info) < 0) { |
| 106 NOTREACHED(); | 130 NOTREACHED(); |
| 107 return std::string(); | 131 return std::string(); |
| 108 } | 132 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 137 } | 161 } |
| 138 return arch; | 162 return arch; |
| 139 } | 163 } |
| 140 | 164 |
| 141 // static | 165 // static |
| 142 size_t SysInfo::VMAllocationGranularity() { | 166 size_t SysInfo::VMAllocationGranularity() { |
| 143 return getpagesize(); | 167 return getpagesize(); |
| 144 } | 168 } |
| 145 | 169 |
| 146 } // namespace base | 170 } // namespace base |
| OLD | NEW |