Email List: Xaustin-review-lX
[All Lists]

Defect in XSH freopen

To: yyyyyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: Defect in XSH freopen
From: Geoff Clare <yyy@xxxxxxxxxxxxx>
Date: Tue, 26 Oct 2004 16:36:40 +0100
@ page 439 line 14439 section freopen objection [gwc freopen fd alloc]

Problem:

Defect code :  2. Omission

A requirement on freopen() from chapter 8 of POSIX.1-1996 did not
survive the change to "man-page" format in POSIX.1-2001/SUSv3.

The omission originally occurred when the alignment of the XPG specs
with POSIX.1 was done between XPG2 and XPG3.  The omission seems to
have gone unnoticed through XPG4, SUSv1 and SUSv2, and now has found
its way into SUSv3.  Since the earlier XPG and SUS specifications
deferred to POSIX.1, the omission was not much of a problem: the
requirement applied despite not being stated explicitly.  But with
SUSv3 and POSIX.1-2001 being the same document, the omission is now
a problem and should be rectified.

The relevant parts of POSIX.1-1996 are:

    8.2.3

    [...]

    (7) Also, in the subclauses below, additional requirements on
    the standard I/O routines, beyond those in the C Standard {2},
    are given.

    8.2.3.1 fopen()

    The fopen() function shall allocate a file descriptor as
    open() does.

    [...]

    8.2.3.2 fclose()

    The fclose() function shall perform a close() on the file
    descriptor that is associated with the FILE stream.

    [...]

    8.2.3.3 freopen()

    The freopen() function has the properties of both fclose() and
    fopen().

Thus POSIX.1-1996 requires freopen() to close fileno(fp) and
then allocate the lowest available fd (as open() does).

In POSIX.1-2001 the fopen() page states the requirement as per
8.2.3.1 above (line 12892), but it omits the same requirement on
the freopen() page.

Action:

Append to line 14439, "The freopen() function shall allocate a file
descriptor as open() does."

<Prev in Thread] Current Thread [Next in Thread>