aboutsummaryrefslogtreecommitdiffstats
path: root/OpenFilesScreen.c
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 /OpenFilesScreen.c
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 'OpenFilesScreen.c')
-rw-r--r--OpenFilesScreen.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c
index 1eda373..80079d0 100644
--- a/OpenFilesScreen.c
+++ b/OpenFilesScreen.c
@@ -86,17 +86,12 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
pdata->error = 127;
return pdata;
}
- while (!feof(fd)) {
- int cmd = fgetc(fd);
- if (cmd == EOF)
- break;
- char* entry = xMalloc(1024);
- if (!fgets(entry, 1024, fd)) {
- free(entry);
+ for (;;) {
+ char* line = String_readLine(fd);
+ if (!line) {
break;
}
- char* newline = strrchr(entry, '\n');
- *newline = '\0';
+ unsigned char cmd = line[0];
if (cmd == 'f') {
OpenFiles_FileData* nextFile = xCalloc(1, sizeof(OpenFiles_FileData));
if (fdata == NULL) {
@@ -108,7 +103,8 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
item = &(fdata->data);
}
assert(cmd >= 0 && cmd <= 0xff);
- item->data[cmd] = entry;
+ item->data[cmd] = xStrdup(line + 1);
+ free(line);
}
pdata->error = pclose(fd);
return pdata;
@@ -132,9 +128,11 @@ void OpenFilesScreen_scan(InfoScreen* this) {
} else {
OpenFiles_FileData* fdata = pdata->files;
while (fdata) {
- char entry[1024];
char** data = fdata->data.data;
- sprintf(entry, "%5s %4s %10s %10s %10s %s",
+ int lenN = data['n'] ? strlen(data['n']) : 0;
+ int sizeEntry = 5 + 7 + 10 + 10 + 10 + lenN + 5 /*spaces*/ + 1 /*null*/;
+ char* entry = xMalloc(sizeEntry);
+ snprintf(entry, sizeEntry, "%5.5s %7.7s %10.10s %10.10s %10.10s %s",
data['f'] ? data['f'] : "",
data['t'] ? data['t'] : "",
data['D'] ? data['D'] : "",

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