ノード ffiを使用してac ライブラリを呼び出していますが、このコードを使用すると問題が発生します。
この c プログラムは、現在のディレクトリにフォルダーを作成し、エラーがなければ 1 を返します。
#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;
}
このCプログラムを呼び出すために使用しているJavaScriptコードは次のとおりです。
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);
このプログラムは、create 関数で char の代わりに int を使用した場合にのみ機能しますが (示されているように)、この関数では char * を使用する必要があります。したがって、関数をcreate(char * dir)
I't に変更すると機能しません。
jsの呼び出しをから変更しようとしました
{"create": [ "int", ["int"] ] })
;
に
{"create": [ "int", ["char *"] ] });
.
それを手伝ってもらえますか?
ありがとう