mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-06 15:05:59 +00:00
Initial commit
This commit is contained in:
commit
1fdadaaee9
38 changed files with 5512 additions and 0 deletions
49
rpcsx-os/iodev/stdout.cpp
Normal file
49
rpcsx-os/iodev/stdout.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#include "io-device.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
struct StdoutInstance : public IoDeviceInstance {};
|
||||
|
||||
struct StdoutDevice : public IoDevice {
|
||||
StdoutInstance *instance = nullptr;
|
||||
};
|
||||
|
||||
static std::int64_t stdout_instance_write(IoDeviceInstance *instance,
|
||||
const void *data,
|
||||
std::uint64_t size) {
|
||||
auto result = std::fwrite(data, 1, size, stdout);
|
||||
std::fflush(stdout);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::int64_t stdout_instance_close(IoDeviceInstance *instance) {
|
||||
instance->device->decRef();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static std::int32_t stdout_device_open(IoDevice *device,
|
||||
orbis::Ref<IoDeviceInstance> *instance,
|
||||
const char *path, std::uint32_t flags,
|
||||
std::uint32_t mode) {
|
||||
auto stdoutDevice = static_cast<StdoutDevice *>(device);
|
||||
if (stdoutDevice->instance == nullptr) {
|
||||
auto *newInstance = new StdoutInstance{};
|
||||
newInstance->write = stdout_instance_write;
|
||||
newInstance->close = stdout_instance_close;
|
||||
io_device_instance_init(device, newInstance);
|
||||
|
||||
*instance = newInstance;
|
||||
} else {
|
||||
device->incRef();
|
||||
*instance = stdoutDevice->instance;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
IoDevice *createStdoutCharacterDevice() {
|
||||
auto *newDevice = new StdoutDevice();
|
||||
newDevice->open = stdout_device_open;
|
||||
return newDevice;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue