OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // Defines the PlatformReader base class. By default, it will read an integer |
| 6 // from a file and assigned it to a PlatformValue which is |
| 7 // implementation-specific. |
| 8 |
| 9 #include "platform_reader.h" |
| 10 |
| 11 #include <sys/types.h> |
| 12 |
| 13 namespace cros_boot_mode { |
| 14 |
| 15 PlatformReader::PlatformReader() : |
| 16 value_(kUnsupported), platform_file_path_(NULL) { } |
| 17 |
| 18 PlatformReader::~PlatformReader() { } |
| 19 |
| 20 const char *PlatformReader::platform_file_path() const { |
| 21 if (platform_file_path_) |
| 22 return platform_file_path_; |
| 23 return default_platform_file_path(); |
| 24 } |
| 25 |
| 26 void PlatformReader::Initialize() { |
| 27 char *buf = new char[max_size() + 1]; |
| 28 size_t bytes_read = helpers::read_file(platform_file_path(), |
| 29 buf, |
| 30 max_size()); |
| 31 // read_file doesn't NUL-terminate. |
| 32 buf[bytes_read] = '\0'; |
| 33 set_value(Process(buf, bytes_read)); |
| 34 delete [] buf; |
| 35 } |
| 36 |
| 37 } // namespace cros_boot_mode |
OLD | NEW |