1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:18:11 +00:00

Kernel: Add realpath syscall

This commit is contained in:
Rok Povsic 2019-08-25 18:17:05 +02:00 committed by Andreas Kling
parent 8f50d75184
commit 18fbe4ac83
4 changed files with 34 additions and 0 deletions

View file

@ -1,5 +1,6 @@
#include <AK/ELF/ELFLoader.h>
#include <AK/ELF/exec_elf.h>
#include <AK/FileSystemPath.h>
#include <AK/StdLibExtras.h>
#include <AK/StringBuilder.h>
#include <AK/Time.h>
@ -1806,6 +1807,35 @@ int Process::sys$mkdir(const char* pathname, mode_t mode)
return VFS::the().mkdir(StringView(pathname, pathname_length), mode & ~umask(), current_directory());
}
int Process::sys$realpath(const char* pathname, char* buffer, size_t size)
{
if (!validate_read_str(pathname))
return -EFAULT;
size_t pathname_length = strlen(pathname);
if (pathname_length == 0)
return -EINVAL;
if (pathname_length >= size)
return -ENAMETOOLONG;
if (!validate_write(buffer, size))
return -EFAULT;
auto custody_or_error = VFS::the().resolve_path(pathname, current_directory());
if (custody_or_error.is_error())
return custody_or_error.error();
auto& custody = custody_or_error.value();
// FIXME: Once resolve_path is fixed to deal with .. and . , remove the use of FileSystemPath::canonical_path.
FileSystemPath canonical_path(custody->absolute_path());
if (!canonical_path.is_valid()) {
printf("FileSystemPath failed to canonicalize '%s'\n", custody->absolute_path());
return 1;
}
strncpy(buffer, canonical_path.string().characters(), size);
return 0;
};
clock_t Process::sys$times(tms* times)
{
if (!validate_write_typed(times))