mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 1/2] commands: ls: explicitly check for directories with S_ISDIR
Date: Tue, 7 Jun 2022 09:03:33 +0200	[thread overview]
Message-ID: <20220607070333.GI1615@pengutronix.de> (raw)
In-Reply-To: <20220602195916.9061-1-a.fatoum@pengutronix.de>

On Thu, Jun 02, 2022 at 09:59:15PM +0200, Ahmad Fatoum wrote:
> S_ISDIR(mode) is implemented as (mode & S_IFMT) == S_IFDIR, which
> accounts for file modes setting multiple bits. So far, this was not the
> case, but upcoming S_IFBLK equals (S_IFCHR | S_IFDIR), which would fail
> the existing checks, so prepare for that by fixing them.
> 
> No functional change. There are no other instances of this elsewhere in
> the code base.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---

Applied, thanks

Sascha

> v1 -> v2:
>   - new patch
> ---
>  commands/ls.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/commands/ls.c b/commands/ls.c
> index bedf2e1c4288..1192aed971cf 100644
> --- a/commands/ls.c
> +++ b/commands/ls.c
> @@ -63,10 +63,10 @@ int ls(const char *path, ulong flags)
>  	if (stat(path, &s))
>  		return -errno;
>  
> -	if (flags & LS_SHOWARG && s.st_mode & S_IFDIR)
> +	if (flags & LS_SHOWARG && S_ISDIR(s.st_mode))
>  		printf("%s:\n", path);
>  
> -	if (!(s.st_mode & S_IFDIR)) {
> +	if (!S_ISDIR(s.st_mode)) {
>  		ls_one(path, path);
>  		return 0;
>  	}
> @@ -112,7 +112,7 @@ int ls(const char *path, ulong flags)
>  			continue;
>  		}
>  
> -		if (s.st_mode & S_IFDIR)
> +		if (S_ISDIR(s.st_mode))
>  			ls(tmp, flags);
>  	}
>  
> @@ -171,7 +171,7 @@ static int do_ls(int argc, char *argv[])
>  			continue;
>  		}
>  
> -		if (!(s.st_mode & S_IFDIR)) {
> +		if (!S_ISDIR(s.st_mode)) {
>  			if (flags & LS_COLUMN)
>  				string_list_add_sorted(&sl, argv[o]);
>  			else
> @@ -197,7 +197,7 @@ static int do_ls(int argc, char *argv[])
>  			continue;
>  		}
>  
> -		if (s.st_mode & S_IFDIR) {
> +		if (S_ISDIR(s.st_mode)) {
>  			ret = ls(argv[o], flags);
>  			if (ret) {
>  				perror("ls");
> -- 
> 2.30.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


      parent reply	other threads:[~2022-06-07  7:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-02 19:59 Ahmad Fatoum
2022-06-02 19:59 ` [PATCH v2 2/2] block: set S_IFBLK for block devices instead of S_IFCHR Ahmad Fatoum
2022-06-07  7:03 ` Sascha Hauer [this message]

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

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

  git send-email \
    --in-reply-to=20220607070333.GI1615@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox