[openssh-commits] [openssh] branch master updated: Add minimal implementations of fstatat and unlinkat.

git+noreply at mindrot.org git+noreply at mindrot.org
Tue May 6 20:03:47 AEST 2025


This is an automated email from the git hooks/post-receive script.

dtucker pushed a commit to branch master
in repository openssh.

The following commit(s) were added to refs/heads/master by this push:
     new 5fd6ef297 Add minimal implementations of fstatat and unlinkat.
5fd6ef297 is described below

commit 5fd6ef297dec23e3574646b6334087131230d0a6
Author: Darren Tucker <dtucker at dtucker.net>
AuthorDate: Tue May 6 19:01:00 2025 +1000

    Add minimal implementations of fstatat and unlinkat.
    
    Fixes build on some pre-POSIX.1-2008 platforms.
---
 configure.ac              |  2 ++
 openbsd-compat/bsd-misc.c | 40 ++++++++++++++++++++++++++++++++++++++++
 openbsd-compat/bsd-misc.h |  8 ++++++++
 3 files changed, 50 insertions(+)

diff --git a/configure.ac b/configure.ac
index 69b74add8..b19f790cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2004,6 +2004,7 @@ AC_CHECK_FUNCS([ \
 	fnmatch \
 	freeaddrinfo \
 	freezero \
+	fstatat \
 	fstatfs \
 	fstatvfs \
 	futimes \
@@ -2099,6 +2100,7 @@ AC_CHECK_FUNCS([ \
 	timegm \
 	timingsafe_bcmp \
 	truncate \
+	unlinkat \
 	unsetenv \
 	updwtmpx \
 	utimensat \
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 226a5915b..b26b4ba46 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -220,6 +220,46 @@ fchmodat(int fd, const char *path, mode_t mode, int flag)
 }
 #endif
 
+#ifndef HAVE_FSTATAT
+/*
+ * A limited implementation of fstatat that just has what OpenSSH uses:
+ * cwd-relative and absolute paths, with or without following symlinks.
+ */
+int
+fstatat(int dirfd, const char *path, struct stat *sb, int flag)
+{
+	if (dirfd != AT_FDCWD && path && path[0] != '/') {
+		errno = ENOSYS;
+		return -1;
+	}
+	if (flag == 0)
+		return stat(path, sb);
+	else if (flag == AT_SYMLINK_NOFOLLOW)
+		return lstat(path, sb);
+	errno = ENOSYS;
+	return -1;
+}
+#endif
+
+#ifndef HAVE_UNLINKAT
+/*
+ * A limited implementation of unlinkat that just has what OpenSSH uses:
+ * cwd-relative and absolute paths.
+ */
+int
+unlinkat(int dirfd, const char *path, int flag)
+{
+	if (dirfd != AT_FDCWD && path && path[0] != '/') {
+		errno = ENOSYS;
+		return -1;
+	}
+	if (flag == 0)
+		return unlink(path);
+	errno = ENOSYS;
+	return -1;
+}
+#endif
+
 #ifndef HAVE_TRUNCATE
 int truncate(const char *path, off_t length)
 {
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index 61ead1b7f..edb0fcc8c 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -77,6 +77,14 @@ int fchmodat(int, const char *, mode_t, int);
 int fchownat(int, const char *, uid_t, gid_t, int);
 #endif
 
+#ifdef HAVE_FSTATAT
+int fstatat(int, const char *, struct stat *, int);
+#endif
+
+#ifdef HAVE_UNLINKAT
+int unlinkat(int, const char *, int);
+#endif
+
 #ifndef HAVE_TRUNCATE
 int truncate (const char *, off_t);
 #endif /* HAVE_TRUNCATE */

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list