Commit | Line | Data |
---|---|---|
45fc66f9 KB |
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 | |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
16 | */ | |
17 | ||
18 | #ifndef lint | |
19341997 | 19 | static char sccsid[] = "@(#)ls.c 5.3 (Berkeley) %G%"; |
45fc66f9 KB |
20 | #endif /* not lint */ |
21 | ||
22 | #include <sys/param.h> | |
23 | #include <sys/stat.h> | |
24 | #include <tzfile.h> | |
25 | #include <utmp.h> | |
26 | #include <stdio.h> | |
27 | ||
28 | /* Derived from the print routines in the ls(1) source code. */ | |
29 | ||
30 | extern int errno; | |
31 | ||
32 | void | |
33 | printlong(name, accpath, sb) | |
34 | char *name; /* filename to print */ | |
35 | char *accpath; /* current valid path to filename */ | |
36 | struct stat *sb; /* stat buffer */ | |
37 | { | |
731250ce | 38 | extern int errno; |
19341997 | 39 | char modep[15], *user_from_uid(), *group_from_gid(), *strerror(); |
45fc66f9 KB |
40 | |
41 | (void)printf("%6lu %4ld ", sb->st_ino, sb->st_blocks); | |
19341997 | 42 | (void)strmode(sb->st_mode, modep); |
731250ce | 43 | (void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, UT_NAMESIZE, |
45fc66f9 KB |
44 | user_from_uid(sb->st_uid, 0), UT_NAMESIZE, |
45 | group_from_gid(sb->st_gid, 0)); | |
46 | ||
47 | if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) | |
48 | (void)printf("%3d, %3d ", major(sb->st_rdev), | |
49 | minor(sb->st_rdev)); | |
50 | else | |
51 | (void)printf("%8ld ", sb->st_size); | |
52 | printtime(sb->st_mtime); | |
53 | (void)printf("%s", name); | |
54 | if (S_ISLNK(sb->st_mode)) | |
55 | printlink(accpath); | |
56 | (void)putchar('\n'); | |
57 | } | |
58 | ||
59 | printtime(ftime) | |
60 | time_t ftime; | |
61 | { | |
62 | int i; | |
63 | char *longstring, *ctime(); | |
64 | time_t time(); | |
65 | ||
66 | longstring = ctime((long *)&ftime); | |
67 | for (i = 4; i < 11; ++i) | |
68 | (void)putchar(longstring[i]); | |
69 | ||
70 | #define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY) | |
71 | if (ftime + SIXMONTHS > time((time_t *)NULL)) | |
72 | for (i = 11; i < 16; ++i) | |
73 | (void)putchar(longstring[i]); | |
74 | else { | |
75 | (void)putchar(' '); | |
76 | for (i = 20; i < 24; ++i) | |
77 | (void)putchar(longstring[i]); | |
78 | } | |
79 | (void)putchar(' '); | |
80 | } | |
81 | ||
45fc66f9 KB |
82 | printlink(name) |
83 | char *name; | |
84 | { | |
85 | int lnklen; | |
86 | char path[MAXPATHLEN + 1], *strerror(); | |
87 | ||
88 | if ((lnklen = readlink(name, path, MAXPATHLEN)) == -1) { | |
89 | (void)fprintf(stderr, "\nfind: %s: %s\n", name, strerror(errno)); | |
90 | return; | |
91 | } | |
92 | path[lnklen] = '\0'; | |
93 | (void)printf(" -> %s", path); | |
94 | } |