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

Defect in XSH write

To: yyyyyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: Defect in XSH write
From: Geoff Clare <yyy@xxxxxxxxxxxxx>
Date: Tue, 13 Jun 2006 17:11:40 +0100
@ page 1676,1678 line 52035-52128 section write objection [gwc pwrite append]

Problem:

Defect code :  3. Clarification required

The description of pwrite() states:

    "The pwrite() function shall be equivalent to write(), except that
    it writes into a given position without changing the file pointer."

It is not clear whether "without changing the file pointer" applies
only to the write() file offset change done by the write operation
itself or also to the write() file offset change done prior to the
write operation when O_APPEND is set.

The former is described at line 52033:

    "Before successful return from write(), the file offset shall be
    incremented by the number of bytes actually written."

the latter at line 52039:

    "If the O_APPEND flag of the file status flags is set, the file
    offset shall be set to the end of the file prior to each write"

For pwrite() the latter could be thought of as occurring before it
"writes into a given position", in which case the "without changing
the file pointer" part would not apply to it.  This makes a difference
to where the file offset points after a pwrite() call when O_APPEND
is set.

Since pwrite() writes at the "given position" (i.e. the position
specified as the last argument to pwrite()), not at the file
offset, it doesn't make much sense for it to move the file offset
to the end of the file as a side effect of writing elsewhere.
Therefore the clarification I have suggested says that the file
offset is not changed by pwrite(), regardless of whether O_APPEND
is set.

A separate issue is that currently the standard does not require
pwrite() to change the length of a regular file if it writes past
the end of the file.  This is because the action of extending the
file is specified in terms of the new offset after write()
increments it:

    "On a regular file, if this incremented file offset is greater
    than the length of the file, the length of the file shall be set
    to this file offset.

Since pwrite() does not increment the offset, the statement does
not apply.  This is almost certainly not intended.

Finally, as an editorial matter the phrase "file pointer" on this
page should be "file offset" and in "fourth argument offset" the
word "offset" should be in italics.

Action:

Change the paragraph at lines 52126-52128 from:

    "The pwrite() function shall be equivalent to write(), except that
    it writes into a given position without changing the file pointer.
    The first three arguments to pwrite() are the same as write() with
    the addition of a fourth argument offset for the desired position
    inside the file."

to:

    "The pwrite() function shall be equivalent to write(), except that
    it writes into a given position and does not change the file offset
    (regardless of whether O_APPEND is set).  The first three arguments
    to pwrite() are the same as write() with the addition of a fourth
    argument <i>offset</i> for the desired position inside the file."


At line 52035 change:

    "On a regular file, if this incremented file offset is greater
    than the length of the file, the length of the file shall be set
    to this file offset.

to:

    "On a regular file, if the position of the last byte written is
    is greater than or equal to the length of the file, the length of
    the file shall be set to this position plus one."

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