caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Adam P. Jenkins" <ajenkins@cs.umass.edu>
To: caml-list@inria.fr
Subject: Suggested addition to Unix module
Date: Sat, 2 Aug 1997 18:07:05 -0400	[thread overview]
Message-ID: <199708022207.SAA02234@noho-us147.javanet.com> (raw)

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






             reply	other threads:[~1997-08-25  9:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-08-02 22:07 Adam P. Jenkins [this message]
1997-08-25 11:55 ` Judicael Courant

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=199708022207.SAA02234@noho-us147.javanet.com \
    --to=ajenkins@cs.umass.edu \
    --cc=caml-list@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).