il fallait que sa puisse passer sur un cv

This commit is contained in:
Marc
2022-02-17 14:19:08 +01:00
parent 1edb531e1a
commit 551505c014
37 changed files with 13 additions and 20 deletions
+40
View File
@@ -0,0 +1,40 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <node.h>
#include <fcntl.h>
#include <string>
#define nodeparam v8::FunctionCallbackInfo<v8::Value>
namespace ioctlNode {
void nodeIoctl(const nodeparam& args) {
v8::Isolate* isolate = args.GetIsolate();
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;
}
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++ ) {
if (!args[i]->IsNumber()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument must be a number").ToLocalChecked()));
return;
}
params[i - 1] = args[i].As<v8::Number>()->Value();
}
args.GetReturnValue().Set(ioctl(fd, request, &params));
close(fd);
}
void Initialize(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "ioctl", nodeIoctl);
}
NODE_MODULE(ioctl_api, Initialize)
}