Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: base/sys_info_posix.cc

Issue 3141: Move GetFreeDiskSpace to SysInfo. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/sys_info.h ('k') | base/sys_info_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 #include "base/basictypes.h" 6 #include "base/basictypes.h"
7 7
8 #include <errno.h> 8 #include <errno.h>
9 #include <string.h> 9 #include <string.h>
10 #include <sys/statvfs.h>
10 #include <unistd.h> 11 #include <unistd.h>
11 12
12 #if defined(OS_MACOSX) 13 #if defined(OS_MACOSX)
13 #include <mach/mach_host.h> 14 #include <mach/mach_host.h>
14 #include <mach/mach_init.h> 15 #include <mach/mach_init.h>
15 #endif 16 #endif
16 17
17 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/string_util.h"
18 20
19 namespace base { 21 namespace base {
20 22
21 int SysInfo::NumberOfProcessors() { 23 int SysInfo::NumberOfProcessors() {
22 // It seems that sysconf returns the number of "logical" processors on both 24 // It seems that sysconf returns the number of "logical" processors on both
23 // mac and linux. So we get the number of "online logical" processors. 25 // mac and linux. So we get the number of "online logical" processors.
24 long res = sysconf(_SC_NPROCESSORS_ONLN); 26 long res = sysconf(_SC_NPROCESSORS_ONLN);
25 if (res == -1) { 27 if (res == -1) {
26 NOTREACHED(); 28 NOTREACHED();
27 return 1; 29 return 1;
(...skipping 24 matching lines...) Expand all
52 long page_size = sysconf(_SC_PAGE_SIZE); 54 long page_size = sysconf(_SC_PAGE_SIZE);
53 if (pages == -1 || page_size == -1) { 55 if (pages == -1 || page_size == -1) {
54 NOTREACHED(); 56 NOTREACHED();
55 return 0; 57 return 0;
56 } 58 }
57 59
58 return static_cast<int64>(pages) * page_size; 60 return static_cast<int64>(pages) * page_size;
59 #endif 61 #endif
60 } 62 }
61 63
64 // static
65 int64 SysInfo::AmountOfFreeDiskSpace(const std::wstring& path) {
66 struct statvfs stats;
67 if (statvfs(WideToUTF8(path).c_str(), &stats) != 0) {
68 return 0;
69 }
70 return static_cast<int64>(stats.f_bavail) * stats.f_frsize;
71 }
72
62 } // namespace base 73 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info.h ('k') | base/sys_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698