Dear Laurent, Underlying OCaml I/O channels are Unix file descriptors, not FILE *'s. But you can use the POSIX function fdopen to get a FILE* form the file descriptor of the channel, which you can access by Channel(channel)->fd (see for the precise definition of the channel struct). That said, it is always tricky when different buffering mechanisms (OCaml's and libc's) interact, so caveat emptor! Best wishes, Nicolás -- Nicolás Ojeda Bär LexiFi 892, rue Yves Kermen F-92100 Boulogne-Billancourt IT support: +33 1 41 10 02 67 On Fri, Oct 13, 2017 at 12:57 PM, Laurent Thévenoux < laurent.thevenoux@inria.fr> wrote: > Hi, > > I have a naive question about file descriptors and C interface (when > interfacing C with OCaml). > > For instance, a file.ml file which looks like: > > > external my_c_interface : out_channel -> int = c_function > > > where c_function writes something to a file and return the number of > written char. > The c_function takes a FILE* file descriptor, as for example: > > > CAMLprim value c_function (value channel) > { > CAMLparam1 (channel); > FILE* fd = ???; > CAMLreturn (Val_int (call_to_c_func (fd))); > } > > > So, if possible, how to convert the ‘value channel’ to a ‘FILE*’? > > Thanks for your help, > Laurent > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs