Move initialization of /dev/zero and /dev/null, meet POSIX standard

This commit is contained in:
Ivan 2024-04-11 10:17:42 +03:00 committed by GitHub
parent 7dfd4a8140
commit 22bdeaf03d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 4 deletions

View File

@ -90,8 +90,6 @@ class FileManager: public IFileManager {
assert(addFile(createType_in(), "/dev/stdin") == 0);
assert(addFile(createType_out(SCE_TYPEOUT_ERROR), "/dev/stdout") == 1);
assert(addFile(createType_out(SCE_TYPEOUT_DEBUG), "/dev/stderr") == 2);
addFile(createType_zero(), "/dev/zero");
addFile(createType_null(), "/dev/null");
}
void addMountPoint(std::string_view mountPoint, std::filesystem::path const& root, MountType type) final {

View File

@ -24,7 +24,7 @@ std::unique_ptr<IFile> createType_null() {
}
size_t TypeNull::read(void* buf, size_t nbytes) {
return nbytes;
return -1;
}
size_t TypeNull::write(void* buf, size_t nbytes) {

View File

@ -30,7 +30,7 @@ size_t TypeZero::read(void* buf, size_t nbytes) {
}
size_t TypeZero::write(void* buf, size_t nbytes) {
return 0;
return nbytes;
}
void TypeZero::sync() {}

View File

@ -5,6 +5,8 @@
#include "core/fileManager/types/type_file.h"
#include "core/fileManager/types/type_random.h"
#include "core/fileManager/types/type_rng.h"
#include "core/fileManager/types/type_null.h"
#include "core/fileManager/types/type_zero.h"
#include "core/memory/memory.h"
#include "logging.h"
@ -37,6 +39,10 @@ std::unique_ptr<IFile> createType_dev(std::filesystem::path path, std::ios_base:
return createType_random();
} else if (path == "/dev/rng") {
return createType_rng();
} else if (path == "/dev/zero") {
return createType_zero();
} else if (path == "/dev/null") {
return createType_null();
} else { // todo: other devices
LOG_CRIT(L"%S: unknown device!", path.c_str());
}