[Toybox] [PATCH] Support diff --no-dereference
enh
enh at google.com
Thu Aug 22 06:23:26 PDT 2024
+ int s = sizeof(toybuf)/2;
+
+ TT.is_symlink = 1;
+ for (i = 0; i < 2; i++) {
+ TT.link[i].name = toybuf + i * s;
+ TT.link[i].len = readlink0(files[i], TT.link[i].name, s);
should probably use xreadlink() and free() instead? toybuf is big
enough to be safe for _one_ path on linux, but not two.
+ if (FLAG(no_dereference))
+ lstat(f[i], st+i);
+ else
+ stat(f[i], st+i);
can be
(FLAG(no_dereference) ? lstat : stat)(f[i], st+i);
instead.
for (j = 0; j < 2; j++) {
+ {
+ }
if (IS_STDIN(files[j])) fstat(0, &TT.st[j]);
?
+ if (FLAG(no_dereference)) {
+ if (lstat(files[!d], &TT.st[!d])) perror_exit("%s", files[!d]);
+ } else {
+ if (stat(files[!d], &TT.st[!d])) perror_exit("%s", files[!d]);
+ }
(same ? : trick works here and removes more duplication.)
otherwise seems plausible to me. (and includes tests :-) )
On Mon, Aug 19, 2024 at 5:07 PM Daniel Rosenberg via Toybox
<toybox at lists.landley.net> wrote:
>
> ping
>
>
> On Fri, Aug 9, 2024 at 5:52 PM Daniel Rosenberg <drosen at google.com> wrote:
> >
> > diff --no-dereference causes diff to not follow symlinks, instead comparing
> > the link name.
> >
> > Added some basic tests.
> > ---
> > lib/lib.h | 1 +
> > lib/xwrap.c | 5 +++
> > tests/diff.test | 7 ++++
> > toys/pending/diff.c | 96 +++++++++++++++++++++++++++++++++++----------
> > 4 files changed, 88 insertions(+), 21 deletions(-)
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
More information about the Toybox
mailing list