1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:57:44 +00:00

LibCore: Add syscall wrapper for stat()

This commit is contained in:
Andreas Kling 2021-11-23 12:22:21 +01:00
parent 4a213869f2
commit 3db9979e40
2 changed files with 19 additions and 0 deletions

View file

@ -130,4 +130,22 @@ ErrorOr<void> ftruncate(int fd, off_t length)
return {};
}
ErrorOr<struct stat> stat(StringView path)
{
if (!path.characters_without_null_termination())
return Error::from_syscall("stat"sv, -EFAULT);
struct stat st = {};
#ifdef __serenity__
Syscall::SC_stat_params params { { path.characters_without_null_termination(), path.length() }, &st, AT_FDCWD, true };
int rc = syscall(SC_stat, &params);
HANDLE_SYSCALL_RETURN_VALUE("stat"sv, rc, st);
#else
String path_string = path;
if (::stat(path_string.characters(), &st) < 0)
return Error::from_syscall("stat"sv, -errno);
return st;
#endif
}
}