caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rich@annexia.org>
To: "Laurent Thévenoux" <laurent.thevenoux@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Interfacing C with OCaml and file descriptors
Date: Fri, 13 Oct 2017 22:37:41 +0100	[thread overview]
Message-ID: <20171013213741.ke5ptnxrq2w3n6oq@annexia.org> (raw)
In-Reply-To: <3380AF33-0E0F-46E9-BF03-E61B65E6B838@inria.fr>

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);

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!

Rich.

  parent reply	other threads:[~2017-10-13 21:37 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 [this message]
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=20171013213741.ke5ptnxrq2w3n6oq@annexia.org \
    --to=rich@annexia.org \
    --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;
as well as URLs for NNTP newsgroup(s).