mirror of
https://github.com/openbsd/src.git
synced 2025-01-04 23:35:36 -08:00
Simplify the display() function by getting rid of a useless buffer
on the stack. No functional change, +8 -15 LOC. Suggested by and OK millert@.
This commit is contained in:
parent
1302b32905
commit
772e31c152
25
bin/ls/ls.c
25
bin/ls/ls.c
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: ls.c,v 1.55 2023/10/07 11:51:08 schwarze Exp $ */
|
/* $OpenBSD: ls.c,v 1.56 2023/10/07 13:29:08 schwarze Exp $ */
|
||||||
/* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */
|
/* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -442,7 +442,6 @@ display(FTSENT *p, FTSENT *list)
|
|||||||
int width;
|
int width;
|
||||||
const char *user, *group;
|
const char *user, *group;
|
||||||
char nuser[12], ngroup[12];
|
char nuser[12], ngroup[12];
|
||||||
char buf[21]; /* 64 bits == 20 digits */
|
|
||||||
char *flags = NULL;
|
char *flags = NULL;
|
||||||
|
|
||||||
needstats = f_inode || f_longform || f_size;
|
needstats = f_inode || f_longform || f_size;
|
||||||
@ -558,29 +557,23 @@ display(FTSENT *p, FTSENT *list)
|
|||||||
d.maxlen = maxlen;
|
d.maxlen = maxlen;
|
||||||
if (needstats) {
|
if (needstats) {
|
||||||
d.btotal = btotal;
|
d.btotal = btotal;
|
||||||
(void)snprintf(buf, sizeof(buf), "%llu",
|
d.s_block = snprintf(NULL, 0, "%llu",
|
||||||
(unsigned long long)maxblock);
|
(unsigned long long)maxblock);
|
||||||
d.s_block = strlen(buf);
|
|
||||||
d.s_flags = maxflags;
|
d.s_flags = maxflags;
|
||||||
d.s_group = maxgroup;
|
d.s_group = maxgroup;
|
||||||
(void)snprintf(buf, sizeof(buf), "%llu",
|
d.s_inode = snprintf(NULL, 0, "%llu",
|
||||||
(unsigned long long)maxinode);
|
(unsigned long long)maxinode);
|
||||||
d.s_inode = strlen(buf);
|
d.s_nlink = snprintf(NULL, 0, "%lu",
|
||||||
(void)snprintf(buf, sizeof(buf), "%lu",
|
|
||||||
(unsigned long)maxnlink);
|
(unsigned long)maxnlink);
|
||||||
d.s_nlink = strlen(buf);
|
if (!f_humanval)
|
||||||
if (!f_humanval) {
|
d.s_size = snprintf(NULL, 0, "%lld",
|
||||||
(void)snprintf(buf, sizeof(buf), "%lld",
|
|
||||||
(long long)maxsize);
|
(long long)maxsize);
|
||||||
d.s_size = strlen(buf);
|
else
|
||||||
} else
|
|
||||||
d.s_size = FMT_SCALED_STRSIZE-2; /* no - or '\0' */
|
d.s_size = FMT_SCALED_STRSIZE-2; /* no - or '\0' */
|
||||||
d.s_major = d.s_minor = 3;
|
d.s_major = d.s_minor = 3;
|
||||||
if (bcfile) {
|
if (bcfile) {
|
||||||
(void)snprintf(buf, sizeof(buf), "%u", maxmajor);
|
d.s_major = snprintf(NULL, 0, "%u", maxmajor);
|
||||||
d.s_major = strlen(buf);
|
d.s_minor = snprintf(NULL, 0, "%u", maxminor);
|
||||||
(void)snprintf(buf, sizeof(buf), "%u", maxminor);
|
|
||||||
d.s_minor = strlen(buf);
|
|
||||||
if (d.s_size <= d.s_major + 2 + d.s_minor)
|
if (d.s_size <= d.s_major + 2 + d.s_minor)
|
||||||
d.s_size = d.s_major + 2 + d.s_minor;
|
d.s_size = d.s_major + 2 + d.s_minor;
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user