diff --git a/libc/Makefile b/libc/Makefile
index 5182a72f..408d35c7 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -138,6 +138,7 @@ execvp.o \
_exit.o \
_Exit.o \
exit.o \
+faccessat.o \
fchmod.o \
fcloseall.o \
fcntl.o \
diff --git a/libc/faccessat.cpp b/libc/faccessat.cpp
new file mode 100644
index 00000000..6d2803b6
--- /dev/null
+++ b/libc/faccessat.cpp
@@ -0,0 +1,34 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ faccessat.cpp
+ Check real user's permissions for a file
+
+*******************************************************************************/
+
+#include
+#include
+#include
+
+DEFN_SYSCALL4(int, sys_faccessat, SYSCALL_FACCESSAT, int, const char*, int, int);
+
+extern "C" int faccessat(int dirfd, const char* path, int mode, int flags)
+{
+ return sys_faccessat(dirfd, path, mode, flags);
+}
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 0a04daf7..643a756c 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -92,7 +92,6 @@ size_t confstr(int, char*, size_t);
char* crypt(const char*, const char*);
char* ctermid(char*);
void encrypt(char [64], int);
-int faccessat(int, const char*, int, int);
int fchdir(int);
int fchown(int, uid_t, gid_t);
int fchownat(int, const char*, uid_t, gid_t, int);
@@ -161,6 +160,7 @@ int execv(const char*, char* const []);
int execve(const char*, char* const [], char* const []);
int execvp(const char*, char* const []);
pid_t fork(void);
+int faccessat(int, const char*, int, int);
int ftruncate(int, off_t);
char* getcwd(char*, size_t);
char* get_current_dir_name(void);
diff --git a/sortix/include/sortix/fcntl.h b/sortix/include/sortix/fcntl.h
index f86a93ec..3d88843d 100644
--- a/sortix/include/sortix/fcntl.h
+++ b/sortix/include/sortix/fcntl.h
@@ -56,6 +56,8 @@ __BEGIN_DECLS
#define AT_FDCWD (-100)
#define AT_REMOVEDIR (1<<0)
+#define AT_EACCESS (1<<1)
+#define AT_SYMLINK_NOFOLLOW (1<<2)
__END_DECLS
diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h
index 11578284..cde733ed 100644
--- a/sortix/include/sortix/syscallnum.h
+++ b/sortix/include/sortix/syscallnum.h
@@ -83,6 +83,7 @@
#define SYSCALL_LINK 59
#define SYSCALL_DUP2 60
#define SYSCALL_UNLINKAT 61
-#define SYSCALL_MAX_NUM 62 /* index of highest constant + 1 */
+#define SYSCALL_FACCESSAT 62
+#define SYSCALL_MAX_NUM 63 /* index of highest constant + 1 */
#endif
diff --git a/sortix/io.cpp b/sortix/io.cpp
index 3d32c2da..23e5c9b3 100644
--- a/sortix/io.cpp
+++ b/sortix/io.cpp
@@ -158,19 +158,27 @@ static int sys_open(const char* path, int flags, mode_t mode)
}
// TODO: This is a hack! Stat the file in some manner and check permissions.
-static int sys_access(const char* path, int /*mode*/)
+static int sys_faccessat(int dirfd, const char* path, int /*mode*/, int flags)
{
+ if ( flags )
+ return errno = ENOSYS, -1;
char* pathcopy = GetStringFromUser(path);
if ( !pathcopy )
return -1;
ioctx_t ctx; SetupUserIOCtx(&ctx);
const char* relpath = pathcopy;
- Ref from = PrepareLookup(&relpath);
+ Ref from = PrepareLookup(&relpath, dirfd);
+ if ( !from ) { delete[] pathcopy; return -1; }
Ref desc = from->open(&ctx, relpath, O_RDONLY);
delete[] pathcopy;
return desc ? 0 : -1;
}
+static int sys_access(const char* path, int mode)
+{
+ return sys_faccessat(AT_FDCWD, path, mode, 0);
+}
+
static int sys_unlinkat(int dirfd, const char* path, int flags)
{
char* pathcopy = GetStringFromUser(path);
@@ -429,6 +437,7 @@ void Init()
Syscall::Register(SYSCALL_CLOSE, (void*) sys_close);
Syscall::Register(SYSCALL_DUP, (void*) sys_dup);
Syscall::Register(SYSCALL_DUP2, (void*) sys_dup2);
+ Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat);
Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);
Syscall::Register(SYSCALL_FSTATAT, (void*) sys_fstatat);
Syscall::Register(SYSCALL_FSTAT, (void*) sys_fstat);