[m-users.] How to get the file descriptor of a stream

Volker Wysk post at volker-wysk.de
Thu Jul 20 15:41:25 AEST 2023


Hi.

I would like to have a predicate which returns the file descriptor, which is
used to implement a stream. Such as the fileno(3) C library function. It's
for querying the terminal width, of streams that can be connected to a
terminal. I want to print (error and normal) messages which are formatted
for the terminal's width.

There's stdout_stream and stderr_stream and you can assume that they have
the file descriptors 1 and 2. But this isn't foolproof and other streams
might be connected to a terminal as well (or isn't it?).

It might, for instance, theoretically happen that stdout_stream is closed
and the file descriptor 1 gets reused later. Then we could end up with a fd
1 which doesn't belong to stdout_stream.

I've searched the io and stream libraries, but couldn't find such a
predicate.

Cheers,
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20230720/6644dbca/attachment.sig>


More information about the users mailing list