1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

Kernel+LibC: Do not return -ENAMETOOLONG from sys$readlink()

That's not how readlink() is supposed to work: it should copy as many bytes
as fit into the buffer, and return the number of bytes copied. So do that,
but add a twist: make sys$readlink() actually return the whole size, not
the number of bytes copied. We fix up this return value in userspace, to make
LibC's readlink() behave as expected, but this will also allow other code
to allocate a buffer of just the right size.

Also, avoid an extra copy of the link target.
This commit is contained in:
Sergey Bugaev 2020-06-16 21:51:08 +03:00 committed by Andreas Kling
parent 35329400b8
commit 47d83800e1
2 changed files with 7 additions and 6 deletions

View file

@ -364,7 +364,8 @@ ssize_t readlink(const char* path, char* buffer, size_t size)
{
Syscall::SC_readlink_params params { { path, strlen(path) }, { buffer, size } };
int rc = syscall(SC_readlink, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
// Return the number of bytes placed in the buffer, not the full path size.
__RETURN_WITH_ERRNO(rc, min((size_t)rc, size), -1);
}
off_t lseek(int fd, off_t offset, int whence)