mirror of https://github.com/xzeldon/htop.git
Avoid some unnecessary casts and mark some not changing variables const
This commit is contained in:
parent
27870bd4de
commit
ac2b07eddd
12
Action.c
12
Action.c
|
@ -93,20 +93,20 @@ static void Action_runSetup(State* st) {
|
||||||
|
|
||||||
static bool changePriority(MainPanel* panel, int delta) {
|
static bool changePriority(MainPanel* panel, int delta) {
|
||||||
bool anyTagged;
|
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)
|
if (!ok)
|
||||||
beep();
|
beep();
|
||||||
return anyTagged;
|
return anyTagged;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addUserToVector(int key, void* userCast, void* panelCast) {
|
static void addUserToVector(int key, void* userCast, void* panelCast) {
|
||||||
char* user = (char*) userCast;
|
const char* user = userCast;
|
||||||
Panel* panel = (Panel*) panelCast;
|
Panel* panel = panelCast;
|
||||||
Panel_add(panel, (Object*) ListItem_new(user, key));
|
Panel_add(panel, (Object*) ListItem_new(user, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Action_setUserOnly(const char* userName, uid_t* userId) {
|
bool Action_setUserOnly(const char* userName, uid_t* userId) {
|
||||||
struct passwd* user = getpwnam(userName);
|
const struct passwd* user = getpwnam(userName);
|
||||||
if (user) {
|
if (user) {
|
||||||
*userId = user->pw_uid;
|
*userId = user->pw_uid;
|
||||||
return true;
|
return true;
|
||||||
|
@ -301,7 +301,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
||||||
void* set = Action_pickFromVector(st, affinityPanel, width, true);
|
void* set = Action_pickFromVector(st, affinityPanel, width, true);
|
||||||
if (set) {
|
if (set) {
|
||||||
Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
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();
|
if (!ok) beep();
|
||||||
Affinity_delete(affinity2);
|
Affinity_delete(affinity2);
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ static Htop_Reaction actionKill(State* st) {
|
||||||
Panel_setHeader(st->panel, "Sending...");
|
Panel_setHeader(st->panel, "Sending...");
|
||||||
Panel_draw(st->panel, true);
|
Panel_draw(st->panel, true);
|
||||||
refresh();
|
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);
|
napms(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
Panel.c
2
Panel.c
|
@ -423,7 +423,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
||||||
for (int try = 0; try < 2; try++) {
|
for (int try = 0; try < 2; try++) {
|
||||||
len = strlen(buffer);
|
len = strlen(buffer);
|
||||||
for (int i = 0; i < size; i++) {
|
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++;
|
while (*cur == ' ') cur++;
|
||||||
if (strncasecmp(cur, buffer, len) == 0) {
|
if (strncasecmp(cur, buffer, len) == 0) {
|
||||||
Panel_setSelected(this, i);
|
Panel_setSelected(this, i);
|
||||||
|
|
|
@ -30,9 +30,9 @@ void UsersTable_delete(UsersTable* this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
|
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) {
|
if (name == NULL) {
|
||||||
struct passwd* userData = getpwuid(uid);
|
const struct passwd* userData = getpwuid(uid);
|
||||||
if (userData != NULL) {
|
if (userData != NULL) {
|
||||||
name = xStrdup(userData->pw_name);
|
name = xStrdup(userData->pw_name);
|
||||||
Hashtable_put(this->users, uid, name);
|
Hashtable_put(this->users, uid, name);
|
||||||
|
|
|
@ -179,12 +179,12 @@ IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this) {
|
||||||
return ioprio;
|
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
|
// Other OSes masquerading as Linux (NetBSD?) don't have this syscall
|
||||||
#ifdef SYS_ioprio_set
|
#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
|
#endif
|
||||||
return (LinuxProcess_updateIOPriority(this) == ioprio.i);
|
return (LinuxProcess_updateIOPriority((LinuxProcess*)this) == ioprio.i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
|
|
|
@ -183,7 +183,7 @@ extern io_priority;
|
||||||
|
|
||||||
IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this);
|
IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this);
|
||||||
|
|
||||||
bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio);
|
bool LinuxProcess_setIOPriority(Process* this, Arg ioprio);
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
void LinuxProcess_printDelay(float delay_percent, char* buffer, int n);
|
void LinuxProcess_printDelay(float delay_percent, char* buffer, int n);
|
||||||
|
|
|
@ -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.
|
//kernel will return data in chunks of size PAGE_SIZE or less.
|
||||||
|
|
||||||
char buffer[CRT_pageSize];// 4k
|
char buffer[CRT_pageSize];// 4k
|
||||||
char *start,*end;
|
|
||||||
ssize_t nread=0;
|
ssize_t nread=0;
|
||||||
if(haveSmapsRollup) {// only available in Linux 4.14+
|
if(haveSmapsRollup) {// only available in Linux 4.14+
|
||||||
xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps_rollup", dirname, name);
|
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;
|
process->m_psswp = 0;
|
||||||
|
|
||||||
while ( ( nread = read(fd,buffer, sizeof(buffer)) ) > 0 ){
|
while ( ( nread = read(fd,buffer, sizeof(buffer)) ) > 0 ){
|
||||||
start = (char *)&buffer;
|
char* start = buffer;
|
||||||
end = start + nread;
|
char* end = start + nread;
|
||||||
do{//parse 4k block
|
do{//parse 4k block
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
||||||
void* set = Action_pickFromVector(st, ioprioPanel, 21, true);
|
void* set = Action_pickFromVector(st, ioprioPanel, 21, true);
|
||||||
if (set) {
|
if (set) {
|
||||||
IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel);
|
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)
|
if (!ok)
|
||||||
beep();
|
beep();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue