Re: pg_check_dir comments and implementation mismatch - Mailing list pgsql-hackers

From Tom Lane
Subject Re: pg_check_dir comments and implementation mismatch
Date
Msg-id 23007.1424653061@sss.pgh.pa.us
Whole thread Raw
In response to Re: pg_check_dir comments and implementation mismatch  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: pg_check_dir comments and implementation mismatch  (Noah Misch <noah@leadboat.com>)
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Fri, Feb 20, 2015 at 12:59 AM, Noah Misch <noah@leadboat.com> wrote:
>> On Mon, Feb 02, 2015 at 03:48:33PM -0500, Robert Haas wrote:
>>> If readir() fails and closedir() succeeds, the return will be -1 but
>>> errno will be 0.

>> Out of curiosity, have you seen a closedir() implementation behave that way?
>> It would violate C99 ("The value of errno is zero at program startup, but is
>> never set to zero by any library function.") and POSIX.

> No.  Good point, I didn't think about that.  I think this way is safer, though.

While the spec forbids library functions from setting errno to zero, there
is no restriction on them changing errno in other ways despite returning
success; their exit-time value of errno is only well-defined if they fail.
So we do need to preserve errno explicitly across closedir(), or we may
report the wrong failure from readdir().
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Precedence of standard comparison operators
Next
From: Robert Haas
Date:
Subject: Re: restrict global access to be readonly