Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add faccessat() and freadlinkat() compatibility shims.
Landon Fuller committed 11 years ago
commit 8af50093a2b53f6a20fdf5ae0c007013e54850cb
parent 6c8f7a2
2 files changed +54 -2
modified compat/bsd_compat.h
@@ -51,12 +51,23 @@ char *bsd_basename(const char *);
void closefrom(int lowfd);
#endif

-
#if !HAVE_FSTATAT || !HAVE_OPENAT || !HAVE_UNLINKAT || !HAVE_FACCESSAT || !HAVE_READLINKAT
+
#ifndef AT_FDCWD
#define AT_FDCWD		-100
#endif

-
#if !HAVE_FSTATAT
+
#ifndef AT_EACCESS
+
#define AT_EACCESS		0x100
+
#endif
+

+
#ifndef AT_SYMLINK_NOFOLLOW
#define	AT_SYMLINK_NOFOLLOW	0x200
+
#endif
+

+
#if !HAVE_FACCESSAT
+
int faccessat(int fd, const char *path, int mode, int flag);
+
#endif
+

+
#if !HAVE_FSTATAT
int fstatat(int fd, const char *path, struct stat *buf, int flag);
#endif

@@ -64,6 +75,10 @@ int fstatat(int fd, const char *path, struct stat *buf, int flag);
int openat(int fd, const char *path, int flags, ...);
#endif

+
#if !HAVE_READLINKAT
+
ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize);
+
#endif
+

#if !HAVE_UNLINKAT
#define AT_REMOVEDIR	0x800
int unlinkat(int fd, const char *path, int flag);
modified compat/file_at.c
@@ -85,6 +85,43 @@ file_chdir_unlock(int dfd)
}
#endif

+
#if !HAVE_FACCESSAT
+
int
+
faccessat(int fd, const char *path, int mode, int flag)
+
{
+
	int ret;
+

+
	if ((ret = file_chdir_lock(fd) != 0))
+
		return ret;
+

+
	if (flag & AT_EACCESS) {
+
		ret = eaccess(path, mode);
+
	} else {
+
		ret = access(path, mode);
+
	}
+

+
	file_chdir_unlock(fd);
+
	return ret;
+
}
+
#endif
+

+
#if !HAVE_READLINKAT
+
ssize_t
+
readlinkat(int fd, const char *restrict path, char *restrict buf,
+
	   size_t bufsize)
+
{
+
	int ret;
+

+
	if ((ret = file_chdir_lock(fd) != 0))
+
		return ret;
+

+
	ret = readlink(path, buf, bufsize);
+

+
	file_chdir_unlock(fd);
+
	return ret;
+
}
+
#endif
+

#if !HAVE_FSTATAT
int
fstatat(int fd, const char *path, struct stat *buf, int flag)