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

Kernel+LibC: Implement FIONREAD ioctl

FIONREAD gets the number of bytes availible to read from a file
descriptor without blocking. I only implemented it for regular files and
sockets
This commit is contained in:
Peter Elliott 2021-07-26 23:06:22 -06:00 committed by Andreas Kling
parent db92e66902
commit 39a77559f1
7 changed files with 38 additions and 4 deletions

View file

@ -16,6 +16,7 @@
#include <Kernel/StdLib.h>
#include <Kernel/UnixTypes.h>
#include <LibC/errno_numbers.h>
#include <LibC/sys/ioctl_numbers.h>
namespace Kernel {
@ -431,6 +432,21 @@ KResult LocalSocket::getsockopt(FileDescription& description, int level, int opt
}
}
KResult LocalSocket::ioctl(FileDescription& description, unsigned request, Userspace<void*> arg)
{
switch (request) {
case FIONREAD: {
int readable = receive_buffer_for(description)->immediately_readable();
if (!copy_to_user(Userspace<int*>(arg), &readable))
return EFAULT;
return KSuccess;
}
}
return ENOTTY;
}
KResult LocalSocket::chmod(FileDescription&, mode_t mode)
{
if (m_file)