summaryrefslogtreecommitdiffstats
path: root/base/sys_info_linux.cc
diff options
context:
space:
mode:
authorrobert.nagy@gmail.com <robert.nagy@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-24 22:05:27 +0000
committerrobert.nagy@gmail.com <robert.nagy@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-24 22:05:27 +0000
commit167ec827dfdc84e4bf6edb4f7b4921fec844920d (patch)
tree48fc2f571bd2e4a088aa80a9f023e54e4b667b43 /base/sys_info_linux.cc
parent03733f5cb43dcd6dddcdea179a28d2fb25a6b09b (diff)
downloadchromium_src-167ec827dfdc84e4bf6edb4f7b4921fec844920d.zip
chromium_src-167ec827dfdc84e4bf6edb4f7b4921fec844920d.tar.gz
chromium_src-167ec827dfdc84e4bf6edb4f7b4921fec844920d.tar.bz2
OpenBSD patches for base and build, part 2
base/base.gyp: - exclude test/test_file_util_linux.cc on OpenBSD because of missing fdatasync() base/base.gypi: - include linux_util.cc on OpenBSD too - exclude some linux specific files from the OpenBSD build because the openbsd implementation is different base/file_util_posix.cc: - Use file_util::GetTempDir directly to get the shm dir on !linux base/sys_info_freebsd.cc: - return 0 and do a NOTREACHED() in case sysctlbyname() fails base/sys_info_openbsd.cc: - cleanup includes - use arraysize() in the sysctl() call - implement SysInfo::MaxSharedMemorySize() build/common.gypi: - -Wno-deprecated is C++ only flag so move it to cflags_cc - Do not exclude linux specific files, dirs on OpenBSD since 90% of it is sharable base/sys_info_linux.cc: - DCHECK if the read string is empty - Use base::StringToInt64() to convert the string to an int64 - DCHECK if the returned int64 is okay for a size_t - call NOTREACHED() and return 0 if fails BUG= TEST=runs on linux? Review URL: http://codereview.chromium.org/8382001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106984 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sys_info_linux.cc')
-rw-r--r--base/sys_info_linux.cc23
1 files changed, 18 insertions, 5 deletions
diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc
index 67bfe5a6..03fdac2 100644
--- a/base/sys_info_linux.cc
+++ b/base/sys_info_linux.cc
@@ -1,11 +1,14 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/sys_info.h"
+#include <limits>
+
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/string_number_conversions.h"
namespace base {
@@ -22,15 +25,25 @@ int64 SysInfo::AmountOfPhysicalMemory() {
// static
size_t SysInfo::MaxSharedMemorySize() {
- static size_t limit;
+ static int64 limit;
static bool limit_valid = false;
if (!limit_valid) {
std::string contents;
file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents);
- limit = strtoul(contents.c_str(), NULL, 0);
- limit_valid = true;
+ DCHECK(!contents.empty());
+ if (!contents.empty() && contents[contents.length() - 1] == '\n') {
+ contents.erase(contents.length() - 1);
+ }
+ if (base::StringToInt64(contents, &limit)) {
+ DCHECK(limit >= 0);
+ DCHECK(static_cast<uint64>(limit) <= std::numeric_limits<size_t>::max());
+ limit_valid = true;
+ } else {
+ NOTREACHED();
+ return 0;
+ }
}
- return limit;
+ return static_cast<size_t>(limit);
}
} // namespace base