universal7885: aidl-support: Adapt to liblogfmt changes

This commit is contained in:
roynatech2544 2022-11-01 13:28:00 +09:00
commit 8957783333
3 changed files with 15 additions and 16 deletions

View file

@ -1,7 +1,5 @@
#define LOG_TAG "libFileIO"
#include <log/log.h>
#include <fstream>
#include <string>
@ -15,20 +13,20 @@ int readline(const char *path) {
std::ifstream file;
std::string value;
file.open(path);
ALOGD(make_str("%s: Opening %s", __func__, path));
LOG_D("%s: Opening %s", __func__, path);
if (file.is_open()) {
getline(file, value);
file.close();
} else {
ALOGE(make_str("%s: Failed to open %s", __func__, path));
LOG_E("%s: Failed to open %s", __func__, path);
return EXIT_ERR;
}
try {
return stoi(value);
} catch (std::invalid_argument const &ex) {
ALOGE(make_str("%s: stoi(): invalid argument: for %s", __func__, value.c_str()));
LOG_E("%s: stoi(): invalid argument: for %s", __func__, value.c_str());
} catch (std::out_of_range const &ex) {
ALOGE(make_str("%s: stoi(): out of range: for %s", __func__, value.c_str()));
LOG_E("%s: stoi(): out of range: for %s", __func__, value.c_str());
}
return EXIT_ERR;
}
@ -36,13 +34,13 @@ int readline(const char *path) {
void writeline(const char *path, const std::string& data) {
std::ofstream file;
file.open(path);
ALOGD(make_str("%s: Opening %s, will write '%s'", __func__, path, data.c_str()));
LOG_D("%s: Opening %s, will write '%s'", __func__, path, data.c_str());
if (file.is_open()) {
file << data;
file.close();
return;
}
ALOGE(make_str("%s: Failed to open %s", __func__, path));
LOG_E("%s: Failed to open %s", __func__, path);
}
void writeline(const char *path, const int data) {