ls: Fix sorting of named entries
Previously, entcmp was being passed struct entry **, when it expected struct entry *. Many autoconf-generated configure scripts use `ls -t` to determine whether or not the system clock is behaving correctly. If they are sorted in the wrong order, it produces an error. checking whether build environment is sane... configure: error: newly created file is older than distributed files! Check your system clock
This commit is contained in:
parent
b70d2857ab
commit
674d1636f8
22
ls.c
22
ls.c
|
@ -358,7 +358,7 @@ usage(void)
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct entry *ent, **dents, **fents;
|
struct entry *ent, *dents, *fents;
|
||||||
size_t i, ds, fs;
|
size_t i, ds, fs;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
|
@ -447,29 +447,27 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for (i = ds = fs = 0, fents = dents = NULL; i < argc; ++i) {
|
for (i = ds = fs = 0, fents = dents = NULL; i < argc; ++i) {
|
||||||
ent = emalloc(sizeof(*ent));
|
|
||||||
mkent(ent, argv[i], 1, Hflag || Lflag);
|
|
||||||
|
|
||||||
if ((!dflag && S_ISDIR(ent->mode)) ||
|
if ((!dflag && S_ISDIR(ent->mode)) ||
|
||||||
((S_ISLNK(ent->mode) && S_ISDIR(ent->tmode)) &&
|
((S_ISLNK(ent->mode) && S_ISDIR(ent->tmode)) &&
|
||||||
((Hflag || Lflag) || !(dflag || Fflag || lflag)))) {
|
((Hflag || Lflag) || !(dflag || Fflag || lflag)))) {
|
||||||
dents = ereallocarray(dents, ++ds, sizeof(ent));
|
dents = ereallocarray(dents, ++ds, sizeof(*dents));
|
||||||
dents[ds - 1] = ent;
|
ent = &dents[ds - 1];
|
||||||
} else {
|
} else {
|
||||||
fents = ereallocarray(fents, ++fs, sizeof(ent));
|
fents = ereallocarray(fents, ++fs, sizeof(*fents));
|
||||||
fents[fs - 1] = ent;
|
ent = &fents[fs - 1];
|
||||||
}
|
}
|
||||||
|
mkent(ent, argv[i], 1, Hflag || Lflag);
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(fents, fs, sizeof(ent), entcmp);
|
qsort(fents, fs, sizeof(*fents), entcmp);
|
||||||
qsort(dents, ds, sizeof(ent), entcmp);
|
qsort(dents, ds, sizeof(*dents), entcmp);
|
||||||
|
|
||||||
for (i = 0; i < fs; ++i)
|
for (i = 0; i < fs; ++i)
|
||||||
ls("", fents[i], 0);
|
ls("", &fents[i], 0);
|
||||||
if (fs && ds)
|
if (fs && ds)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
for (i = 0; i < ds; ++i)
|
for (i = 0; i < ds; ++i)
|
||||||
ls("", dents[i], 1);
|
ls("", &dents[i], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fshut(stdout, "<stdout>");
|
return fshut(stdout, "<stdout>");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user