diff options
author | Benny Baumann <BenBE@geshi.org> | 2020-10-29 23:02:57 +0100 |
---|---|---|
committer | Benny Baumann <BenBE@geshi.org> | 2020-11-09 19:17:57 +0100 |
commit | 2d6da2e52066067e4c82a2e16f73438319e1db81 (patch) | |
tree | 5e3180abd332708ae94ec34b56d9e89dddb2a6e5 | |
parent | 84dad4c38ee4eb16ea8716891419b0a3780f3818 (diff) |
Add compat wrapper for readlinkat
-rw-r--r-- | Compat.c | 26 | ||||
-rw-r--r-- | Compat.h | 7 | ||||
-rw-r--r-- | linux/ProcessLocksScreen.c | 20 |
3 files changed, 34 insertions, 19 deletions
@@ -13,9 +13,7 @@ in the source distribution for its full text. #include <sys/stat.h> #include "Compat.h" -#ifndef HAVE_FSTATAT #include "XUtils.h" -#endif int Compat_fstatat(int dirfd, @@ -44,3 +42,27 @@ int Compat_fstatat(int dirfd, #endif } + +int Compat_readlinkat(int dirfd, + const char* dirpath, + const char* pathname, + char* buf, + size_t bufsize) { + +#ifdef HAVE_READLINKAT + + (void)dirpath; + + return readlinkat(dirfd, pathname, buf, bufsize); + +#else + + (void)dirfd; + + char path[4096]; + xSnprintf(path, sizeof(path), "%s/%s", dirpath, pathname); + + return readlink(path, buf, bufsize); + +#endif +} @@ -7,6 +7,7 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include <stddef.h> #include <sys/stat.h> @@ -16,4 +17,10 @@ int Compat_fstatat(int dirfd, struct stat* statbuf, int flags); +int Compat_readlinkat(int dirfd, + const char* dirpath, + const char* pathname, + char* buf, + size_t bufsize); + #endif /* HEADER_Compat */ diff --git a/linux/ProcessLocksScreen.c b/linux/ProcessLocksScreen.c index bdbf22ff..c93d2845 100644 --- a/linux/ProcessLocksScreen.c +++ b/linux/ProcessLocksScreen.c @@ -23,6 +23,7 @@ in the source distribution for its full text. #include <sys/wait.h> #include "CRT.h" +#include "Compat.h" #include "FunctionBar.h" #include "IncSet.h" #include "ProcessList.h" @@ -104,26 +105,11 @@ static char *ProcessLocksScreen_getInodeFilename(pid_t pid, ino_t inode) { if (!strtoull(de->d_name, (char **) NULL, 10)) continue; -#if !defined(HAVE_FSTATAT) || !defined(HAVE_READLINKAT) - char filepath[PATH_MAX + 1]; - xSnprintf(filepath, sizeof(filepath), "%s/%s", path, de->d_name); -#endif - -#ifdef HAVE_FSTATAT - if (!fstatat(fd, de->d_name, &sb, 0) && inode != sb.st_ino) - continue; -#else - if (!stat(filepath, &sb)) && inode != sb.st_ino) + if (!Compat_fstatat(fd, path, de->d_name, &sb, 0) && inode != sb.st_ino) continue; -#endif -#ifdef HAVE_READLINKAT - if ((len = readlinkat(fd, de->d_name, sym, sizeof(sym) - 1)) < 1) - goto out; -#else - if ((len = readlink(filepath, sym, sizeof(sym) - 1)) < 1) + if ((len = Compat_readlinkat(fd, path, de->d_name, sym, sizeof(sym) - 1)) < 1) goto out; -#endif sym[len] = '\0'; |