comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <pchapin@sover.net>
Subject: Re: Too detailed public view of POSIX.IO.File_Descriptor in Florist?
Date: Sun, 14 Oct 2007 07:21:06 -0400
Date: 2007-10-14T07:21:06-04:00	[thread overview]
Message-ID: <4711fb9e$0$7203$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <ygeabqmi8uq.fsf@hugsarin.dmusyd.edu>

Jacob Sparre Andersen wrote:

> Doesn't Florist (the POSIX.5 interface) give us a too detailed view of
> POSIX.IO.File_Descriptor?
> 
> Is there any need at all for knowing that a file descriptor is an
> integer type?

I don't know anything about Florist. However POSIX does guarantee that
open(2) returns "a non-negative integer representing the lowest numbered
unused file descriptor." This means that the actual values of the file
descriptors are significant and can be meaningfully compared.

I/O redirection depends on this. If I have all file descriptors in the
range 0..n open and I close a descriptor i that is less than or equal to
n, I know that the next time I open a file it will be on descriptor i.
Since the standard input is descriptor zero and the standard output is
descriptor one, I can close these descriptors explicitly and then open a
file that then appears to be my standard input or output accordingly.
Thus, in C,

	close(0);
	open("some/file.txt", O_RDONLY);

Now when the program reads its standard input it actually gets
some/file.txt.

Peter



  reply	other threads:[~2007-10-14 11:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-14  5:05 Too detailed public view of POSIX.IO.File_Descriptor in Florist? Jacob Sparre Andersen
2007-10-14 11:21 ` Peter C. Chapin [this message]
2007-10-14 18:55   ` Jacob Sparre Andersen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox