forked from pool/powertop
67 lines
1.6 KiB
Diff
67 lines
1.6 KiB
Diff
--- config.c 2007-05-13 19:22:30.000000000 +0200
|
|
+++ config.c 2007-05-15 10:16:16.000000000 +0200
|
|
@@ -47,7 +47,8 @@
|
|
file = popen("zcat /proc/config.gz", "r");
|
|
while (file && !feof(file)) {
|
|
char line[100];
|
|
- fgets(line, 100, file);
|
|
+ if (fgets(line, 100, file) == NULL)
|
|
+ break;
|
|
strcpy(configlines[configcount++], line);
|
|
}
|
|
pclose(file);
|
|
@@ -56,7 +57,10 @@
|
|
file = fopen("/proc/sys/kernel/osrelease", "r");
|
|
if (!file)
|
|
return;
|
|
- fgets(version, 100, file);
|
|
+ if (fgets(version, 100, file) == NULL) {
|
|
+ fclose(file);
|
|
+ return;
|
|
+ }
|
|
fclose(file);
|
|
c = strchr(version, '\n');
|
|
if (c)
|
|
@@ -71,7 +75,8 @@
|
|
return;
|
|
while (!feof(file)) {
|
|
char line[100];
|
|
- fgets(line, 100, file);
|
|
+ if (fgets(line, 100, file) == NULL)
|
|
+ break;
|
|
strcpy(configlines[configcount++], line);
|
|
}
|
|
fclose(file);
|
|
--- powertop.c 2007-05-15 01:41:30.000000000 +0200
|
|
+++ powertop.c 2007-05-15 10:14:48.000000000 +0200
|
|
@@ -135,7 +135,8 @@
|
|
int nr = -1;
|
|
uint64_t count = 0;
|
|
memset(line, 0, sizeof(line));
|
|
- fgets(line, 1024, file);
|
|
+ if (fgets(line, 1024, file) == NULL)
|
|
+ break;
|
|
c = strchr(line, ':');
|
|
if (!c)
|
|
continue;
|
|
@@ -199,7 +200,8 @@
|
|
|
|
while (!feof(file)) {
|
|
memset(line, 0, 4096);
|
|
- fgets(line, 4096, file);
|
|
+ if (fgets(line, 4096, file) == NULL)
|
|
+ break;
|
|
c = strstr(line, "age[");
|
|
if (!c)
|
|
continue;
|
|
@@ -420,7 +422,8 @@
|
|
while (file && !feof(file)) {
|
|
char *count, *pid, *process, *func;
|
|
int cnt;
|
|
- fgets(line, 1024, file);
|
|
+ if (fgets(line, 1024, file) == NULL)
|
|
+ break;
|
|
if (strstr(line, "total events"))
|
|
break;
|
|
c = count = &line[0];
|