utilities to set and get process title now available

This commit is contained in:
Michele Caini 2017-02-23 21:52:33 +01:00
parent 17c01f1c7e
commit add2153b8f
2 changed files with 28 additions and 0 deletions

View File

@ -584,6 +584,31 @@ struct Utilities {
return avg;
}
/**
* @brief Gets the title of the current process.
* @return The process title.
*/
static std::string processTitle() {
std::size_t size = details::DEFAULT_SIZE;
char buf[details::DEFAULT_SIZE];
std::string str{};
if(0 == uv_get_process_title(buf, size)) {
str.assign(buf, size);
}
return str;
}
/**
* @brief Sets the current process title.
* @param title The process title to be set.
* @return True in case of success, false otherwise.
*/
static bool processTitle(std::string title) {
return (0 == uv_set_process_title(title.c_str()));
}
/**
* @brief Gets memory information (in bytes).
* @return Memory information.

View File

@ -99,4 +99,7 @@ TEST(Util, Utilities) {
ASSERT_FALSE(uvw::Utilities::exepath().empty());
ASSERT_FALSE(uvw::Utilities::cwd().empty());
ASSERT_TRUE(uvw::Utilities::chdir(uvw::Utilities::cwd()));
ASSERT_NE(uvw::Utilities::processTitle(), std::string{});
ASSERT_TRUE(uvw::Utilities::processTitle(uvw::Utilities::processTitle()));
}