summaryrefslogtreecommitdiffstats
path: root/linux
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2024-04-17 16:45:46 +0800
committerBenBE <BenBE@geshi.org>2024-04-17 11:54:00 +0200
commita46b3f0a98c801b94df08598be0127e4d7db2aca (patch)
tree9a0e51e445dbb19685897d225ff847016f9c6761 /linux
parent6f0adfab242f40e0a0e82445abac4e574c7a97e8 (diff)
Use 'fp' name for local 'FILE*' variables.
It is inappropriate to use the 'fd' name for 'FILE*' variables. POSIX file descriptiors are of type 'int' and are distinguished from ISO C stream pointers (type 'FILE*'). Rename these variables to 'fp', which is a preferred naming in POSIX. (Note that ISO C preferred the 'stream' name for the variables.) No code changes.
Diffstat (limited to 'linux')
-rw-r--r--linux/LinuxProcessTable.c16
-rw-r--r--linux/Platform.c52
2 files changed, 34 insertions, 34 deletions
diff --git a/linux/LinuxProcessTable.c b/linux/LinuxProcessTable.c
index f8adf9ad..1e7c041d 100644
--- a/linux/LinuxProcessTable.c
+++ b/linux/LinuxProcessTable.c
@@ -71,11 +71,11 @@ static FILE* fopenat(openat_arg_t openatArg, const char* pathname, const char* m
if (fd < 0)
return NULL;
- FILE* stream = fdopen(fd, mode);
- if (!stream)
+ FILE* fp = fdopen(fd, mode);
+ if (!fp)
close(fd);
- return stream;
+ return fp;
}
static inline uint64_t fast_strtoull_dec(char** str, int maxlen) {
@@ -755,8 +755,8 @@ static bool LinuxProcessTable_readStatmFile(LinuxProcess* process, openat_arg_t
static bool LinuxProcessTable_readSmapsFile(LinuxProcess* process, openat_arg_t procFd, bool haveSmapsRollup) {
//http://elixir.free-electrons.com/linux/v4.10/source/fs/proc/task_mmu.c#L719
//kernel will return data in chunks of size PAGE_SIZE or less.
- FILE* f = fopenat(procFd, haveSmapsRollup ? "smaps_rollup" : "smaps", "r");
- if (!f)
+ FILE* fp = fopenat(procFd, haveSmapsRollup ? "smaps_rollup" : "smaps", "r");
+ if (!fp)
return false;
process->m_pss = 0;
@@ -764,10 +764,10 @@ static bool LinuxProcessTable_readSmapsFile(LinuxProcess* process, openat_arg_t
process->m_psswp = 0;
char buffer[256];
- while (fgets(buffer, sizeof(buffer), f)) {
+ while (fgets(buffer, sizeof(buffer), fp)) {
if (!strchr(buffer, '\n')) {
// Partial line, skip to end of this line
- while (fgets(buffer, sizeof(buffer), f)) {
+ while (fgets(buffer, sizeof(buffer), fp)) {
if (strchr(buffer, '\n')) {
break;
}
@@ -784,7 +784,7 @@ static bool LinuxProcessTable_readSmapsFile(LinuxProcess* process, openat_arg_t
}
}
- fclose(f);
+ fclose(fp);
return true;
}
diff --git a/linux/Platform.c b/linux/Platform.c
index 59fe7056..3316d1db 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -450,8 +450,8 @@ void Platform_setZfsCompressedArcValues(Meter* this) {
char* Platform_getProcessEnv(pid_t pid) {
char procname[128];
xSnprintf(procname, sizeof(procname), PROCDIR "/%d/environ", pid);
- FILE* fd = fopen(procname, "r");
- if (!fd)
+ FILE* fp = fopen(procname, "r");
+ if (!fp)
return NULL;
char* env = NULL;
@@ -464,9 +464,9 @@ char* Platform_getProcessEnv(pid_t pid) {
size += bytes;
capacity += 4096;
env = xRealloc(env, capacity);
- } while ((bytes = fread(env + size, 1, capacity - size, fd)) > 0);
+ } while ((bytes = fread(env + size, 1, capacity - size, fp)) > 0);
- fclose(fd);
+ fclose(fp);
if (bytes < 0) {
free(env);
@@ -515,13 +515,13 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) {
int fd = openat(dfd, de->d_name, O_RDONLY | O_CLOEXEC);
if (fd == -1)
continue;
- FILE* f = fdopen(fd, "r");
- if (!f) {
+ FILE* fp = fdopen(fd, "r");
+ if (!fp) {
close(fd);
continue;
}
- for (char buffer[1024]; fgets(buffer, sizeof(buffer), f); ) {
+ for (char buffer[1024]; fgets(buffer, sizeof(buffer), fp); ) {
if (!strchr(buffer, '\n'))
continue;
@@ -559,7 +559,7 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) {
data_ref = &(*data_ref)->next;
}
- fclose(f);
+ fclose(fp);
}
closedir(dirp);
@@ -574,18 +574,18 @@ void Platform_getPressureStall(const char* file, bool some, double* ten, double*
*ten = *sixty = *threehundred = 0;
char procname[128];
xSnprintf(procname, sizeof(procname), PROCDIR "/pressure/%s", file);
- FILE* fd = fopen(procname, "r");
- if (!fd) {
+ FILE* fp = fopen(procname, "r");
+ if (!fp) {
*ten = *sixty = *threehundred = NAN;
return;
}
- int total = fscanf(fd, "some avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
+ int total = fscanf(fp, "some avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
if (!some) {
- total = fscanf(fd, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
+ total = fscanf(fp, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
}
(void) total;
assert(total == 3);
- fclose(fd);
+ fclose(fp);
}
void Platform_getFileDescriptors(double* used, double* max) {
@@ -607,15 +607,15 @@ void Platform_getFileDescriptors(double* used, double* max) {
}
bool Platform_getDiskIO(DiskIOData* data) {
- FILE* fd = fopen(PROCDIR "/diskstats", "r");
- if (!fd)
+ FILE* fp = fopen(PROCDIR "/diskstats", "r");
+ if (!fp)
return false;
char lastTopDisk[32] = { '\0' };
unsigned long long int read_sum = 0, write_sum = 0, timeSpend_sum = 0;
char lineBuffer[256];
- while (fgets(lineBuffer, sizeof(lineBuffer), fd)) {
+ while (fgets(lineBuffer, sizeof(lineBuffer), fp)) {
char diskname[32];
unsigned long long int read_tmp, write_tmp, timeSpend_tmp;
if (sscanf(lineBuffer, "%*d %*d %31s %*u %*u %llu %*u %*u %*u %llu %*u %*u %llu", diskname, &read_tmp, &write_tmp, &timeSpend_tmp) == 4) {
@@ -637,7 +637,7 @@ bool Platform_getDiskIO(DiskIOData* data) {
timeSpend_sum += timeSpend_tmp;
}
}
- fclose(fd);
+ fclose(fp);
/* multiply with sector size */
data->totalBytesRead = 512 * read_sum;
data->totalBytesWritten = 512 * write_sum;
@@ -646,13 +646,13 @@ bool Platform_getDiskIO(DiskIOData* data) {
}
bool Platform_getNetworkIO(NetworkIOData* data) {
- FILE* fd = fopen(PROCDIR "/net/dev", "r");
- if (!fd)
+ FILE* fp = fopen(PROCDIR "/net/dev", "r");
+ if (!fp)
return false;
memset(data, 0, sizeof(NetworkIOData));
char lineBuffer[512];
- while (fgets(lineBuffer, sizeof(lineBuffer), fd)) {
+ while (fgets(lineBuffer, sizeof(lineBuffer), fp)) {
char interfaceName[32];
unsigned long long int bytesReceived, packetsReceived, bytesTransmitted, packetsTransmitted;
if (sscanf(lineBuffer, "%31s %llu %llu %*u %*u %*u %*u %*u %*u %llu %llu",
@@ -672,7 +672,7 @@ bool Platform_getNetworkIO(NetworkIOData* data) {
data->packetsTransmitted += packetsTransmitted;
}
- fclose(fd);
+ fclose(fp);
return true;
}
@@ -1079,18 +1079,18 @@ bool Platform_init(void) {
}
}
- FILE* fd = fopen(PROCDIR "/1/mounts", "r");
- if (fd) {
+ FILE* fp = fopen(PROCDIR "/1/mounts", "r");
+ if (fp) {
char lineBuffer[256];
- while (fgets(lineBuffer, sizeof(lineBuffer), fd)) {
+ while (fgets(lineBuffer, sizeof(lineBuffer), fp)) {
// detect lxc or overlayfs and guess that this means we are running containerized
if (String_startsWith(lineBuffer, "lxcfs /proc") || String_startsWith(lineBuffer, "overlay / overlay")) {
Running_containerized = true;
break;
}
}
- fclose(fd);
- } // if (fd)
+ fclose(fp);
+ }
return true;
}

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