From: Phillip Wood Date: Mon, 11 Apr 2022 13:40:24 GMT Subject: Re: [RFC PATCH 3/6] dir-iterator: refactor dir_iterator_advance() Message-ID: <9e5495d0-c117-2242-6718-46042e9664bf@gmail.com> In-Reply-To: <220411.86o817j2dt.gmgdl@evledraar.gmail.com> On 11/04/2022 12:11, Ævar Arnfjörð Bjarmason wrote: > > On Sun, Apr 10 2022, Plato Kiorpelidis wrote: > >> + >> + errno = 0; >> + dir_entry = readdir(level->dir); >> >> - strbuf_setlen(&iter->base.path, level->prefix_len); >> - errno = 0; >> - de = readdir(level->dir); >> - >> - if (!de) { >> - if (errno) { >> - warning_errno("error reading directory '%s'", >> - iter->base.path.buf); >> - if (iter->flags & DIR_ITERATOR_PEDANTIC) >> - goto error_out; >> - } else if (pop_level(iter) == 0) { >> + if (dir_entry == NULL) { > > Don't compare against NULL, use !dir_entry. > > Also: Manually resetting "errno" before isn't needed. It will be (re)set > if readdir() returns NULL(). That's not what the man page says If the end of the directory stream is reached, NULL is returned and errno is not changed. If an error occurs, NULL is returned and errno is set to indicate the error. To distinguish end of stream from an error, set errno to zero before calling readdir() and then check the value of errno if NULL is returned. Best Wishes Phillip