ladybird/Kernel/Devices/RandomDevice.cpp

29 lines
563 B
C++
Raw Normal View History

#include <Kernel/Devices/RandomDevice.h>
#include <Kernel/Random.h>
2018-10-15 01:44:54 +03:00
RandomDevice::RandomDevice()
: CharacterDevice(1, 8)
2018-10-15 01:44:54 +03:00
{
}
RandomDevice::~RandomDevice()
{
}
bool RandomDevice::can_read(const FileDescription&) const
{
return true;
}
ssize_t RandomDevice::read(FileDescription&, u8* buffer, ssize_t size)
2018-10-15 01:44:54 +03:00
{
get_good_random_bytes(buffer, size);
return size;
2018-10-15 01:44:54 +03:00
}
ssize_t RandomDevice::write(FileDescription&, const u8*, ssize_t size)
2018-10-15 01:44:54 +03:00
{
// FIXME: Use input for entropy? I guess that could be a neat feature?
2019-04-03 14:18:42 +03:00
return min(PAGE_SIZE, size);
2018-10-15 01:44:54 +03:00
}