diff --git a/libc/Makefile b/libc/Makefile
index 48dcf069..fc251f0d 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -140,6 +140,7 @@ _Exit.o \
exit.o \
faccessat.o \
fchdir.o \
+fchmodat.o \
fchmod.o \
fchownat.o \
fchown.o \
diff --git a/libc/fchmodat.cpp b/libc/fchmodat.cpp
new file mode 100644
index 00000000..0eda2fa9
--- /dev/null
+++ b/libc/fchmodat.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 .
+
+ fchmodat.cpp
+ Changes the mode bits of a file.
+
+*******************************************************************************/
+
+#include
+#include
+#include
+
+DEFN_SYSCALL4(int, sys_fchmodat, SYSCALL_FCHMODAT, int, const char*, mode_t, int);
+
+extern "C" int fchmodat(int dirfd, const char* path, mode_t mode, int flags)
+{
+ return sys_fchmodat(dirfd, path, mode, flags);
+}
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 46422061..c085201d 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -48,6 +48,7 @@ __BEGIN_DECLS
int chmod(const char* path, mode_t mode);
int fchmod(int fd, mode_t mode);
+int fchmodat(int dirfd, const char* path, mode_t mode, int flags);
int fstat(int fd, struct stat* st);
int fstatat(int dirfd, const char* path, struct stat* buf, int flags);
int lstat(const char* restrict path, struct stat* restrict st);
diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h
index 27907bd6..1a4da48a 100644
--- a/sortix/include/sortix/syscallnum.h
+++ b/sortix/include/sortix/syscallnum.h
@@ -90,6 +90,7 @@
#define SYSCALL_FCHOWNAT 66
#define SYSCALL_FCHOWN 67
#define SYSCALL_FCHMOD 68
-#define SYSCALL_MAX_NUM 69 /* index of highest constant + 1 */
+#define SYSCALL_FCHMODAT 69
+#define SYSCALL_MAX_NUM 70 /* index of highest constant + 1 */
#endif
diff --git a/sortix/io.cpp b/sortix/io.cpp
index 0c6b300b..04b3fe67 100644
--- a/sortix/io.cpp
+++ b/sortix/io.cpp
@@ -393,14 +393,17 @@ static int sys_fchmod(int fd, mode_t mode)
return desc->chmod(&ctx, mode);
}
-static int sys_chmod(const char* path, mode_t mode)
+static int sys_fchmodat(int dirfd, const char* path, mode_t mode, int flags)
{
+ if ( flags )
+ return errno = ENOTSUP, -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_WRONLY);
from.Reset();
delete[] pathcopy;
@@ -409,6 +412,11 @@ static int sys_chmod(const char* path, mode_t mode)
return desc->chmod(&ctx, mode);
}
+static int sys_chmod(const char* path, mode_t mode)
+{
+ return sys_fchmodat(AT_FDCWD, path, mode, 0);
+}
+
static int sys_link(const char* oldpath, const char* newpath)
{
ioctx_t ctx; SetupUserIOCtx(&ctx);
@@ -487,6 +495,7 @@ void Init()
Syscall::Register(SYSCALL_DUP2, (void*) sys_dup2);
Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat);
Syscall::Register(SYSCALL_FCHDIR, (void*) sys_fchdir);
+ Syscall::Register(SYSCALL_FCHMODAT, (void*) sys_fchmodat);
Syscall::Register(SYSCALL_FCHMOD, (void*) sys_fchmod);
Syscall::Register(SYSCALL_FCHOWNAT, (void*) sys_fchownat);
Syscall::Register(SYSCALL_FCHOWN, (void*) sys_fchown);