Search code examples
cjna

What do I pass through JNA if the c method requests a file pointer?


So I have a c library method like so:

void foo (FILE *out_file, some_struct *struct_ptr, int i);

Assuming function foo only uses out_file as output, the c call example given is:

foo(stdout,struct,1)

What do I pass into JNA as a FILE* pointer? I get that the JNA class declaration would be

public void foo (Pointer *out_file, Pointer *struct_ptr, int i);

but how do I get Pointer *out_file to print to stdout, or even to a file?


Solution

  • fopen() (see the man page with related functions) is the easiest way to get a file pointer. If you want stdout, you'll have to look at your platform definition of that symbol. Sometimes it's a macro, sometimes it references an element of a global array, sometimes it's an inlined function.