From: David Allsopp <dra-news@metastack.com>
To: "Richard W.M. Jones" <rich@annexia.org>,
"Laurent Thévenoux" <laurent.thevenoux@inria.fr>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: RE: [Caml-list] Interfacing C with OCaml and file descriptors
Date: Fri, 13 Oct 2017 22:42:23 +0000 [thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D9016D4EBFE4@Remus.metastack.local> (raw)
In-Reply-To: <20171013213741.ke5ptnxrq2w3n6oq@annexia.org>
Richard W.M. Jones wrote:
> On Fri, Oct 13, 2017 at 12:57:33PM +0200, Laurent Thévenoux wrote:
> > Hi,
> >
> > I have a naive question about file descriptors and C interface (when
> interfacing C with OCaml).
>
> Firstly, you're confused about the difference between 'FILE *' and a file
> descriptor. They are not the same thing at all. Read some basic Unix
> texts about the difference.
>
> Once you've sorted that out, it turns out that you can (currently) cast a
> Unix.file_descr from OCaml directly into a C int file descriptor using
> Int_val:
>
> int fd = Int_val (fdv);
> read (fd, buf, len);
FWIW, note that this is not portable - it won't work on Windows, since Unix.file_descr is a struct.
> It would be really nice if there was an official C function defined by
> OCaml to do this in a portable and future-proof way!
One possibility might be to include the CRT_fd_val macro already in the win32unix version of unixsupport.h and make it an "official" conversion.
David
next prev parent reply other threads:[~2017-10-13 22:42 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
2017-10-13 21:37 ` Richard W.M. Jones
2017-10-13 22:42 ` David Allsopp [this message]
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=E51C5B015DBD1348A1D85763337FB6D9016D4EBFE4@Remus.metastack.local \
--to=dra-news@metastack.com \
--cc=caml-list@inria.fr \
--cc=laurent.thevenoux@inria.fr \
--cc=rich@annexia.org \
/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