From b90fdf618f13b2ba4f64ba0f1861088c2ae58844 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Sun, 5 Feb 2023 03:20:15 +0100 Subject: New upstream version 3.2.2 --- Compat.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'Compat.c') diff --git a/Compat.c b/Compat.c index 43d02ec..d0ad2cc 100644 --- a/Compat.c +++ b/Compat.c @@ -1,7 +1,7 @@ /* htop - Compat.c (C) 2020 htop dev team -Released under the GNU GPLv2, see the COPYING file +Released under the GNU GPLv2+, see the COPYING file in the source distribution for its full text. */ @@ -11,6 +11,7 @@ in the source distribution for its full text. #include #include // IWYU pragma: keep +#include #include #include #include // IWYU pragma: keep @@ -18,6 +19,12 @@ in the source distribution for its full text. #include "XUtils.h" // IWYU pragma: keep +/* GNU/Hurd does not have PATH_MAX in limits.h */ +#ifndef PATH_MAX +# define PATH_MAX 4096 +#endif + + int Compat_faccessat(int dirfd, const char* pathname, int mode, @@ -37,14 +44,14 @@ int Compat_faccessat(int dirfd, #endif // Error out on unsupported configurations - if (dirfd != AT_FDCWD || mode != F_OK) { + if (dirfd != (int)AT_FDCWD || mode != F_OK) { errno = EINVAL; return -1; } // Fallback to stat(2)/lstat(2) depending on flags struct stat statinfo; - if(flags) { + if (flags) { ret = lstat(pathname, &statinfo); } else { ret = stat(pathname, &statinfo); @@ -117,3 +124,33 @@ ssize_t Compat_readlinkat(int dirfd, #endif } + +ssize_t Compat_readlink(openat_arg_t dirfd, + const char* pathname, + char* buf, + size_t bufsize) { + +#ifdef HAVE_OPENAT + + char fdPath[32]; + xSnprintf(fdPath, sizeof(fdPath), "/proc/self/fd/%d", dirfd); + + char dirPath[PATH_MAX + 1]; + ssize_t r = readlink(fdPath, dirPath, sizeof(dirPath) - 1); + if (r < 0) + return r; + + dirPath[r] = '\0'; + + char linkPath[PATH_MAX + 1]; + xSnprintf(linkPath, sizeof(linkPath), "%s/%s", dirPath, pathname); + +#else + + char linkPath[PATH_MAX + 1]; + xSnprintf(linkPath, sizeof(linkPath), "%s/%s", dirfd, pathname); + +#endif /* HAVE_OPENAT */ + + return readlink(linkPath, buf, bufsize); +} -- cgit v1.2.3