GNU bug report logs - #10472
`realpath --relative-to=<path> /` outputs inconsistent trailing slash

Previous Next

Package: coreutils;

Reported by: Mike Frysinger <vapier <at> gentoo.org>

Date: Tue, 10 Jan 2012 20:17:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #34 received at 10472 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: 10472 <at> debbugs.gnu.org
Subject: Re: bug#10472: `realpath --relative-to=<path> /` outputs inconsistent
	trailing slash
Date: Wed, 25 Jan 2012 20:41:24 +0100
Pádraig Brady wrote:
> On 01/25/2012 06:00 PM, Pádraig Brady wrote:
>> On 01/25/2012 05:10 PM, Jim Meyering wrote:
>>> On an unrelated note, have you considered removing the remaining
>>> printf uses in favor of fputc/fputs, since they're all trivial?
>>
>> Good point. I'll undo the s/printf/putchar/ change in this patch,
>> and do a follow up, using the lower level functions.
>
> The patch below, gives an 11% improvement.
> Tested like:
>
> seq 1000000 | sed 's|.*|/1/2/3/4/&|' > paths
> time xargs src/realpath -sm < paths >/dev/null
> time xargs src/realpath -sm --relative-to=/1/2/3 < paths >/dev/null

Thanks!

> diff --git a/src/realpath.c b/src/realpath.c
...
> @@ -181,26 +181,27 @@ relpath (const char *can_fname)
...
> -      putchar (use_nuls ? '\0' : '\n');
> -
>        return true;
>      }
>
> @@ -228,7 +229,9 @@ process_path (const char *fname, int can_mode)
>      }
>
>    if (!relpath (can_fname))
> -    printf ("%s%c", can_fname, (use_nuls ? '\0' : '\n'));
> +    fputs (can_fname, stdout);
> +
> +  putchar (use_nuls ? '\0' : '\n');

Nice to see the "use_nuls" use factored out.
With that, it is feasible to move it's declaration into main.
ACK, either way.




This bug report was last modified 13 years and 75 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.