aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/prompt.cc5
-rw-r--r--src/util/string.cc5
2 files changed, 7 insertions, 3 deletions
diff --git a/src/util/prompt.cc b/src/util/prompt.cc
index 08ff7e4..92ce2ce 100644
--- a/src/util/prompt.cc
+++ b/src/util/prompt.cc
@@ -13,12 +13,11 @@ namespace ov4
{
char hostname[MAXLINE];
gethostname(hostname, MAXLINE);
- char *user = getlogin();
cout
<< make_color((string)name, ov4::color::bright_green)
<< " "
- << make_color((user != nullptr ? user : "ov4"), ov4::color::bright_blue)
+ << make_color(safe_str(getlogin()) , ov4::color::bright_blue)
<< make_color("@", ov4::color::bright_blue)
<< make_color(hostname, ov4::color::bright_blue)
<< ":"
@@ -32,6 +31,6 @@ namespace ov4
string get_prompt()
{
- return (string)((string)(getlogin()) == "root" ? prompt_root : prompt_normal);
+ return (string)(safe_str(getlogin()) == "root" ? prompt_root : prompt_normal);
}
}
diff --git a/src/util/string.cc b/src/util/string.cc
index 7146fe3..cc0de34 100644
--- a/src/util/string.cc
+++ b/src/util/string.cc
@@ -35,4 +35,9 @@ void argv2string(vector<string> *s, const char * const * argv)
}
}
+std::string safe_str(const char *s, const char *fallback)
+{
+ return (s != nullptr) ? s : fallback;
+}
+
}