blob: d45aaa3e1fda10575d6b84bfe853d16422dbb2a4 [file] [log] [blame]
// Copyright 2020 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.
#include "typecd/utils.h"
#include <string>
#include <base/files/file_util.h>
#include <base/strings/string_number_conversions.h>
#include <base/strings/string_util.h>
namespace typecd {
bool ReadHexFromPath(const base::FilePath& path, uint32_t* val) {
std::string val_str;
if (!base::ReadFileToString(path, &val_str)) {
LOG(ERROR) << "Couldn't read value from path " << path;
return false;
}
base::TrimWhitespaceASCII(val_str, base::TRIM_TRAILING, &val_str);
if (!base::HexStringToUInt(val_str.c_str(), val)) {
LOG(ERROR) << "Error parsing hex value: " << val_str;
return false;
}
return true;
}
} // namespace typecd