Suggested addition to Unix module

From: Adam P. Jenkins (ajenkins@cs.umass.edu)
Date: Sun Aug 03 1997 - 00:07:05 MET DST


Date: Sat, 2 Aug 1997 18:07:05 -0400
Message-Id: <199708022207.SAA02234@noho-us147.javanet.com>
From: "Adam P. Jenkins" <ajenkins@cs.umass.edu>
To: caml-list@inria.fr
Subject: Suggested addition to Unix module

Hi,

I'm writing to suggest that there be descr_of_fd and fd_of_descr
functions added to the Unix module, to convert between the file_descr
type and its corresponding integer file descriptor. This shouldn't
ever be necessary in a caml program, but it can be when communicating
with another program.

I recently needed this. I have a program (that I didn't write) which
calls another program as a subprocess, with an opened file-descriptor
as a command-line argument; the child-process then reads and writes
this file descriptor to communicate with the parent. This is the same
thing inetd does for instance except it can use a different descriptor
than 0.

Well, in my case I wrote the program being called as a child process
in O'Caml, so I needed a way to turn the file descriptor passed on the
command-line into something I could use in OCaml. It's really just a
casting operation since file_descr is just the fd internally. Here's
my implementation, though it's trivial.

Also, is there a way to cast in OCaml instead of doing what I've done
here, when you know the internal representations of two types are the
same? I realize this could be abused, turning OCaml into C, but then
what I did below is kind of silly too. Thank you.

Adam

-- 
Adam P. Jenkins 
mailto:ajenkins@cs.umass.edu

----------------------------------------------------------------

external descr_of_fd : int -> file_descr = "unix_descr_of_fd" external fd_of_descr : file_descr -> int = "unix_fd_of_descr"

value unix_descr_of_fd(value fd) { return descr; }

value unix_fd_of_descr(value descr) { return descr; }



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:12 MET