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

Unified Diff: platform_reader.cc

Issue 3530001: first cut: establishes base helper classes and main (Closed) Base URL: http://git.chromium.org/git/cros_boot_mode.git
Patch Set: truncation is bad, m'kay. . . Created 10 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « platform_reader.h ('k') | platform_switch.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: platform_reader.cc
diff --git a/platform_reader.cc b/platform_reader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..81519c69bbcc73d9964da6b1ae0ec763a2fdcd91
--- /dev/null
+++ b/platform_reader.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Defines the PlatformReader base class. By default, it will read an integer
+// from a file and assigned it to a PlatformValue which is
+// implementation-specific.
+
+#include "platform_reader.h"
+
+#include <sys/types.h>
+
+namespace cros_boot_mode {
+
+PlatformReader::PlatformReader() :
+ value_(kUnsupported), platform_file_path_(NULL) { }
+
+PlatformReader::~PlatformReader() { }
+
+const char *PlatformReader::platform_file_path() const {
+ if (platform_file_path_)
+ return platform_file_path_;
+ return default_platform_file_path();
+}
+
+void PlatformReader::Initialize() {
+ char *buf = new char[max_size() + 1];
+ size_t bytes_read = helpers::read_file(platform_file_path(),
+ buf,
+ max_size());
+ // read_file doesn't NUL-terminate.
+ buf[bytes_read] = '\0';
+ set_value(Process(buf, bytes_read));
+ delete [] buf;
+}
+
+} // namespace cros_boot_mode
« no previous file with comments | « platform_reader.h ('k') | platform_switch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698