diff options
author | Daniel Lange <DLange@git.local> | 2023-02-05 03:20:15 +0100 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2023-02-05 03:20:15 +0100 |
commit | b90fdf618f13b2ba4f64ba0f1861088c2ae58844 (patch) | |
tree | da70bf44b2423f6f8e9a070c063fed79d190b489 /Compat.c | |
parent | 65357c8c46154de4e4eca14075bfe5523bb5fc14 (diff) | |
download | debian_htop-b90fdf618f13b2ba4f64ba0f1861088c2ae58844.tar.gz debian_htop-b90fdf618f13b2ba4f64ba0f1861088c2ae58844.tar.bz2 debian_htop-b90fdf618f13b2ba4f64ba0f1861088c2ae58844.zip |
New upstream version 3.2.2
Diffstat (limited to 'Compat.c')
-rw-r--r-- | Compat.c | 43 |
1 files changed, 40 insertions, 3 deletions
@@ -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 <errno.h> #include <fcntl.h> // IWYU pragma: keep +#include <limits.h> #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> // 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); +} |