comp.lang.ada
 help / color / mirror / Atom feed
* Too detailed public view of POSIX.IO.File_Descriptor in Florist?
@ 2007-10-14  5:05 Jacob Sparre Andersen
  2007-10-14 11:21 ` Peter C. Chapin
  0 siblings, 1 reply; 3+ messages in thread
From: Jacob Sparre Andersen @ 2007-10-14  5:05 UTC (permalink / raw)


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?

Greetings,

Jacob
-- 
"I don't want to gain immortality in my works.
 I want to gain it by not dying."



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Too detailed public view of POSIX.IO.File_Descriptor in Florist?
  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
  2007-10-14 18:55   ` Jacob Sparre Andersen
  0 siblings, 1 reply; 3+ messages in thread
From: Peter C. Chapin @ 2007-10-14 11:21 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Too detailed public view of POSIX.IO.File_Descriptor in Florist?
  2007-10-14 11:21 ` Peter C. Chapin
@ 2007-10-14 18:55   ` Jacob Sparre Andersen
  0 siblings, 0 replies; 3+ messages in thread
From: Jacob Sparre Andersen @ 2007-10-14 18:55 UTC (permalink / raw)


Peter C. Chapin wrote:

> Thus, in C,
>
> 	close(0);
> 	open("some/file.txt", O_RDONLY);

Or in Ada:

   Close (Standard_Input);
   File := Open ("some/file.txt", Read_Only);

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

Yes.

I have never actually used the semantics of Open this way.  If I want
to transfer a file to one of the predefined file descriptors, I tend
to use Duplicate_and_Close, but I can see your point.

Greetings,

Jacob
-- 
"No!  The universe is ours."



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-10-14 18:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2007-10-14 18:55   ` Jacob Sparre Andersen

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