aboutsummaryrefslogtreecommitdiffstats
path: root/Compat.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
committerDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
commit65357c8c46154de4e4eca14075bfe5523bb5fc14 (patch)
tree8f430ee5a0d5de377c4e7c94e47842a27c70d7e8 /Compat.c
parentf80394a20254938142011855f2954b3f63fe5909 (diff)
downloaddebian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.gz
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.bz2
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.zip
New upstream version 3.0.3upstream/3.0.3
Diffstat (limited to 'Compat.c')
-rw-r--r--Compat.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/Compat.c b/Compat.c
new file mode 100644
index 0000000..43d02ec
--- /dev/null
+++ b/Compat.c
@@ -0,0 +1,119 @@
+/*
+htop - Compat.c
+(C) 2020 htop dev team
+Released under the GNU GPLv2, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "config.h" // IWYU pragma: keep
+
+#include "Compat.h"
+
+#include <errno.h>
+#include <fcntl.h> // IWYU pragma: keep
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h> // IWYU pragma: keep
+
+#include "XUtils.h" // IWYU pragma: keep
+
+
+int Compat_faccessat(int dirfd,
+ const char* pathname,
+ int mode,
+ int flags) {
+ int ret;
+
+#ifdef HAVE_FACCESSAT
+
+ // Implementation note: AT_SYMLINK_NOFOLLOW unsupported on FreeBSD, fallback to lstat in that case
+
+ errno = 0;
+
+ ret = faccessat(dirfd, pathname, mode, flags);
+ if (!ret || errno != EINVAL)
+ return ret;
+
+#endif
+
+ // Error out on unsupported configurations
+ if (dirfd != AT_FDCWD || mode != F_OK) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ // Fallback to stat(2)/lstat(2) depending on flags
+ struct stat statinfo;
+ if(flags) {
+ ret = lstat(pathname, &statinfo);
+ } else {
+ ret = stat(pathname, &statinfo);
+ }
+
+ return ret;
+}
+
+int Compat_fstatat(int dirfd,
+ const char* dirpath,
+ const char* pathname,
+ struct stat* statbuf,
+ int flags) {
+
+#ifdef HAVE_FSTATAT
+
+ (void)dirpath;
+
+ return fstatat(dirfd, pathname, statbuf, flags);
+
+#else
+
+ (void)dirfd;
+
+ char path[4096];
+ xSnprintf(path, sizeof(path), "%s/%s", dirpath, pathname);
+
+ if (flags & AT_SYMLINK_NOFOLLOW)
+ return lstat(path, statbuf);
+
+ return stat(path, statbuf);
+
+#endif
+}
+
+#ifndef HAVE_OPENAT
+
+int Compat_openat(const char* dirpath,
+ const char* pathname,
+ int flags) {
+
+ char path[4096];
+ xSnprintf(path, sizeof(path), "%s/%s", dirpath, pathname);
+
+ return open(path, flags);
+}
+
+#endif /* !HAVE_OPENAT */
+
+ssize_t 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
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy