* flush file buffer, etc
@ 1999-08-30 17:36 John Skaller
1999-08-31 19:32 ` Xavier Leroy
0 siblings, 1 reply; 3+ messages in thread
From: John Skaller @ 1999-08-30 17:36 UTC (permalink / raw)
To: caml-list
How do I flush a Unix.file_descr?
Deterimine if a file_descr isatty?
Get the Unix fd as an integer?
-------------------------------------------------------
John Skaller email: skaller@maxtal.com.au
http://www.maxtal.com.au/~skaller
phone: 61-2-96600850
snail: 10/1 Toxteth Rd, Glebe NSW 2037, Australia
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: flush file buffer, etc
1999-08-30 17:36 flush file buffer, etc John Skaller
@ 1999-08-31 19:32 ` Xavier Leroy
1999-09-01 11:02 ` Markus Mottl
0 siblings, 1 reply; 3+ messages in thread
From: Xavier Leroy @ 1999-08-31 19:32 UTC (permalink / raw)
To: John Skaller, caml-list
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: flush file buffer, etc
1999-08-31 19:32 ` Xavier Leroy
@ 1999-09-01 11:02 ` Markus Mottl
0 siblings, 0 replies; 3+ messages in thread
From: Markus Mottl @ 1999-09-01 11:02 UTC (permalink / raw)
To: Xavier Leroy; +Cc: OCAML
> > How do I flush a Unix.file_descr?
[snip]
> 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.
Maybe "fsync" would be appropriate. According to the man page this system
call conforms to POSIX.1b (formerly POSIX.4).
> > 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:
Another solution, which works with the existing library, would be
to simply call "tcgetattr fd" and catch the possibly resulting error
"ENOTTY".
E.g.:
try ignore (tcgetattr fd) with Unix_error (ENOTTY,_,_) -> ...
Regards,
Markus Mottl
--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1999-09-02 18:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-30 17:36 flush file buffer, etc John Skaller
1999-08-31 19:32 ` Xavier Leroy
1999-09-01 11:02 ` Markus Mottl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox