blob: 83be03c605b94f1c0d6f5282126d75ae92178778 [file] [log] [blame]
Kevin Linc6615ae2020-11-11 19:36:59 +08001// Copyright 2021 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#include "runtime_probe/system_property_impl.h"
6
7#include <string>
8
9#include <vboot/crossystem.h>
10
Kevin Lina6779a02021-03-12 19:28:43 +080011namespace runtime_probe {
12
Kevin Linc6615ae2020-11-11 19:36:59 +080013bool SystemPropertyImpl::GetInt(const std::string& key, int* value_out) {
14 int value = ::VbGetSystemPropertyInt(key.c_str());
15 if (value == -1)
16 return false;
17 *value_out = value;
18 return true;
19}
20
21bool SystemPropertyImpl::SetInt(const std::string& key, int value) {
22 return 0 == ::VbSetSystemPropertyInt(key.c_str(), value);
23}
24
25bool SystemPropertyImpl::GetString(const std::string& key,
26 std::string* value_out) {
27 char buf[VB_MAX_STRING_PROPERTY];
28 if (::VbGetSystemPropertyString(key.c_str(), buf, sizeof(buf)) == nullptr)
29 return false;
30 *value_out = std::string(buf);
31 return true;
32}
33
34bool SystemPropertyImpl::SetString(const std::string& key,
35 const std::string& value) {
36 return 0 == ::VbSetSystemPropertyString(key.c_str(), value.c_str());
37}
Kevin Lina6779a02021-03-12 19:28:43 +080038
39} // namespace runtime_probe