From 1888d833acac54bc81e87d2052385430472a65f6 Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Thu, 23 May 2019 11:22:05 -0500 Subject: bin/ls: make buildable against libbsd --- bin/ls/ls.c | 74 +++++++++++++++++++++---------------------------------------- 1 file changed, 25 insertions(+), 49 deletions(-) (limited to 'bin/ls/ls.c') diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 282207f..532da47 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -32,20 +32,6 @@ * SUCH DAMAGE. */ -#include -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\ - The Regents of the University of California. All rights reserved."); -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)ls.c 8.7 (Berkeley) 8/5/94"; -#else -__RCSID("$NetBSD: ls.c,v 1.76 2017/02/06 21:06:04 rin Exp $"); -#endif -#endif /* not lint */ - #include #include #include @@ -58,12 +44,12 @@ __RCSID("$NetBSD: ls.c,v 1.76 2017/02/06 21:06:04 rin Exp $"); #include #include #include +#include #include #include #include #include #include -#include #include "ls.h" #include "extern.h" @@ -114,7 +100,7 @@ int f_whiteout; /* show whiteout entries */ int f_fullpath; /* print full pathname, not filename */ int f_leafonly; /* when recursing, print leaf names only */ -__dead static void +static void usage(void) { @@ -346,7 +332,7 @@ ls_main(int argc, char *argv[]) /* If -i, -l, or -s, figure out block size. */ if (f_inode || f_longform || f_size) { if (!kflag) - (void)getbsize(NULL, &blocksize); + blocksize = 4096; blocksize /= 512; } @@ -499,13 +485,14 @@ display(FTSENT *p, FTSENT *list) ino_t maxinode; int maxmajor, maxminor; uint32_t maxnlink; - int bcfile, entries, flen, glen, ulen, maxflags, maxgroup; + int bcfile, entries, glen, ulen, maxgroup; unsigned int maxlen; int maxuser, needstats; - const char *user, *group; + struct passwd *user; + struct group *group; + const char *user_name, *group_name; char buf[21]; /* 64 bits == 20 digits, +1 for NUL */ char nuser[12], ngroup[12]; - char *flags = NULL; /* * If list is NULL there are two possibilities: that the parent @@ -518,10 +505,9 @@ display(FTSENT *p, FTSENT *list) return; needstats = f_inode || f_longform || f_size; - flen = 0; maxinode = maxnlink = 0; bcfile = 0; - maxuser = maxgroup = maxflags = maxlen = 0; + maxuser = maxgroup = maxlen = 0; btotal = stotal = maxblock = maxsize = 0; maxmajor = maxminor = 0; for (cur = list, entries = 0; cur; cur = cur->fts_link) { @@ -573,46 +559,37 @@ display(FTSENT *p, FTSENT *list) btotal += sp->st_blocks; stotal += sp->st_size; if (f_longform) { - if (f_numericonly || - (user = user_from_uid(sp->st_uid, 0)) == - NULL) { + user = getpwuid(sp->st_uid); + if (user != NULL) { + user_name = user->pw_name; + } + if (f_numericonly) { (void)snprintf(nuser, sizeof(nuser), "%u", sp->st_uid); - user = nuser; + user_name = nuser; } - if (f_numericonly || - (group = group_from_gid(sp->st_gid, 0)) == - NULL) { + group = getgrgid(sp->st_gid); + if (group != NULL) { + group_name = group->gr_name; + } + if (f_numericonly) { (void)snprintf(ngroup, sizeof(ngroup), "%u", sp->st_gid); - group = ngroup; + group_name = ngroup; } - if ((ulen = strlen(user)) > maxuser) + if ((ulen = strlen(user_name)) > maxuser) maxuser = ulen; - if ((glen = strlen(group)) > maxgroup) + if ((glen = strlen(group_name)) > maxgroup) maxgroup = glen; - if (f_flags) { - flags = - flags_to_string((u_long)sp->st_flags, "-"); - if ((flen = strlen(flags)) > maxflags) - maxflags = flen; - } else - flen = 0; if ((np = malloc(sizeof(NAMES) + - ulen + glen + flen + 2)) == NULL) + ulen + glen + 2)) == NULL) err(EXIT_FAILURE, NULL); np->user = &np->data[0]; - (void)strcpy(np->user, user); + (void)strcpy(np->user, user_name); np->group = &np->data[ulen + 1]; - (void)strcpy(np->group, group); - - if (f_flags) { - np->flags = &np->data[ulen + glen + 2]; - (void)strcpy(np->flags, flags); - free(flags); - } + (void)strcpy(np->group, group_name); cur->fts_pointer = np; } } @@ -637,7 +614,6 @@ display(FTSENT *p, FTSENT *list) if (f_commas) /* allow for commas before every third digit */ d.s_block += (d.s_block - 1) / 3; } - d.s_flags = maxflags; d.s_group = maxgroup; (void)snprintf(buf, sizeof(buf), "%llu", (unsigned long long)maxinode); -- cgit v1.2.3-60-g2f50