/* * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted provided * that: (1) source distributions retain this entire copyright notice and * comment, and (2) distributions including binaries display the following * acknowledgement: ``This product includes software developed by the * University of California, Berkeley and its contributors'' in the * documentation or other materials provided with the distribution and in * all advertising materials mentioning features or use of this software. * Neither the name of the University nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint static char sccsid[] = "@(#)ls.c 5.4 (Berkeley) 6/1/90"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> #include <tzfile.h> #include <utmp.h> #include <stdio.h> /* Derived from the print routines in the ls(1) source code. */ extern int errno; void printlong(name, accpath, sb) char *name; /* filename to print */ char *accpath; /* current valid path to filename */ struct stat *sb; /* stat buffer */ { extern int errno; char modep[15], *user_from_uid(), *group_from_gid(), *strerror(); (void)printf("%6lu %4ld ", sb->st_ino, sb->st_blocks); (void)strmode(sb->st_mode, modep); (void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, UT_NAMESIZE, user_from_uid(sb->st_uid, 0), UT_NAMESIZE, group_from_gid(sb->st_gid, 0)); if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) (void)printf("%3d, %3d ", major(sb->st_rdev), minor(sb->st_rdev)); else (void)printf("%8ld ", sb->st_size); printtime(sb->st_mtime); (void)printf("%s", name); if (S_ISLNK(sb->st_mode)) printlink(accpath); (void)putchar('\n'); } printtime(ftime) time_t ftime; { int i; char *longstring, *ctime(); time_t time(); longstring = ctime((long *)&ftime); for (i = 4; i < 11; ++i) (void)putchar(longstring[i]); #define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY) if (ftime + SIXMONTHS > time((time_t *)NULL)) for (i = 11; i < 16; ++i) (void)putchar(longstring[i]); else { (void)putchar(' '); for (i = 20; i < 24; ++i) (void)putchar(longstring[i]); } (void)putchar(' '); } printlink(name) char *name; { int lnklen; char path[MAXPATHLEN + 1], *strerror(); if ((lnklen = readlink(name, path, MAXPATHLEN)) == -1) { (void)fprintf(stderr, "\nfind: %s: %s\n", name, strerror(errno)); return; } path[lnklen] = '\0'; (void)printf(" -> %s", path); }