summaryrefslogtreecommitdiffstats
path: root/htop.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-04-21 19:16:16 -0300
committerHisham Muhammad <hisham@gobolinux.org>2014-04-21 19:16:16 -0300
commit30bafafb240388a63aecc4053414dca0289c7b7b (patch)
tree8568fa29b1ff035f5db11f7d24445d065e9a3144 /htop.c
parent57b393f78317e6478fe3ed38b913c9082fe4184c (diff)
avoid strtok and reduce scope of variables.
Diffstat (limited to 'htop.c')
-rw-r--r--htop.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/htop.c b/htop.c
index 94ff3a7c..24844c9f 100644
--- a/htop.c
+++ b/htop.c
@@ -396,7 +396,7 @@ int main(int argc, char** argv) {
}
break;
case 'd':
- if (sscanf(optarg, "%d", &delay) == 1) {
+ if (sscanf(optarg, "%16d", &delay) == 1) {
if (delay < 1) delay = 1;
if (delay > 100) delay = 100;
} else {
@@ -413,9 +413,10 @@ int main(int argc, char** argv) {
case 'C':
usecolors=0;
break;
- case 'p':
+ case 'p': {
argCopy = strdup(optarg);
- pid = strtok(argCopy, ",");
+ char* saveptr;
+ pid = strtok_r(argCopy, ",", &saveptr);
if( !pidWhiteList ) {
pidWhiteList = Hashtable_new(8, false);
@@ -424,11 +425,12 @@ int main(int argc, char** argv) {
while( pid ) {
unsigned int num_pid = atoi(pid);
Hashtable_put(pidWhiteList, num_pid, (void *) 1);
- pid = strtok(NULL, ",");
+ pid = strtok_r(NULL, ",", &saveptr);
}
free(argCopy);
break;
+ }
default:
exit(1);
}
@@ -503,9 +505,7 @@ int main(int argc, char** argv) {
bool follow = false;
struct timeval tv;
- double newTime = 0.0;
double oldTime = 0.0;
- bool recalculate;
int ch = ERR;
int closeTimeout = 0;
@@ -516,8 +516,8 @@ int main(int argc, char** argv) {
while (!quit) {
gettimeofday(&tv, NULL);
- newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000);
- recalculate = (newTime - oldTime > settings->delay);
+ double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000);
+ bool recalculate = (newTime - oldTime > settings->delay);
int following = follow ? selectedPid(panel) : -1;
if (recalculate) {
Header_draw(header);

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