Skip to content

Commit

Permalink
Use 'sb' name for local 'struct stat' buffers
Browse files Browse the repository at this point in the history
Deprecate the use of 'st' and other names. The 'sb' name is often seen
in example codes in Linux man pages. (The 'statbuf' name is sometimes
also used but I choose 'sb' name because it's shorter.)

No code changes.
  • Loading branch information
Explorer09 authored and BenBE committed Apr 17, 2024
1 parent a46b3f0 commit 7017b86
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ int Compat_faccessat(int dirfd,
}

// Fallback to stat(2)/lstat(2) depending on flags
struct stat statinfo;
struct stat sb;
if (flags) {
ret = lstat(pathname, &statinfo);
ret = lstat(pathname, &sb);
} else {
ret = stat(pathname, &statinfo);
ret = stat(pathname, &sb);
}

return ret;
Expand Down
6 changes: 3 additions & 3 deletions OpenFilesScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
item = &fdata->data;
const char* filename = getDataForType(item, 'n');

struct stat st;
if (stat(filename, &st) == 0) {
struct stat sb;
if (stat(filename, &sb) == 0) {
char fileSizeBuf[21]; /* 20 (long long) + 1 (NULL) */
xSnprintf(fileSizeBuf, sizeof(fileSizeBuf), "%"PRIu64, (uint64_t)st.st_size); /* st.st_size is long long on macOS, long on linux */
xSnprintf(fileSizeBuf, sizeof(fileSizeBuf), "%"PRIu64, (uint64_t)sb.st_size); /* sb.st_size is long long on macOS, long on linux */
free_and_xStrdup(&item->data[fileSizeIndex], fileSizeBuf);
}
}
Expand Down
26 changes: 13 additions & 13 deletions linux/LinuxProcessTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,18 @@ static bool LinuxProcessTable_updateUser(const Machine* host, Process* process,
return true;
}

struct stat sstat;
struct stat sb;
#ifdef HAVE_OPENAT
int statok = fstat(procFd, &sstat);
int statok = fstat(procFd, &sb);
#else
int statok = stat(procFd, &sstat);
int statok = stat(procFd, &sb);
#endif
if (statok == -1)
return false;

if (process->st_uid != sstat.st_uid) {
process->st_uid = sstat.st_uid;
process->user = UsersTable_getRef(host->usersTable, sstat.st_uid);
if (process->st_uid != sb.st_uid) {
process->st_uid = sb.st_uid;
process->user = UsersTable_getRef(host->usersTable, sb.st_uid);
}

return true;
Expand Down Expand Up @@ -1349,19 +1349,19 @@ static char* LinuxProcessTable_updateTtyDevice(TtyDriver* ttyDrivers, unsigned l
continue;
}
unsigned int idx = min - ttyDrivers[i].minorFrom;
struct stat sstat;
struct stat sb;
char* fullPath;
for (;;) {
xAsprintf(&fullPath, "%s/%d", ttyDrivers[i].path, idx);
int err = stat(fullPath, &sstat);
if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) {
int err = stat(fullPath, &sb);
if (err == 0 && major(sb.st_rdev) == maj && minor(sb.st_rdev) == min) {
return fullPath;
}
free(fullPath);

xAsprintf(&fullPath, "%s%d", ttyDrivers[i].path, idx);
err = stat(fullPath, &sstat);
if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) {
err = stat(fullPath, &sb);
if (err == 0 && major(sb.st_rdev) == maj && minor(sb.st_rdev) == min) {
return fullPath;
}
free(fullPath);
Expand All @@ -1372,8 +1372,8 @@ static char* LinuxProcessTable_updateTtyDevice(TtyDriver* ttyDrivers, unsigned l

idx = min;
}
int err = stat(ttyDrivers[i].path, &sstat);
if (err == 0 && tty_nr == sstat.st_rdev) {
int err = stat(ttyDrivers[i].path, &sb);
if (err == 0 && tty_nr == sb.st_rdev) {
return xStrdup(ttyDrivers[i].path);
}
}
Expand Down

0 comments on commit 7017b86

Please sign in to comment.