aboutsummaryrefslogtreecommitdiffstats
path: root/linux
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-07-25 18:25:28 +0200
committerDaniel Lange <DLange@git.local>2016-07-25 18:25:28 +0200
commit31b71b67011fa52f091df6fe536a11d6d0bfb256 (patch)
tree31cb222871017376af8b7435d24cf4961863fa93 /linux
parent8c82a38002ce09db2a0b83dab8b598cf1ab0596c (diff)
downloaddebian_htop-31b71b67011fa52f091df6fe536a11d6d0bfb256.tar.gz
debian_htop-31b71b67011fa52f091df6fe536a11d6d0bfb256.tar.bz2
debian_htop-31b71b67011fa52f091df6fe536a11d6d0bfb256.zip
Imported Upstream version 2.0.2upstream/2.0.2
Diffstat (limited to 'linux')
-rw-r--r--linux/Battery.c17
-rw-r--r--linux/LinuxProcessList.c7
2 files changed, 14 insertions, 10 deletions
diff --git a/linux/Battery.c b/linux/Battery.c
index 572bad4..1068184 100644
--- a/linux/Battery.c
+++ b/linux/Battery.c
@@ -65,10 +65,11 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
break;
}
- char line[50] = "";
+ char* line = NULL;
for (unsigned short int i = 0; i < lineNum; i++) {
- char* ok = fgets(line, sizeof line, file);
- if (!ok) break;
+ free(line);
+ line = String_readLine(file);
+ if (!line) break;
}
fclose(file);
@@ -76,7 +77,8 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
char *foundNumStr = String_getToken(line, wordNum);
const unsigned long int foundNum = atoi(foundNumStr);
free(foundNumStr);
-
+ free(line);
+
total += foundNum;
}
@@ -116,14 +118,13 @@ static ACPresence procAcpiCheck() {
continue;
}
- char line[100];
- char* ok = fgets(line, sizeof line, file);
- if (!ok) continue;
- line[sizeof(line) - 1] = '\0';
+ char* line = String_readLine(file);
+ if (!line) continue;
fclose(file);
const char *isOnline = String_getToken(line, 2);
+ free(line);
if (strcmp(isOnline, "on-line") == 0) {
isOn = AC_PRESENT;
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 1b1a0f3..712baa5 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -470,6 +470,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
int amtRead = xread(fd, command, sizeof(command) - 1);
close(fd);
int tokenEnd = 0;
+ int lastChar = 0;
if (amtRead > 0) {
for (int i = 0; i < amtRead; i++)
if (command[i] == '\0' || command[i] == '\n') {
@@ -477,14 +478,16 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
tokenEnd = i;
}
command[i] = ' ';
+ } else {
+ lastChar = i;
}
}
if (tokenEnd == 0) {
tokenEnd = amtRead;
}
- command[amtRead] = '\0';
+ command[lastChar + 1] = '\0';
process->basenameOffset = tokenEnd;
- setCommand(process, command, amtRead);
+ setCommand(process, command, lastChar + 1);
return true;
}

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