OLD | NEW |
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 <sys/statvfs.h> |
| 11 #include <sys/utsname.h> |
11 #include <unistd.h> | 12 #include <unistd.h> |
12 | 13 |
13 #if defined(OS_MACOSX) | 14 #if defined(OS_MACOSX) |
14 #include <mach/mach_host.h> | 15 #include <mach/mach_host.h> |
15 #include <mach/mach_init.h> | 16 #include <mach/mach_init.h> |
16 #endif | 17 #endif |
17 | 18 |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
20 | 21 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 64 |
64 // static | 65 // static |
65 int64 SysInfo::AmountOfFreeDiskSpace(const std::wstring& path) { | 66 int64 SysInfo::AmountOfFreeDiskSpace(const std::wstring& path) { |
66 struct statvfs stats; | 67 struct statvfs stats; |
67 if (statvfs(WideToUTF8(path).c_str(), &stats) != 0) { | 68 if (statvfs(WideToUTF8(path).c_str(), &stats) != 0) { |
68 return -1; | 69 return -1; |
69 } | 70 } |
70 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; | 71 return static_cast<int64>(stats.f_bavail) * stats.f_frsize; |
71 } | 72 } |
72 | 73 |
| 74 // static |
| 75 bool SysInfo::HasEnvironmentVariable(const char* var) { |
| 76 return getenv(var) != NULL; |
| 77 } |
| 78 |
| 79 // static |
| 80 std::wstring SysInfo::GetEnvironmentVariable(const char* var) { |
| 81 char* value = getenv(var); |
| 82 if (!value) { |
| 83 return L""; |
| 84 } else { |
| 85 return UTF8ToWide(value); |
| 86 } |
| 87 } |
| 88 |
| 89 // static |
| 90 std::string SysInfo::OperatingSystemName() { |
| 91 utsname info; |
| 92 if (uname(&info) < 0) { |
| 93 NOTREACHED(); |
| 94 return ""; |
| 95 } |
| 96 return std::string(info.sysname); |
| 97 } |
| 98 |
| 99 // static |
| 100 std::string SysInfo::OperatingSystemVersion() { |
| 101 utsname info; |
| 102 if (uname(&info) < 0) { |
| 103 NOTREACHED(); |
| 104 return ""; |
| 105 } |
| 106 return std::string(info.release); |
| 107 } |
| 108 |
| 109 // static |
| 110 std::string SysInfo::CPUArchitecture() { |
| 111 utsname info; |
| 112 if (uname(&info) < 0) { |
| 113 NOTREACHED(); |
| 114 return ""; |
| 115 } |
| 116 return std::string(info.machine); |
| 117 } |
| 118 |
| 119 // static |
| 120 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { |
| 121 NOTIMPLEMENTED(); |
| 122 } |
| 123 |
| 124 // static |
| 125 int SysInfo::DisplayCount() { |
| 126 NOTIMPLEMENTED(); |
| 127 return 1; |
| 128 } |
| 129 |
73 } // namespace base | 130 } // namespace base |
OLD | NEW |