English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-07-01 (14:59)
From: Mark Shinwell <mshinwell@j...>
Subject: Re: [Caml-list] file_desc
On Tue, Jul 01, 2008 at 09:35:53AM -0500, Robert Fischer wrote:
> Is there a way to convert a file_descr to/from an int in OCaml?  The type is
> abstract, and there doesn't seem to be an obvious answer.
> Alternatively, is there a way to get at an inherited file_descr from a
> process I execv'd into?

Not in the default standard library, I don't think.  Jane Street's core
library <http://ocaml.janestcapital.com/?q=node/13> contains such a
function, however.  It is implemented as:

    external file_descr_of_int : int -> file_descr = "%identity"

Another approach is to write something like:

    let file_descr_of_int fd =
      assert (fd >= 0);
      assert (Obj.is_int (Obj.repr Unix.stdin));
      ((Obj.magic fd) : Unix.file_descr)