From 81e44312b4976d5516f129f36a67fe381bcb6883 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 25 Dec 2011 20:23:53 +0000 Subject: [PATCH] Use strdup explicitly --- AffinityPanel.c | 2 +- ChangeLog | 3 +++ ColorsPanel.c | 3 ++- ColorsPanel.h | 1 + DisplayOptionsPanel.c | 22 +++++++++++----------- FunctionBar.c | 6 +++--- ListItem.c | 2 +- OpenFilesScreen.c | 1 - OpenFilesScreen.h | 2 +- ProcessList.c | 6 +++--- Settings.h | 1 + String.c | 6 +----- String.h | 3 +-- UsersTable.c | 5 +++-- UsersTable.h | 3 ++- htop.c | 4 ++-- htop.h | 4 ++-- 17 files changed, 38 insertions(+), 36 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index 404104a1..655af607 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -38,7 +38,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) { } else { mode = false; } - Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mode)); + Panel_add(this, (Object*) CheckItem_new(strdup(number), NULL, mode)); } return this; } diff --git a/ChangeLog b/ChangeLog index 6ece69c0..c8c29815 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ What's new in version 1.0.1 +* Move .htoprc to XDG-compliant path ~/.config/htop/htoprc, + respecting $XDG_CONFIG_HOME + (thanks to Hadzhimurad Ustarkhan for the suggestion.) * Safer behavior on the kill screen, to make it harder to kill the wrong process. * BUGFIX: keep main panel up-to-date when running the screen manager, to fix crash when processes die while on the F9/Kill screen. diff --git a/ColorsPanel.c b/ColorsPanel.c index b4ee5f29..374e1df2 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -1,4 +1,5 @@ +#include "config.h" #include "CRT.h" #include "ColorsPanel.h" @@ -88,7 +89,7 @@ ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) { Panel_setHeader(super, "Colors"); for (int i = 0; ColorSchemes[i] != NULL; i++) { - Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), NULL, false)); + Panel_add(super, (Object*) CheckItem_new(strdup(ColorSchemes[i]), NULL, false)); } CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true); return this; diff --git a/ColorsPanel.h b/ColorsPanel.h index fac99639..f32152bf 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -3,6 +3,7 @@ #ifndef HEADER_ColorsPanel #define HEADER_ColorsPanel +#include "config.h" #include "CRT.h" #include "Panel.h" diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 71d73097..c2c0d33e 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -65,16 +65,16 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* super->eventHandler = DisplayOptionsPanel_eventHandler; Panel_setHeader(super, "Display options"); - Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Display threads in a different color"), &(settings->pl->highlightThreads), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Show custom thread names"), &(settings->pl->showThreadNames), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Tree view"), &(settings->pl->treeView), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Hide kernel threads"), &(settings->pl->hideKernelThreads), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Hide userland threads"), &(settings->pl->hideUserlandThreads), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Display threads in a different color"), &(settings->pl->highlightThreads), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Show custom thread names"), &(settings->pl->showThreadNames), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Leave a margin around header"), &(settings->header->margin), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false)); + Panel_add(super, (Object*) CheckItem_new(strdup("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false)); return this; } diff --git a/FunctionBar.c b/FunctionBar.c index ef0fcba2..ba657492 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -54,8 +54,8 @@ FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* eve this->events = malloc(sizeof(int) * 15); int i = 0; while (i < 15 && functions[i]) { - this->functions[i] = String_copy(functions[i]); - this->keys[i] = String_copy(keys[i]); + this->functions[i] = strdup(functions[i]); + this->keys[i] = strdup(keys[i]); this->events[i] = events[i]; i++; } @@ -89,7 +89,7 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) { for (int i = 0; i < this->size; i++) { if (this->events[i] == event) { free(this->functions[i]); - this->functions[i] = String_copy(text); + this->functions[i] = strdup(text); break; } } diff --git a/ListItem.c b/ListItem.c index 68ca7c92..500c31fa 100644 --- a/ListItem.c +++ b/ListItem.c @@ -49,7 +49,7 @@ ListItem* ListItem_new(const char* value, int key) { Object_setClass(this, LISTITEM_CLASS); ((Object*)this)->display = ListItem_display; ((Object*)this)->delete = ListItem_delete; - this->value = String_copy(value); + this->value = strdup(value); this->key = key; return this; } diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index b4ec11ae..98110016 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -5,7 +5,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE #include #include #include diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index a5d3cbc7..78694054 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -9,7 +9,7 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE +#include "config.h" #include #include #include diff --git a/ProcessList.c b/ProcessList.c index 224c18c9..d33d83b8 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -617,7 +617,7 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c command[amtRead] = '\0'; fclose(file); free(process->comm); - process->comm = String_copy(command); + process->comm = strdup(command); return true; } @@ -710,11 +710,11 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P if (process->state == 'Z') { free(process->comm); - process->comm = String_copy(command); + process->comm = strdup(command); } else if (Process_isThread(process)) { if (this->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') { free(process->comm); - process->comm = String_copy(command); + process->comm = strdup(command); } else if (this->showingThreadNames) { if (! ProcessList_readCmdlineFile(process, dirname, name)) goto errorReadingProcess; diff --git a/Settings.h b/Settings.h index b75364e3..9f1db00c 100644 --- a/Settings.h +++ b/Settings.h @@ -9,6 +9,7 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "config.h" #include "String.h" #include "ProcessList.h" #include "Header.h" diff --git a/String.c b/String.c index 81e9eeeb..7d8d285a 100644 --- a/String.c +++ b/String.c @@ -5,7 +5,7 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE +#include "config.h" #include "String.h" #include #include @@ -18,10 +18,6 @@ in the source distribution for its full text. #define String_startsWith(s, match) (strstr((s), (match)) == (s)) }*/ -inline char* String_copy(const char* orig) { - return strdup(orig); -} - char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); diff --git a/String.h b/String.h index 1d1534f7..99b1a97f 100644 --- a/String.h +++ b/String.h @@ -9,6 +9,7 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "config.h" #include #include #include @@ -18,8 +19,6 @@ in the source distribution for its full text. #define String_startsWith(s, match) (strstr((s), (match)) == (s)) -extern char* String_copy(const char* orig); - char* String_cat(const char* s1, const char* s2); char* String_trim(const char* in); diff --git a/UsersTable.c b/UsersTable.c index 1c56da46..f05b815c 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -5,11 +5,12 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "config.h" #include "UsersTable.h" #include "Hashtable.h" -#include "String.h" #include +#include #include #include #include @@ -40,7 +41,7 @@ char* UsersTable_getRef(UsersTable* this, unsigned int uid) { if (name == NULL) { struct passwd* userData = getpwuid(uid); if (userData != NULL) { - name = String_copy(userData->pw_name); + name = strdup(userData->pw_name); Hashtable_put(this->users, uid, name); } } diff --git a/UsersTable.h b/UsersTable.h index 7a591f78..6b3f2726 100644 --- a/UsersTable.h +++ b/UsersTable.h @@ -9,10 +9,11 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include "config.h" #include "Hashtable.h" -#include "String.h" #include +#include #include #include #include diff --git a/htop.c b/htop.c index 866b3fa3..cdd7d456 100644 --- a/htop.c +++ b/htop.c @@ -5,7 +5,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE +#include "config.h" + #include #include #include @@ -29,7 +30,6 @@ in the source distribution for its full text. #include "OpenFilesScreen.h" #include "AffinityPanel.h" -#include "config.h" #include "debug.h" //#link m diff --git a/htop.h b/htop.h index f0b5282f..64ea21bd 100644 --- a/htop.h +++ b/htop.h @@ -9,7 +9,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE +#include "config.h" + #include #include #include @@ -33,7 +34,6 @@ in the source distribution for its full text. #include "OpenFilesScreen.h" #include "AffinityPanel.h" -#include "config.h" #include "debug.h" //#link m