#include #include #include #include #include #define nodeparam v8::FunctionCallbackInfo namespace ioctlNode { void nodeIoctl(const nodeparam& args) { v8::Isolate* isolate = args.GetIsolate(); if (args.Length() < 2 || !args[0]->IsString() || !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'); unsigned long request = args[1].As()->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()->Value(); } args.GetReturnValue().Set(ioctl(fd, request, ¶ms)); close(fd); } void Initialize(v8::Local exports) { NODE_SET_METHOD(exports, "ioctl", nodeIoctl); } NODE_MODULE(ioctl_api, Initialize) }