From: "Nicolás Ojeda Bär" <nicolas.ojeda.bar@lexifi.com>
To: "Laurent Thévenoux" <laurent.thevenoux@inria.fr>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Interfacing C with OCaml and file descriptors
Date: Fri, 13 Oct 2017 13:10:35 +0200 [thread overview]
Message-ID: <CADK7aFMb+5CxBY67xQe6B9DYzarzsL-C7vTazc_=OTt2Ya=uFg@mail.gmail.com> (raw)
In-Reply-To: <3380AF33-0E0F-46E9-BF03-E61B65E6B838@inria.fr>
[-- Attachment #1: Type: text/plain, Size: 1593 bytes --]
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 <caml/io.h> 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
[-- Attachment #2: Type: text/html, Size: 2604 bytes --]
next prev parent reply other threads:[~2017-10-13 11:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-13 10:57 Laurent Thévenoux
2017-10-13 11:10 ` Nicolás Ojeda Bär [this message]
2017-10-13 21:37 ` Richard W.M. Jones
2017-10-13 22:42 ` David Allsopp
2017-10-14 6:10 ` Richard W.M. Jones
2017-10-14 15:18 ` Malcolm Matalka
2017-10-14 15:54 ` Thierry Martinez
2017-10-16 6:46 ` Laurent Thévenoux
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADK7aFMb+5CxBY67xQe6B9DYzarzsL-C7vTazc_=OTt2Ya=uFg@mail.gmail.com' \
--to=nicolas.ojeda.bar@lexifi.com \
--cc=caml-list@inria.fr \
--cc=laurent.thevenoux@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox