From: "Richard W.M. Jones" <rich@annexia.org>
To: David Allsopp <dra-news@metastack.com>
Cc: "Laurent Thévenoux" <laurent.thevenoux@inria.fr>,
"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Interfacing C with OCaml and file descriptors
Date: Sat, 14 Oct 2017 07:10:56 +0100 [thread overview]
Message-ID: <20171014061056.dauqokuaulyuxwd3@annexia.org> (raw)
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D9016D4EBFE4@Remus.metastack.local>
On Fri, Oct 13, 2017 at 10:42:23PM +0000, David Allsopp wrote:
> 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.
Right, precisely my point. However it currently works on Unix
which is what I (and the original poster) care about.
Rich.
> > 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
>
>
> --
> 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
--
Richard Jones
next prev parent reply other threads:[~2017-10-14 6: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
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 [this message]
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=20171014061056.dauqokuaulyuxwd3@annexia.org \
--to=rich@annexia.org \
--cc=caml-list@inria.fr \
--cc=dra-news@metastack.com \
--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