From deeedf9e5d90b61543bd7efc99f917746ebb3f66 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Mon, 14 Jan 2013 22:58:34 +0100 Subject: [PATCH] Add lchown(2). --- libc/Makefile | 1 + libc/include/unistd.h | 2 +- libc/lchown.cpp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 libc/lchown.cpp diff --git a/libc/Makefile b/libc/Makefile index 82029fbd..3f029bc5 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -167,6 +167,7 @@ ioleast.o \ isatty.o \ kernelinfo.o \ kill.o \ +lchown.o \ linkat.o \ link.o \ localeconv.o \ diff --git a/libc/include/unistd.h b/libc/include/unistd.h index f03ecb1f..0a2e1ec3 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -109,7 +109,6 @@ pid_t getpgid(pid_t); pid_t getpgrp(void); pid_t getsid(pid_t); uid_t getuid(void); -int lchown(const char*, uid_t, gid_t); int lockf(int, int, off_t); int nice(int); long pathconf(const char*, int); @@ -166,6 +165,7 @@ char* get_current_dir_name(void); pid_t getpid(void); pid_t getppid(void); int isatty(int); +int lchown(const char*, uid_t, gid_t); int link(const char*, const char*); int linkat(int, const char*, int, const char*, int); off_t lseek(int, off_t, int); diff --git a/libc/lchown.cpp b/libc/lchown.cpp new file mode 100644 index 00000000..01014731 --- /dev/null +++ b/libc/lchown.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + 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 . + + lchown.cpp + Changes the owner and group of a file. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int lchown(const char* path, uid_t owner, gid_t group) +{ + return fchownat(AT_FDCWD, path, owner, group, AT_SYMLINK_NOFOLLOW); +}