From 4abab5ad6c8465a7528ccdd5f49367da05f78bbd Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Tue, 1 Oct 2024 15:47:05 +0200 Subject: Initial version --- src/unistd/fchown.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/unistd/fchown.c (limited to 'src/unistd/fchown.c') diff --git a/src/unistd/fchown.c b/src/unistd/fchown.c new file mode 100644 index 0000000..737b367 --- /dev/null +++ b/src/unistd/fchown.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include "syscall.h" + +int fchown(int fd, uid_t uid, gid_t gid) +{ + int ret = __syscall(SYS_fchown, fd, uid, gid); + if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0) + return __syscall_ret(ret); + + char buf[15+3*sizeof(int)]; + __procfdname(buf, fd); +#ifdef SYS_chown + return syscall(SYS_chown, buf, uid, gid); +#else + return syscall(SYS_fchownat, AT_FDCWD, buf, uid, gid, 0); +#endif + +} -- cgit v1.2.3