From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e7549ba39f382cd3 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news.glorb.com!indigo.octanews.net!news-out.octanews.net!mauve.octanews.net!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Sun, 14 Oct 2007 07:21:06 -0400 From: "Peter C. Chapin" User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Too detailed public view of POSIX.IO.File_Descriptor in Florist? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4711fb9e$0$7203$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: 7f6ebb43.news.sover.net X-Trace: DXC=Bc3Zo]O3Hoff\[Q9fA_YO`K6_LM2JZB_c\AbD3?GgQca:WUUlR<856oD_eHiGeP\9j8SbM6g^[Lbo X-Complaints-To: abuse@sover.net Xref: g2news2.google.com comp.lang.ada:2445 Date: 2007-10-14T07:21:06-04:00 List-Id: 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