From 4e8680e2316458f158e28e9936de2737e480719c Mon Sep 17 00:00:00 2001 From: Tomas Pecka <peckato1@fit.cvut.cz> Date: Wed, 26 Jan 2022 17:39:10 +0100 Subject: [PATCH] aql: Simplify HOME env var handling --- aql2/src/aql.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/aql2/src/aql.cpp b/aql2/src/aql.cpp index 6ab6ad61d1..be2832c93f 100644 --- a/aql2/src/aql.cpp +++ b/aql2/src/aql.cpp @@ -97,10 +97,14 @@ int main ( int argc, char * argv[] ) { exceptions.push_back ( exception.error ( ) ); } ); - const char* envHome = std::getenv ( "HOME" ); + std::optional < std::filesystem::path > envHomePath; + if ( auto *env = std::getenv ( "HOME" ) ) { + envHomePath = std::string ( env ); + } + std::unique_ptr < ReadlinePromptHistory > historyHandler; - if ( envHome != nullptr ) { - historyHandler = std::make_unique < ReadlinePromptHistory > ( std::string ( envHome ) + "/.aql_history" ); + if ( envHomePath ) { + historyHandler = std::make_unique < ReadlinePromptHistory > ( envHomePath.value ( ) / ".aql_history" ); } try { -- GitLab