libc: Add symlink(), symlinkat(), and lstat()

This commit is contained in:
apio 2023-05-20 21:47:20 +02:00
parent 67a9d130e2
commit cb205c851c
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 27 additions and 0 deletions

View File

@ -29,6 +29,9 @@ extern "C"
#pragma GCC pop_options
/* Retrieve information about a file or symbolic link. */
int lstat(const char* path, struct stat* st);
/* Retrieve information about a file. */
int fstat(int fd, struct stat* st);

View File

@ -133,6 +133,12 @@ extern "C"
/* Create a pipe for inter-process communication. */
int pipe(int pfds[2]);
/* Create a symbolic link. */
int symlink(const char* target, const char* linkpath);
/* Create a symbolic link relative to a file descriptor. */
int symlinkat(const char* target, int dirfd, const char* linkpath);
#ifdef __cplusplus
}
#endif

View File

@ -30,6 +30,12 @@ extern "C"
__errno_return(rc, int);
}
int lstat(const char* path, struct stat* st)
{
long rc = syscall(SYS_fstatat, AT_FDCWD, path, st, AT_SYMLINK_NOFOLLOW);
__errno_return(rc, int);
}
int fstat(int fd, struct stat* st)
{
long rc = syscall(SYS_fstatat, fd, "", st, AT_EMPTY_PATH);

View File

@ -406,4 +406,16 @@ extern "C"
long rc = syscall(SYS_pipe, (int*)pfds);
__errno_return(rc, int);
}
int symlink(const char* target, const char* linkpath)
{
long rc = syscall(SYS_symlinkat, target, AT_FDCWD, linkpath);
__errno_return(rc, int);
}
int symlinkat(const char* target, int dirfd, const char* linkpath)
{
long rc = syscall(SYS_symlinkat, target, dirfd, linkpath);
__errno_return(rc, int);
}
}