universal7885: aidl-support: Add new signature for readline()

std::string readline(const char *)
This commit is contained in:
roynatech2544 2022-11-26 01:15:28 +09:00
commit 4ad9296609
2 changed files with 12 additions and 4 deletions

View file

@ -7,9 +7,9 @@
namespace FileIO { namespace FileIO {
constexpr const int EXIT_ERR = -1; constexpr int ERR = -1;
int readline(const char *path) { std::string readline(const char *path) {
std::ifstream file; std::ifstream file;
std::string value; std::string value;
file.open(path); file.open(path);
@ -19,8 +19,13 @@ int readline(const char *path) {
file.close(); file.close();
} else { } else {
LOG_E("%s: Failed to open %s", __func__, path); LOG_E("%s: Failed to open %s", __func__, path);
return EXIT_ERR; value = std::to_string(ERR);
} }
return value;
}
int readline(const char *path) {
const std::string value = readline(path);
try { try {
return stoi(value); return stoi(value);
} catch (std::invalid_argument const &ex) { } catch (std::invalid_argument const &ex) {
@ -28,7 +33,7 @@ int readline(const char *path) {
} catch (std::out_of_range const &ex) { } catch (std::out_of_range const &ex) {
LOG_E("%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; return ERR;
} }
void writeline(const char *path, const std::string& data) { void writeline(const char *path, const std::string& data) {

View file

@ -1,4 +1,7 @@
#include <string>
namespace FileIO { namespace FileIO {
std::string readline(const char *path);
int readline(const char *path); int readline(const char *path);
void writeline(const char *path, const std::string& data); void writeline(const char *path, const std::string& data);