mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 04:25:33 -04:00
universal7885: libFileIO: switch to libbase log header and logformat
This commit is contained in:
parent
49c565abdb
commit
efa3468e1a
2 changed files with 11 additions and 10 deletions
|
|
@ -4,6 +4,7 @@ cc_library_shared {
|
||||||
cppflags: ["-fexceptions"],
|
cppflags: ["-fexceptions"],
|
||||||
local_include_dirs: ["include"],
|
local_include_dirs: ["include"],
|
||||||
export_include_dirs: ["include"],
|
export_include_dirs: ["include"],
|
||||||
shared_libs: ["liblog"],
|
shared_libs: ["libbase"],
|
||||||
|
header_libs: ["logformat"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#define LOG_TAG "libFileIO"
|
#include <android-base/logging.h>
|
||||||
|
|
||||||
#include <log/log.h>
|
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <LogFormat.h>
|
||||||
|
|
||||||
namespace FileIO {
|
namespace FileIO {
|
||||||
|
|
||||||
constexpr const int EXIT_ERR = -1;
|
constexpr const int EXIT_ERR = -1;
|
||||||
|
|
@ -13,20 +13,20 @@ int readline(const char *path) {
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
std::string value;
|
std::string value;
|
||||||
file.open(path);
|
file.open(path);
|
||||||
ALOGD("%s: Opening %s", __func__, path);
|
LOG(DEBUG) << make_str("%s: Opening %s", __func__, path);
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
getline(file, value);
|
getline(file, value);
|
||||||
file.close();
|
file.close();
|
||||||
} else {
|
} else {
|
||||||
ALOGE("%s: Failed to open %s", __func__, path);
|
LOG(ERROR) << make_str("%s: Failed to open %s", __func__, path);
|
||||||
return EXIT_ERR;
|
return EXIT_ERR;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return stoi(value);
|
return stoi(value);
|
||||||
} catch (std::invalid_argument const &ex) {
|
} catch (std::invalid_argument const &ex) {
|
||||||
ALOGE("%s: stoi(): invalid argument: for %s", __func__, value.c_str());
|
LOG(ERROR) << make_str("%s: stoi(): invalid argument: for %s", __func__, value.c_str());
|
||||||
} catch (std::out_of_range const &ex) {
|
} catch (std::out_of_range const &ex) {
|
||||||
ALOGE("%s: stoi(): out of range: for %s", __func__, value.c_str());
|
LOG(ERROR) << make_str("%s: stoi(): out of range: for %s", __func__, value.c_str());
|
||||||
}
|
}
|
||||||
return EXIT_ERR;
|
return EXIT_ERR;
|
||||||
}
|
}
|
||||||
|
|
@ -34,13 +34,13 @@ int readline(const char *path) {
|
||||||
void writeline(const char *path, const std::string& data) {
|
void writeline(const char *path, const std::string& data) {
|
||||||
std::ofstream file;
|
std::ofstream file;
|
||||||
file.open(path);
|
file.open(path);
|
||||||
ALOGD("%s: Opening %s, will write '%s'", __func__, path, data.c_str());
|
LOG(DEBUG) << make_str("%s: Opening %s, will write '%s'", __func__, path, data.c_str());
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
file << data;
|
file << data;
|
||||||
file.close();
|
file.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ALOGE("%s: Failed to open %s", __func__, path);
|
LOG(ERROR) << make_str("%s: Failed to open %s", __func__, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeline(const char *path, const int data) {
|
void writeline(const char *path, const int data) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue