Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: John Skaller <skaller@maxtal.com.au>, caml-list@inria.fr
Subject: Re: flush file buffer, etc
Date: Tue, 31 Aug 1999 21:32:05 +0200	[thread overview]
Message-ID: <19990831213205.60338@pauillac.inria.fr> (raw)
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

> 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.





  reply	other threads:[~1999-09-01  8:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-30 17:36 John Skaller
1999-08-31 19:32 ` Xavier Leroy [this message]
1999-09-01 11:02   ` Markus Mottl

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=19990831213205.60338@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=skaller@maxtal.com.au \
    /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