* file_desc
@ 2008-07-01 14:35 Robert Fischer
2008-07-01 14:56 ` [Caml-list] file_desc SerP
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Robert Fischer @ 2008-07-01 14:35 UTC (permalink / raw)
To: caml-list
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?
~~ Robert.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] file_desc
2008-07-01 14:35 file_desc Robert Fischer
@ 2008-07-01 14:56 ` SerP
2008-07-01 14:59 ` Mark Shinwell
2008-07-01 15:15 ` Dave Benjamin
2 siblings, 0 replies; 4+ messages in thread
From: SerP @ 2008-07-01 14:56 UTC (permalink / raw)
Cc: caml-list
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?
>
> ~~ Robert.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
Obj.magic is a single way to do this.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] file_desc
2008-07-01 14:35 file_desc Robert Fischer
2008-07-01 14:56 ` [Caml-list] file_desc SerP
@ 2008-07-01 14:59 ` Mark Shinwell
2008-07-01 15:15 ` Dave Benjamin
2 siblings, 0 replies; 4+ messages in thread
From: Mark Shinwell @ 2008-07-01 14:59 UTC (permalink / raw)
To: Robert Fischer; +Cc: caml-list
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)
Mark
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] file_desc
2008-07-01 14:35 file_desc Robert Fischer
2008-07-01 14:56 ` [Caml-list] file_desc SerP
2008-07-01 14:59 ` Mark Shinwell
@ 2008-07-01 15:15 ` Dave Benjamin
2 siblings, 0 replies; 4+ messages in thread
From: Dave Benjamin @ 2008-07-01 15:15 UTC (permalink / raw)
To: Robert Fischer; +Cc: caml-list
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.
If you don't want to use Obj.magic, there is also the Netsys module from
Ocamlnet, which defines these two functions as C extensions:
val int_of_file_descr : Unix.file_descr -> int
val file_descr_of_int : int -> Unix.file_descr
Dave
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-07-01 15:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-01 14:35 file_desc Robert Fischer
2008-07-01 14:56 ` [Caml-list] file_desc SerP
2008-07-01 14:59 ` Mark Shinwell
2008-07-01 15:15 ` Dave Benjamin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox