I want to call a c function test_main(int argc, char *argv[]) from dart using dart FFI. But the code below doesn't work obviously because Dart string cannot have null characters in it. How does one compose argv in dart?
// FFI signature of the C function
typedef benchmark_hexagon_main_test = Int32 Function(Int32 argc, Pointer<Utf8> argv, Int32 len);
// Dart type definition for calling the C foreign function
typedef benchmarkHexagonMainTest = int Function(int argc, Pointer<Utf8> argv, int len);
static Future<RunTime> benchmarkMainTest(String f, int P, int l) async {
final DynamicLibrary libBenchmark = Platform.isAndroid
? DynamicLibrary.open("libbenchmark.so")
: DynamicLibrary.process();
final benchmarkHexagonMainTest hexagonBenchmark =
libBenchmark
.lookup<NativeFunction<benchmark_hexagon_main_test>>("benchmark_test_main_start")
.asFunction();
String strArgs = "Program" + null + " -f " + null + f + null + " -P " + null + "${P}" + null + " -l " + null +"${l}" + null;
hexagonBenchmark(7, Utf8.toUtf8(strArgs), strArgs.length);
}
'''