Skip to content

Commit

Permalink
Merge pull request aristocratos#539 from nobounce/replace-NULL-nullptr
Browse files Browse the repository at this point in the history
Modernize using nullptr.
  • Loading branch information
aristocratos committed Jul 30, 2023
2 parents 94e5c02 + e4abcef commit 8a33aab
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 85 deletions.
26 changes: 13 additions & 13 deletions src/btop.cpp
Expand Up @@ -244,14 +244,14 @@ void clean_quit(int sig) {
Runner::stop();
if (Global::_runner_started) {
#ifdef __APPLE__
if (pthread_join(Runner::runner_id, NULL) != 0) {
if (pthread_join(Runner::runner_id, nullptr) != 0) {
Logger::warning("Failed to join _runner thread on exit!");
pthread_cancel(Runner::runner_id);
}
#else
struct timespec ts;
ts.tv_sec = 5;
if (pthread_timedjoin_np(Runner::runner_id, NULL, &ts) != 0) {
if (pthread_timedjoin_np(Runner::runner_id, nullptr, &ts) != 0) {
Logger::warning("Failed to join _runner thread on exit!");
pthread_cancel(Runner::runner_id);
}
Expand Down Expand Up @@ -356,7 +356,7 @@ namespace Runner {
public:
int status;
thread_lock(pthread_mutex_t& mtx) : pt_mutex(mtx) {
pthread_mutex_init(&pt_mutex, NULL);
pthread_mutex_init(&pt_mutex, nullptr);
status = pthread_mutex_lock(&pt_mutex);
}
~thread_lock() {
Expand Down Expand Up @@ -444,7 +444,7 @@ namespace Runner {
// sigaddset(&mask, SIGTSTP);
sigaddset(&mask, SIGWINCH);
sigaddset(&mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &mask, NULL);
pthread_sigmask(SIG_BLOCK, &mask, nullptr);

//? pthread_mutex_lock to lock thread and monitor health from main thread
thread_lock pt_lck(mtx);
Expand Down Expand Up @@ -666,7 +666,7 @@ namespace Runner {
active = false;
// exit(1);
pthread_cancel(Runner::runner_id);
if (pthread_create(&Runner::runner_id, NULL, &Runner::_runner, NULL) != 0) {
if (pthread_create(&Runner::runner_id, nullptr, &Runner::_runner, nullptr) != 0) {
Global::exit_error_msg = "Failed to re-create _runner thread!";
clean_quit(1);
}
Expand Down Expand Up @@ -754,7 +754,7 @@ int main(int argc, char **argv) {

//? Setup paths for config, log and user themes
for (const auto& env : {"XDG_CONFIG_HOME", "HOME"}) {
if (std::getenv(env) != NULL and access(std::getenv(env), W_OK) != -1) {
if (std::getenv(env) != nullptr and access(std::getenv(env), W_OK) != -1) {
Config::conf_dir = fs::path(std::getenv(env)) / (((string)env == "HOME") ? ".config/btop" : "btop");
break;
}
Expand Down Expand Up @@ -821,17 +821,17 @@ int main(int argc, char **argv) {
}

//? Try to find and set a UTF-8 locale
if (std::setlocale(LC_ALL, "") != NULL and not s_contains((string)std::setlocale(LC_ALL, ""), ";")
if (std::setlocale(LC_ALL, "") != nullptr and not s_contains((string)std::setlocale(LC_ALL, ""), ";")
and str_to_upper(s_replace((string)std::setlocale(LC_ALL, ""), "-", "")).ends_with("UTF8")) {
Logger::debug("Using locale " + (string)std::setlocale(LC_ALL, ""));
}
else {
string found;
bool set_failure{}; // defaults to false
for (const auto loc_env : array{"LANG", "LC_ALL"}) {
if (std::getenv(loc_env) != NULL and str_to_upper(s_replace((string)std::getenv(loc_env), "-", "")).ends_with("UTF8")) {
if (std::getenv(loc_env) != nullptr and str_to_upper(s_replace((string)std::getenv(loc_env), "-", "")).ends_with("UTF8")) {
found = std::getenv(loc_env);
if (std::setlocale(LC_ALL, found.c_str()) == NULL) {
if (std::setlocale(LC_ALL, found.c_str()) == nullptr) {
set_failure = true;
Logger::warning("Failed to set locale " + found + " continuing anyway.");
}
Expand All @@ -844,7 +844,7 @@ int main(int argc, char **argv) {
for (auto& l : ssplit(loc, ';')) {
if (str_to_upper(s_replace(l, "-", "")).ends_with("UTF8")) {
found = l.substr(l.find('=') + 1);
if (std::setlocale(LC_ALL, found.c_str()) != NULL) {
if (std::setlocale(LC_ALL, found.c_str()) != nullptr) {
break;
}
}
Expand All @@ -865,10 +865,10 @@ int main(int argc, char **argv) {
if (cur_locale.empty()) {
Logger::warning("No UTF-8 locale detected! Some symbols might not display correctly.");
}
else if (std::setlocale(LC_ALL, string(cur_locale + ".UTF-8").c_str()) != NULL) {
else if (std::setlocale(LC_ALL, string(cur_locale + ".UTF-8").c_str()) != nullptr) {
Logger::debug("Setting LC_ALL=" + cur_locale + ".UTF-8");
}
else if(std::setlocale(LC_ALL, "en_US.UTF-8") != NULL) {
else if(std::setlocale(LC_ALL, "en_US.UTF-8") != nullptr) {
Logger::debug("Setting LC_ALL=en_US.UTF-8");
}
else {
Expand Down Expand Up @@ -940,7 +940,7 @@ int main(int argc, char **argv) {

//? Start runner thread
Runner::thread_sem_init();
if (pthread_create(&Runner::runner_id, NULL, &Runner::_runner, NULL) != 0) {
if (pthread_create(&Runner::runner_id, nullptr, &Runner::_runner, nullptr) != 0) {
Global::exit_error_msg = "Failed to create _runner thread!";
clean_quit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/btop_draw.cpp
Expand Up @@ -307,7 +307,7 @@ namespace Draw {
static size_t clock_len{}; // defaults to 0
static string clock_str;

if (auto n_time = time(NULL); not force and n_time == c_time)
if (auto n_time = time(nullptr); not force and n_time == c_time)
return false;
else {
c_time = n_time;
Expand Down
2 changes: 1 addition & 1 deletion src/btop_input.hpp
Expand Up @@ -32,7 +32,7 @@ using std::string;

/* The input functions relies on the following std::cin options being set:
cin.sync_with_stdio(false);
cin.tie(NULL);
cin.tie(nullptr);
These will automatically be set when running Term::init() from btop_tools.cpp
*/

Expand Down
12 changes: 6 additions & 6 deletions src/btop_tools.cpp
Expand Up @@ -80,7 +80,7 @@ namespace Term {
else settings.c_lflag &= ~(ICANON);
if (tcsetattr(STDIN_FILENO, TCSANOW, &settings)) return false;
if (on) setlinebuf(stdin);
else setbuf(stdin, NULL);
else setbuf(stdin, nullptr);
return true;
}
}
Expand Down Expand Up @@ -121,15 +121,15 @@ namespace Term {
initialized = (bool)isatty(STDIN_FILENO);
if (initialized) {
tcgetattr(STDIN_FILENO, &initial_settings);
current_tty = (ttyname(STDIN_FILENO) != NULL ? static_cast<string>(ttyname(STDIN_FILENO)) : "unknown");
current_tty = (ttyname(STDIN_FILENO) != nullptr ? static_cast<string>(ttyname(STDIN_FILENO)) : "unknown");

//? Disable stream sync
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);

//? Disable stream ties
cin.tie(NULL);
cout.tie(NULL);
cin.tie(nullptr);
cout.tie(nullptr);
echo(false);
linebuffered(false);
refresh();
Expand Down Expand Up @@ -531,8 +531,8 @@ namespace Tools {

string username() {
auto user = getenv("LOGNAME");
if (user == NULL or strlen(user) == 0) user = getenv("USER");
return (user != NULL ? user : "");
if (user == nullptr or strlen(user) == 0) user = getenv("USER");
return (user != nullptr ? user : "");
}

}
Expand Down

0 comments on commit 8a33aab

Please sign in to comment.