From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA02086 for caml-redistribution; Wed, 1 Sep 1999 10:00:38 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA12918 for ; Tue, 31 Aug 1999 21:32:12 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id VAA06418; Tue, 31 Aug 1999 21:32:06 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA25695; Tue, 31 Aug 1999 21:32:05 +0200 (MET DST) Message-ID: <19990831213205.60338@pauillac.inria.fr> Date: Tue, 31 Aug 1999 21:32:05 +0200 From: Xavier Leroy To: John Skaller , caml-list@inria.fr Subject: Re: flush file buffer, etc References: <3.0.6.32.19990831033648.009647e0@mail.triode.net.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: <3.0.6.32.19990831033648.009647e0@mail.triode.net.au>; from John Skaller on Tue, Aug 31, 1999 at 03:36:48AM +1000 Sender: weis > How do I flush a Unix.file_descr? Depends what you mean by "flush". Writes to Unix.file_descr are unbuffered at the level of the OCaml runtime system (unlike {in,out}_channels, which are buffered) and thus go straight to the kernel I/O buffers. So no explicit flushing to the kernel buffers is required. On the other hand, if you want to really commit the writes to the hard disk, there is no function in the Unix module for this. But I'm not even sure there exists a standardized Unix system call to do this. > Deterimine if a file_descr isatty? Your best bet is to make isatty() available in Caml. The following C wrapper and Caml declaration are all you need: value caml_isatty(value fd) { return Val_bool(isatty(Int_val(fd))); } extern isatty : Unix.file_descr -> bool = "caml_isatty" > Get the Unix fd as an integer? You can't, because a Unix file descriptor is fundamentally not an integer: it makes no sense to add or multiply two file descriptors, for instance. For most Unix system programming tasks, an abstract file_descr type works just fine and is so much safer. I know there are some tasks where a correspondence between file descriptors and integers is essential, e.g. reimplementing the Bourne shell in OCaml. If you really must, you could define a coercion function as follows external fd_of_file_descr: Unix.file_descr -> int = "%identity" but it's not very safe in that if the internal representation of file descriptors in the Caml/Unix interface ever changes (e.g. becomes a heap-allocated block rather than just an integer), your code will break horribly.