summaryrefslogtreecommitdiffstats
path: root/Compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'Compat.c')
-rw-r--r--Compat.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/Compat.c b/Compat.c
index 1077c08b..6df0b081 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 <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,
@@ -43,11 +50,11 @@ int Compat_faccessat(int dirfd,
}
// Fallback to stat(2)/lstat(2) depending on flags
- struct stat statinfo;
- if(flags) {
- ret = lstat(pathname, &statinfo);
+ struct stat sb;
+ if (flags) {
+ ret = lstat(pathname, &sb);
} else {
- ret = stat(pathname, &statinfo);
+ ret = stat(pathname, &sb);
}
return ret;
@@ -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);
+}