refactor des clibs et suppression de file.cc qui etait inutile

This commit is contained in:
Marc
2022-02-15 12:26:30 +01:00
parent bb8f751606
commit 205de4293b
6 changed files with 110 additions and 76 deletions
+95
View File
@@ -1,3 +1,98 @@
{
"python.linting.enabled": false,
"files.associations": {
"*.ejs": "html",
"*.inc": "cpp",
"internet": "cpp",
"socket": "cpp",
"functional": "c",
"cmath": "cpp",
"cstdlib": "cpp",
"hash_map": "cpp",
"cwchar": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwctype": "cpp",
"bitset": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"algorithm": "cpp",
"array": "cpp",
"chrono": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"atomic": "cpp",
"bit": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"fstream": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeindex": "cpp",
"valarray": "cpp",
"variant": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"compare": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"new": "cpp",
"typeinfo": "cpp",
"*.tcc": "cpp",
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"ios": "cpp",
"locale": "cpp",
"queue": "cpp",
"stack": "cpp"
},
}
+9 -2
View File
@@ -22,10 +22,17 @@
]
},
{
"target_name": "file",
"target_name": "socket",
'cflags': [ '-Wall' ],
"sources": [
"clibs/chibrax/file.cc"
"clibs/chibrax/socket.cc"
]
},
{
"target_name": "ip",
'cflags': [ '-Wall', '-Wextra' ],
"sources": [
"clibs/chibrax/ip.cc"
]
}
]
+4 -2
View File
@@ -10,7 +10,9 @@ echo " ioctl"
cp build/Release/ioctl.node rootfs\ overrides/chibrax/ioctl.node
echo " mount"
cp build/Release/mount.node rootfs\ overrides/chibrax/mount.node
echo " file"
cp build/Release/file.node rootfs\ overrides/chibrax/file.node
echo " socket"
cp build/Release/socket.node rootfs\ overrides/chibrax/socket.node
echo " ip"
cp build/Release/ip.node rootfs\ overrides/chibrax/ip.node
echo "done"
-49
View File
@@ -1,49 +0,0 @@
#include <node.h>
#include <string>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#define nodeparam v8::FunctionCallbackInfo<v8::Value>
namespace fileNode {
void nodeOpen(const nodeparam& args) {
v8::Isolate* isolate = args.GetIsolate();
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsUint32() || ( args.Length() == 3 && !( args[2]->IsUndefined() || args[2]->IsUint32()))) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument 1 must be a path, 2 must be a number").ToLocalChecked()));
return;
}
v8::String::Utf8Value str(isolate, args[0]);
std::string path(*str);
int flags = args[1].As<v8::Number>()->Value();
if(args.Length() == 3 && args[2]->IsUndefined()) {
mode_t mode = args[2].As<v8::Number>()->Value();
args.GetReturnValue().Set(open(path.c_str(), flags, mode));
} else {
args.GetReturnValue().Set(open(path.c_str(), flags));
}
}
void nodeClose(const nodeparam& args) {
v8::Isolate* isolate = args.GetIsolate();
if (args.Length() < 1 || !args[0]->IsUint32()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument 1 must be a file descriptor (number)").ToLocalChecked()));
return;
}
close(args[1].As<v8::Number>()->Value());
}
void Initialize(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "open", nodeOpen);
NODE_SET_METHOD(exports, "close", nodeClose);
}
NODE_MODULE(file_api, Initialize)
}
+2 -8
View File
@@ -9,19 +9,13 @@
namespace ioctlNode {
void nodeIoctl(const nodeparam& args) {
v8::Isolate* isolate = args.GetIsolate();
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsUint32()) {
if (args.Length() < 2 || !args[0]->IsUint32() || !args[1]->IsUint32()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument 1& 2 must be a number").ToLocalChecked()));
return;
}
v8::String::Utf8Value str(isolate, args[0]);
std::string cppStr(*str);
int fd = open(cppStr.c_str(), 'r');
u_int32_t fd = args[0].As<v8::Number>()->Value();
unsigned long request = args[1].As<v8::Number>()->Value();
int params[args.Length() - 2];
for(int i = 1 ; i < args.Length(); i++ ) {
-15
View File
@@ -1,15 +0,0 @@
//@ts-check
/**
* @type {{ open: (path: string, flags: number, mode?: number) => number, close: (fd: number) => void }}
*/
//@ts-expect-error
const cfiles = require('./file.node')
const modes = {
O_ACCMODE: 3,
O_RDONLY: 0,
O_WRONLY: 1,
O_RDWR: 2
}
module.exports = { ...cfiles, modes }