[PATCH] [klibc] add minimal faccessat()

maximilian attems max at stro.at
Thu Apr 15 20:18:40 PDT 2010


Implement as wrapper around sys_faccessat().

Latest dash started using it, also define AT_EACCESS:
usr/dash/bltin/test.c: In function ‘test_file_access’:
usr/dash/bltin/test.c:490: error: too many arguments to function ‘faccessat’

Signed-off-by: maximilian attems <max at stro.at>
---
 usr/include/fcntl.h    |    5 +++++
 usr/include/unistd.h   |    2 +-
 usr/klibc/Kbuild       |    2 +-
 usr/klibc/SYSCALLS.def |    2 +-
 usr/klibc/faccessat.c  |   26 ++++++++++++++++++++++++++
 5 files changed, 34 insertions(+), 3 deletions(-)
 create mode 100644 usr/klibc/faccessat.c

diff --git a/usr/include/fcntl.h b/usr/include/fcntl.h
index 0908e21..2cff616 100644
--- a/usr/include/fcntl.h
+++ b/usr/include/fcntl.h
@@ -13,6 +13,11 @@
 #endif
 #include <linux/fcntl.h>
 
+/* missing in linux/fcntl.h */
+#ifndef AT_EACCESS
+# define AT_EACCESS	0x200
+#endif
+
 /* This is ugly, but "struct flock" has actually been defined with
    a long off_t, so it's really "struct flock64".  It just happens
    to work.  Gag.  Barf.
diff --git a/usr/include/unistd.h b/usr/include/unistd.h
index 547e717..8cb2877 100644
--- a/usr/include/unistd.h
+++ b/usr/include/unistd.h
@@ -58,7 +58,7 @@ __extern int setfsuid(uid_t);
 #define F_OK	0		/* Existence */
 
 __extern int access(const char *, int);
-__extern int faccessat(int, const char *, int);
+__extern int faccessat(int, const char *, int, int);
 __extern int link(const char *, const char *);
 __extern int linkat(int, const char *, int, const char *);
 __extern int unlink(const char *);
diff --git a/usr/klibc/Kbuild b/usr/klibc/Kbuild
index ab5212b..765052a 100644
--- a/usr/klibc/Kbuild
+++ b/usr/klibc/Kbuild
@@ -19,7 +19,7 @@ klib-y := vsnprintf.o snprintf.o vsprintf.o sprintf.o \
 	  printf.o vprintf.o fprintf.o vfprintf.o perror.o \
 	  statfs.o fstatfs.o umount.o \
 	  creat.o open.o openat.o open_cloexec.o \
-	  fopen.o fread.o fread2.o fgetc.o fgets.o \
+	  fopen.o fread.o fread2.o fgetc.o fgets.o faccessat.o \
 	  fwrite.o fwrite2.o fputc.o fputs.o puts.o putchar.o \
 	  sleep.o usleep.o strtotimespec.o strtotimeval.o \
 	  raise.o abort.o assert.o alarm.o pause.o \
diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def
index ae58b9b..896452c 100644
--- a/usr/klibc/SYSCALLS.def
+++ b/usr/klibc/SYSCALLS.def
@@ -98,7 +98,7 @@ int swapoff(const char *);
  * Inode-related system calls
  */
 int access(const char *, int);
-<?> int faccessat(int, const char *, int);
+<?> int faccessat::__faccessat(int, const char *, int);
 int link(const char *, const char *);
 <?> int linkat(int, const char *, int, const char *);
 int unlink(const char *);
diff --git a/usr/klibc/faccessat.c b/usr/klibc/faccessat.c
new file mode 100644
index 0000000..f18cf84
--- /dev/null
+++ b/usr/klibc/faccessat.c
@@ -0,0 +1,26 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+extern int __faccessat(int dirfd, const char *pathname, int mode);
+
+int faccessat(int dirfd, const char *pathname, int mode, int flags)
+{
+
+	/* ignoring AT_EACCESS subsequently */
+	if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS)) {
+		errno = EINVAL;
+		return -1;
+	}
+	if (dirfd < 0 && dirfd != AT_FDCWD) {
+		errno = EBADF;
+		return -1;
+	}
+	if (!pathname) {
+		errno = ENOENT;
+		return -1;
+	}
+
+	/* FIXME: use AT_SYMLINK_NOFOLLOW value */
+	return __faccessat(dirfd, pathname, mode);
+}
-- 
1.7.0.4



More information about the klibc mailing list