Re: [hackers] [PATCH] Don't add excessive slashes to directories in ls(1) with the R flag

From: Dimitris Papastamos <sin_AT_2f30.org>
Date: Wed, 17 Feb 2016 20:48:25 +0000

On Wed, Feb 17, 2016 at 10:37:59PM +0200, Pekka Jylhä-Ollila wrote:
> This patch fixes directory names when using the R flag, and the
> directory name ends with '/'. Try out "ls -R ./" with the current
> version, the output looks like this:
>
> $ ls -R ./
> dir1
> dir2
>
> .//dir1:
> file1
>
> .//dir2:
> file2
> ---
> ls.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/ls.c b/ls.c
> index 72d7434..4b51d17 100644
> --- a/ls.c
> +++ b/ls.c
> _AT_@ -276,8 +276,12 @@ lsdir(const char *path, const struct entry *dir)
> output(&ents[i]);
>
> if (Rflag) {
> - if (snprintf(prefix, PATH_MAX, "%s%s/", path, dir->name) >=
> - PATH_MAX)
> + i = strlen(dir->name);
> + if (i && dir->name[i - 1] == '/')
> + i = snprintf(prefix, PATH_MAX, "%s%s", path, dir->name);
> + else
> + i = snprintf(prefix, PATH_MAX, "%s%s/", path, dir->name);
> + if (i >= PATH_MAX)
> eprintf("path too long: %s%s\n", path, dir->name);

what about ls -R .///////
Received on Wed Feb 17 2016 - 21:48:25 CET

This archive was generated by hypermail 2.3.0 : Wed Feb 17 2016 - 22:00:13 CET