git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Plato Kiorpelidis" <kioplato@gmail.com>
Cc: git@vger.kernel.org, matheus.bernardino@usp.br, mhagger@alum.mit.edu
Subject: Re: [RFC PATCH 3/6] dir-iterator: refactor dir_iterator_advance()
Date: Mon, 11 Apr 2022 14:40:24 +0100	[thread overview]
Message-ID: <9e5495d0-c117-2242-6718-46042e9664bf@gmail.com> (raw)
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


  reply	other threads:[~2022-04-11 13:40 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-10 11:18 [RFC PATCH 0/6][GSoC] iterate dirs before or after their contents Plato Kiorpelidis
2022-04-10 11:18 ` [RFC PATCH 1/6] t0066: improve readablity of dir-iterator tests Plato Kiorpelidis
2022-04-11 13:16   ` Phillip Wood
2022-04-24 19:25     ` Plato Kiorpelidis
2022-04-10 11:18 ` [RFC PATCH 2/6] t0066: better test coverage for dir-iterator Plato Kiorpelidis
2022-04-10 11:18 ` [RFC PATCH 3/6] dir-iterator: refactor dir_iterator_advance() Plato Kiorpelidis
2022-04-11 11:11   ` Ævar Arnfjörð Bjarmason
2022-04-11 13:40     ` Phillip Wood [this message]
2022-04-27 15:45     ` Plato Kiorpelidis
2022-04-11 13:26   ` Phillip Wood
2022-04-27 14:32     ` Plato Kiorpelidis
2022-04-10 11:18 ` [RFC PATCH 4/6] dir-iterator: iterate dirs before or after their contents Plato Kiorpelidis
2022-04-11 13:31   ` Phillip Wood
2022-04-27 14:57     ` Plato Kiorpelidis
2022-04-10 11:18 ` [RFC PATCH 5/6] t0066: remove redundant tests Plato Kiorpelidis
2022-04-11 11:10   ` Ævar Arnfjörð Bjarmason
2022-04-27 16:00     ` Plato Kiorpelidis
2022-04-10 11:18 ` [RFC PATCH 6/6] test-dir-iterator: handle EACCES errno by dir-iterator Plato Kiorpelidis
2022-04-11 11:04   ` Ævar Arnfjörð Bjarmason
2022-04-27 17:30     ` Plato Kiorpelidis
2022-04-11 13:37 ` [RFC PATCH 0/6][GSoC] iterate dirs before or after their contents Phillip Wood
2022-04-19 13:06   ` Plato Kiorpelidis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e5495d0-c117-2242-6718-46042e9664bf@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kioplato@gmail.com \
    --cc=matheus.bernardino@usp.br \
    --cc=mhagger@alum.mit.edu \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).