-/* $OpenBSD: ls.c,v 1.54 2020/10/07 21:03:09 millert Exp $ */
+/* $OpenBSD: ls.c,v 1.55 2023/10/07 11:51:08 schwarze Exp $ */
/* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */
/*
unsigned long long btotal;
blkcnt_t maxblock;
ino_t maxinode;
+ unsigned int maxmajor, maxminor;
int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser, maxlen;
int entries, needstats;
int width;
btotal = maxblock = maxinode = maxlen = maxnlink = 0;
bcfile = 0;
maxuser = maxgroup = maxflags = 0;
+ maxmajor = maxminor = 0;
maxsize = 0;
for (cur = list, entries = 0; cur != NULL; cur = cur->fts_link) {
if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
(void)strlcpy(np->group, group, glen + 1);
if (S_ISCHR(sp->st_mode) ||
- S_ISBLK(sp->st_mode))
+ S_ISBLK(sp->st_mode)) {
bcfile = 1;
-
+ if (maxmajor < major(sp->st_rdev))
+ maxmajor = major(sp->st_rdev);
+ if (maxminor < minor(sp->st_rdev))
+ maxminor = minor(sp->st_rdev);
+ }
if (f_flags) {
np->flags = &np->data[ulen + 1 + glen + 1];
(void)strlcpy(np->flags, flags, flen + 1);
d.entries = entries;
d.maxlen = maxlen;
if (needstats) {
- d.bcfile = bcfile;
d.btotal = btotal;
(void)snprintf(buf, sizeof(buf), "%llu",
(unsigned long long)maxblock);
d.s_size = strlen(buf);
} else
d.s_size = FMT_SCALED_STRSIZE-2; /* no - or '\0' */
+ d.s_major = d.s_minor = 3;
+ if (bcfile) {
+ (void)snprintf(buf, sizeof(buf), "%u", maxmajor);
+ d.s_major = strlen(buf);
+ (void)snprintf(buf, sizeof(buf), "%u", maxminor);
+ d.s_minor = strlen(buf);
+ if (d.s_size <= d.s_major + 2 + d.s_minor)
+ d.s_size = d.s_major + 2 + d.s_minor;
+ else
+ d.s_major = d.s_size - 2 - d.s_minor;
+ }
d.s_user = maxuser;
}
-/* $OpenBSD: print.c,v 1.39 2020/10/07 21:03:09 millert Exp $ */
+/* $OpenBSD: print.c,v 1.40 2023/10/07 11:51:08 schwarze Exp $ */
/* $NetBSD: print.c,v 1.15 1996/12/11 03:25:39 thorpej Exp $ */
/*
if (f_flags)
(void)printf("%-*s ", dp->s_flags, np->flags);
if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
- (void)printf("%3u, %3u ",
- major(sp->st_rdev), minor(sp->st_rdev));
- else if (dp->bcfile)
- (void)printf("%*s%*lld ",
- 8 - dp->s_size, "", dp->s_size,
- (long long)sp->st_size);
+ (void)printf("%*u, %*u ",
+ dp->s_major, major(sp->st_rdev),
+ dp->s_minor, minor(sp->st_rdev));
else
printsize(dp->s_size, sp->st_size);
if (f_accesstime)