summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-27 11:46:29 +0100
committercgzones <cgzones@googlemail.com>2020-10-27 18:00:43 +0100
commitac2b07eddd6f0b7c41b84b71653ca90fd301085f (patch)
tree0877120c0d42eed27a7f3d29a9fe79803cdd141f
parent27870bd4deceff8396bbc569927716773b1aea29 (diff)
Avoid some unnecessary casts and mark some not changing variables const
-rw-r--r--Action.c12
-rw-r--r--Panel.c2
-rw-r--r--UsersTable.c4
-rw-r--r--linux/LinuxProcess.c6
-rw-r--r--linux/LinuxProcess.h2
-rw-r--r--linux/LinuxProcessList.c5
-rw-r--r--linux/Platform.c2
7 files changed, 16 insertions, 17 deletions
diff --git a/Action.c b/Action.c
index 3f5737fc..5b68811e 100644
--- a/Action.c
+++ b/Action.c
@@ -93,20 +93,20 @@ static void Action_runSetup(State* st) {
static bool changePriority(MainPanel* panel, int delta) {
bool anyTagged;
- bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged);
+ bool ok = MainPanel_foreachProcess(panel, Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged);
if (!ok)
beep();
return anyTagged;
}
static void addUserToVector(int key, void* userCast, void* panelCast) {
- char* user = (char*) userCast;
- Panel* panel = (Panel*) panelCast;
+ const char* user = userCast;
+ Panel* panel = panelCast;
Panel_add(panel, (Object*) ListItem_new(user, key));
}
bool Action_setUserOnly(const char* userName, uid_t* userId) {
- struct passwd* user = getpwnam(userName);
+ const struct passwd* user = getpwnam(userName);
if (user) {
*userId = user->pw_uid;
return true;
@@ -301,7 +301,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
void* set = Action_pickFromVector(st, affinityPanel, width, true);
if (set) {
Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl);
- bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity2 }, NULL);
+ bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg){ .v = affinity2 }, NULL);
if (!ok) beep();
Affinity_delete(affinity2);
}
@@ -318,7 +318,7 @@ static Htop_Reaction actionKill(State* st) {
Panel_setHeader(st->panel, "Sending...");
Panel_draw(st->panel, true);
refresh();
- MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (Arg){ .i = sgn->key }, NULL);
+ MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg){ .i = sgn->key }, NULL);
napms(500);
}
}
diff --git a/Panel.c b/Panel.c
index 782cbdc1..02440d85 100644
--- a/Panel.c
+++ b/Panel.c
@@ -423,7 +423,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
for (int try = 0; try < 2; try++) {
len = strlen(buffer);
for (int i = 0; i < size; i++) {
- char* cur = ((ListItem*) Panel_get(this, i))->value;
+ const char* cur = ((ListItem*) Panel_get(this, i))->value;
while (*cur == ' ') cur++;
if (strncasecmp(cur, buffer, len) == 0) {
Panel_setSelected(this, i);
diff --git a/UsersTable.c b/UsersTable.c
index 83c6dbc3..25e44883 100644
--- a/UsersTable.c
+++ b/UsersTable.c
@@ -30,9 +30,9 @@ void UsersTable_delete(UsersTable* this) {
}
char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
- char* name = (char*) (Hashtable_get(this->users, uid));
+ char* name = Hashtable_get(this->users, uid);
if (name == NULL) {
- struct passwd* userData = getpwuid(uid);
+ const struct passwd* userData = getpwuid(uid);
if (userData != NULL) {
name = xStrdup(userData->pw_name);
Hashtable_put(this->users, uid, name);
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c
index 23783ef0..fad80555 100644
--- a/linux/LinuxProcess.c
+++ b/linux/LinuxProcess.c
@@ -179,12 +179,12 @@ IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this) {
return ioprio;
}
-bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio) {
+bool LinuxProcess_setIOPriority(Process* this, Arg ioprio) {
// Other OSes masquerading as Linux (NetBSD?) don't have this syscall
#ifdef SYS_ioprio_set
- syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->super.pid, ioprio.i);
+ syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->pid, ioprio.i);
#endif
- return (LinuxProcess_updateIOPriority(this) == ioprio.i);
+ return (LinuxProcess_updateIOPriority((LinuxProcess*)this) == ioprio.i);
}
#ifdef HAVE_DELAYACCT
diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h
index 45a3127f..80a4220b 100644
--- a/linux/LinuxProcess.h
+++ b/linux/LinuxProcess.h
@@ -183,7 +183,7 @@ extern io_priority;
IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this);
-bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio);
+bool LinuxProcess_setIOPriority(Process* this, Arg ioprio);
#ifdef HAVE_DELAYACCT
void LinuxProcess_printDelay(float delay_percent, char* buffer, int n);
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 5d9bc3c4..f7d01557 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -480,7 +480,6 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di
//kernel will return data in chunks of size PAGE_SIZE or less.
char buffer[CRT_pageSize];// 4k
- char *start,*end;
ssize_t nread=0;
if(haveSmapsRollup) {// only available in Linux 4.14+
xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps_rollup", dirname, name);
@@ -496,8 +495,8 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di
process->m_psswp = 0;
while ( ( nread = read(fd,buffer, sizeof(buffer)) ) > 0 ){
- start = (char *)&buffer;
- end = start + nread;
+ char* start = buffer;
+ char* end = start + nread;
do{//parse 4k block
int tmp;
diff --git a/linux/Platform.c b/linux/Platform.c
index 43bf84b1..f6f7ba19 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -103,7 +103,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) {
void* set = Action_pickFromVector(st, ioprioPanel, 21, true);
if (set) {
IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel);
- bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio2 }, NULL);
+ bool ok = MainPanel_foreachProcess((MainPanel*)panel, LinuxProcess_setIOPriority, (Arg){ .i = ioprio2 }, NULL);
if (!ok)
beep();
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy