1

I'm using node ffi to call a c library, and I have some issues using this code :

This c program create a folder in the current directory and return 1 if no error.

#include <stdint.h>
#include <stdio.h>
#include <sys/stat.h>

int create(int dir) 
{
int id;
id = mkdir(dir, S_IRWXU);   
if (id == -1)
  return 1;
else
  return 2;
}

the javascript code I'm using to call this c program is :

var FFI = require("../lib/ffi");
var libsender = new FFI.Library("./libsender", {"create": [ "int", [ "int" ] ] });


if (process.argv.length < 3) {
console.log("Arguments: " + process.argv[0] + " " + process.argv[1] + " <max>");
process.exit();
}

var output;
output = libsender.create(process.argv[2])
console.log("Your output: " + output);

This program is working just if I use int instead of char in the create function (like shown), but I need to use char * in this function. So if I change the function to create(char * dir) I't does not work.

I tried to change the call in the js from

{"create": [ "int", ["int"] ] });

to

{"create": [ "int", ["char *"] ] });.

can you help with that ?

Thanks

1 Answer 1

2

Try to change int create(int dir) to int create(char* dir), and…

var libsender = new FFI.Library("./libsender", { "create": [ "int", [ "int" ] ]

…to…

var libsender = new FFI.Library("./libsender", { "create": [ "int", [ "string" ] ]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.