From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA16930 for caml-redistribution; Mon, 25 Aug 1997 11:27:05 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA25749 for ; Sun, 3 Aug 1997 00:08:46 +0200 (MET DST) Received: from noho-us147.javanet.com (ajenkins@noho-us147.javanet.com [206.150.72.62]) by nez-perce.inria.fr (8.8.5/8.8.5) with ESMTP id AAA12709 for ; Sun, 3 Aug 1997 00:08:43 +0200 (MET DST) Received: (from ajenkins@localhost) by noho-us147.javanet.com (8.8.5/8.8.5) id SAA02234; Sat, 2 Aug 1997 18:07:05 -0400 Date: Sat, 2 Aug 1997 18:07:05 -0400 Message-Id: <199708022207.SAA02234@noho-us147.javanet.com> From: "Adam P. Jenkins" To: caml-list@inria.fr Subject: Suggested addition to Unix module Sender: weis 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; }