|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1989 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted provided ! 6: * that: (1) source distributions retain this entire copyright notice and ! 7: * comment, and (2) distributions including binaries display the following ! 8: * acknowledgement: ``This product includes software developed by the ! 9: * University of California, Berkeley and its contributors'' in the ! 10: * documentation or other materials provided with the distribution and in ! 11: * all advertising materials mentioning features or use of this software. ! 12: * Neither the name of the University nor the names of its contributors may ! 13: * be used to endorse or promote products derived from this software without ! 14: * specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)ls.c 5.4 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include <sys/param.h> ! 25: #include <sys/stat.h> ! 26: #include <tzfile.h> ! 27: #include <utmp.h> ! 28: #include <stdio.h> ! 29: ! 30: /* Derived from the print routines in the ls(1) source code. */ ! 31: ! 32: extern int errno; ! 33: ! 34: void ! 35: printlong(name, accpath, sb) ! 36: char *name; /* filename to print */ ! 37: char *accpath; /* current valid path to filename */ ! 38: struct stat *sb; /* stat buffer */ ! 39: { ! 40: extern int errno; ! 41: char modep[15], *user_from_uid(), *group_from_gid(), *strerror(); ! 42: ! 43: (void)printf("%6lu %4ld ", sb->st_ino, sb->st_blocks); ! 44: (void)strmode(sb->st_mode, modep); ! 45: (void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, UT_NAMESIZE, ! 46: user_from_uid(sb->st_uid, 0), UT_NAMESIZE, ! 47: group_from_gid(sb->st_gid, 0)); ! 48: ! 49: if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) ! 50: (void)printf("%3d, %3d ", major(sb->st_rdev), ! 51: minor(sb->st_rdev)); ! 52: else ! 53: (void)printf("%8ld ", sb->st_size); ! 54: printtime(sb->st_mtime); ! 55: (void)printf("%s", name); ! 56: if (S_ISLNK(sb->st_mode)) ! 57: printlink(accpath); ! 58: (void)putchar('\n'); ! 59: } ! 60: ! 61: printtime(ftime) ! 62: time_t ftime; ! 63: { ! 64: int i; ! 65: char *longstring, *ctime(); ! 66: time_t time(); ! 67: ! 68: longstring = ctime((long *)&ftime); ! 69: for (i = 4; i < 11; ++i) ! 70: (void)putchar(longstring[i]); ! 71: ! 72: #define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY) ! 73: if (ftime + SIXMONTHS > time((time_t *)NULL)) ! 74: for (i = 11; i < 16; ++i) ! 75: (void)putchar(longstring[i]); ! 76: else { ! 77: (void)putchar(' '); ! 78: for (i = 20; i < 24; ++i) ! 79: (void)putchar(longstring[i]); ! 80: } ! 81: (void)putchar(' '); ! 82: } ! 83: ! 84: printlink(name) ! 85: char *name; ! 86: { ! 87: int lnklen; ! 88: char path[MAXPATHLEN + 1], *strerror(); ! 89: ! 90: if ((lnklen = readlink(name, path, MAXPATHLEN)) == -1) { ! 91: (void)fprintf(stderr, "\nfind: %s: %s\n", name, strerror(errno)); ! 92: return; ! 93: } ! 94: path[lnklen] = '\0'; ! 95: (void)printf(" -> %s", path); ! 96: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.