bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#10472: `realpath --relative-to=<path> /` outputs inconsistent traili


From: Jim Meyering
Subject: 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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]