libc: Add fchown, fchmod, and some POSIX feature test macros
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-05-19 19:59:20 +02:00
parent 3db0c4fed2
commit dc169124cc
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 21 additions and 0 deletions

View File

@ -18,6 +18,9 @@ extern "C"
/* Change the mode bits of a file. */
int chmod(const char* path, mode_t mode);
/* Change the mode bits of a file descriptor. */
int fchmod(int fd, mode_t mode);
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wshadow"

View File

@ -14,6 +14,9 @@
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#define _POSIX_CHOWN_RESTRICTED 200112L
#define _POSIX_SHELL 200112L
#ifdef __cplusplus
extern "C"
{
@ -55,6 +58,9 @@ extern "C"
/* Change the owner and group of a file. */
int chown(const char* path, uid_t uid, gid_t gid);
/* Change the owner and group of a file descriptor. */
int fchown(int fd, uid_t uid, gid_t gid);
/* Replace the current process with another one. On success, does not return. */
int execv(const char* path, char* const* argv);

View File

@ -18,6 +18,12 @@ extern "C"
__errno_return(rc, int);
}
int fchmod(int fd, mode_t mode)
{
long rc = syscall(SYS_fchmodat, fd, "", mode, AT_EMPTY_PATH);
__errno_return(rc, int);
}
int stat(const char* path, struct stat* st)
{
long rc = syscall(SYS_fstatat, AT_FDCWD, path, st, 0);

View File

@ -148,6 +148,12 @@ extern "C"
__errno_return(rc, int);
}
int fchown(int fd, uid_t uid, gid_t gid)
{
long rc = syscall(SYS_fchownat, fd, "", uid, gid, AT_EMPTY_PATH);
__errno_return(rc, int);
}
int execv(const char* path, char* const* argv)
{
return execve(path, argv, environ);