summaryrefslogtreecommitdiff
path: root/usr.bin/find/ls.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/find/ls.c')
-rw-r--r--usr.bin/find/ls.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/usr.bin/find/ls.c b/usr.bin/find/ls.c
index 23b7cfe..14ce841 100644
--- a/usr.bin/find/ls.c
+++ b/usr.bin/find/ls.c
@@ -29,14 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-#ifndef lint
-#if 0
-static char sccsid[] = "from: @(#)ls.c 8.1 (Berkeley) 6/6/93";
-#else
-__RCSID("$NetBSD: ls.c,v 1.21 2011/08/31 16:24:57 plunky Exp $");
-#endif
-#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
@@ -49,8 +41,8 @@ __RCSID("$NetBSD: ls.c,v 1.21 2011/08/31 16:24:57 plunky Exp $");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <bsd/string.h>
#include <time.h>
-#include <tzfile.h>
#include <unistd.h>
#include "find.h"
@@ -66,13 +58,28 @@ printlong(char *name, /* filename to print */
struct stat *sb) /* stat buffer */
{
char modep[15];
+ struct passwd *user = getpwuid(sb->st_uid);
+ struct group *group = getgrgid(sb->st_gid);
+ char *username, *groupname;
+
+ if (user == NULL) {
+ username = malloc(21);
+ snprintf(username, 20, "%d", sb->st_uid);
+ } else {
+ username = user->pw_name;
+ }
+ if (group == NULL) {
+ groupname = malloc(21);
+ snprintf(groupname, 20, "%d", sb->st_gid);
+ } else {
+ groupname = group->gr_name;
+ }
(void)printf("%7lu %6lld ", (u_long)sb->st_ino,
(long long)sb->st_blocks);
(void)strmode(sb->st_mode, modep);
(void)printf("%s %3lu %-*s %-*s ", modep, (unsigned long)sb->st_nlink,
- LOGIN_NAME_MAX, user_from_uid(sb->st_uid, 0), LOGIN_NAME_MAX,
- group_from_gid(sb->st_gid, 0));
+ LOGIN_NAME_MAX, username, LOGIN_NAME_MAX, groupname);
if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode))
(void)printf("%3llu,%5llu ",
@@ -85,6 +92,9 @@ printlong(char *name, /* filename to print */
if (S_ISLNK(sb->st_mode))
printlink(accpath);
(void)putchar('\n');
+
+ if (user == NULL) free(username);
+ if (group == NULL) free(groupname);
}
static void
@@ -96,7 +106,8 @@ printtime(time_t ftime)
longstring = ctime(&ftime);
for (i = 4; i < 11; ++i)
(void)putchar(longstring[i]);
-
+#define DAYSPERNYEAR 365
+#define SECSPERDAY 24 * 60 * 60
#define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY)
if (ftime + SIXMONTHS > time(NULL))
for (i = 11; i < 16; ++i)