]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
Add minimal implementations of fstatat and unlinkat.
authorDarren Tucker <dtucker@dtucker.net>
Tue, 6 May 2025 09:01:00 +0000 (19:01 +1000)
committerDarren Tucker <dtucker@dtucker.net>
Tue, 6 May 2025 10:02:38 +0000 (20:02 +1000)
Fixes build on some pre-POSIX.1-2008 platforms.

configure.ac
openbsd-compat/bsd-misc.c
openbsd-compat/bsd-misc.h

index 69b74add8d00d3340bf1d325f4e021d0b93cf03c..b19f790cdd5401866368ffb40209f702e7e10a1f 100644 (file)
@@ -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 \
index 226a5915bd1dd3d0e405ea2fb57d5d58a819031a..b26b4ba4670ed4eade36411d6dfb61a284201b98 100644 (file)
@@ -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)
 {
index 61ead1b7fad0ad871fa54c4cf833a51d7a9573ba..edb0fcc8ca2bdb74a35331cbd7ee8c233f8188af 100644 (file)
@@ -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 */