universal7885: parts-hidl: Use libFileIO

- Also fix compile errors
This commit is contained in:
roynatech2544 2022-10-03 18:39:01 +09:00
commit 3e5e571267
15 changed files with 150 additions and 210 deletions

View file

@ -1,7 +1,9 @@
cc_library_shared {
name: "libfileio",
srcs: ["FileIO.cpp"],
include_dirs: ["include"],
cppflags: ["-fexceptions"],
local_include_dirs: ["include"],
export_include_dirs: ["include"],
shared_libs: ["liblog"],
}

View file

@ -25,15 +25,14 @@ int readline(const char *path) {
try {
return stoi(value);
} catch (std::invalid_argument const &ex) {
ALOGE("%s: stoi(): invalid argument: for %s", __func__, value);
ALOGE("%s: stoi(): invalid argument: for %s", __func__, value.c_str());
} catch (std::out_of_range const &ex) {
ALOGE("%s: stoi(): out of range: for %s", __func__, value);
ALOGE("%s: stoi(): out of range: for %s", __func__, value.c_str());
}
return EXIT_ERR;
}
template <typename T>
void writeline(const char *path, const T data) {
void writeline(const char *path, const std::string& data) {
std::ofstream file;
file.open(path);
ALOGD("%s: Opening %s", __func__, path);
@ -45,4 +44,8 @@ void writeline(const char *path, const T data) {
ALOGE("%s: Failed to open %s", __func__, path);
}
void writeline(const char *path, const int data) {
writeline(path, std::to_string(data));
}
} // namespace FileIO

View file

@ -1,6 +1,6 @@
namespace FileIO {
int readline(const char *path);
template <typename T>
void writeline(const char *path, const T data);
void writeline(const char *path, const std::string& data);
void writeline(const char *path, const int data);
} // namespace FileIO