1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
$NetBSD: patch-ac,v 1.7 2015/07/09 11:44:09 jperkin Exp $
Use nbcompat.
--- ls.c.orig 1996-12-21 23:40:58.000000000 +0000
+++ ls.c
@@ -53,18 +53,37 @@ static char const sccsid[] = "@(#)ls.c 8
#include <dirent.h>
#include <err.h>
#include <errno.h>
+#if defined(HAVE_NBCOMPAT_H)
+#include <nbcompat.h>
+#include <nbcompat/fts.h>
+#else
#include <fts.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <locale.h>
+#ifdef HAVE_NBCOMPAT_H
+#include <nbcompat/pwd.h>
+#include <nbcompat/grp.h>
+#endif
+#include <pwd.h>
+#include <grp.h>
+
+#ifdef __sun
+#include <sys/ttold.h>
+#endif
#include "ls.h"
#include "extern.h"
static void display __P((FTSENT *, FTSENT *));
+#ifdef __DragonFly__
+static int mastercmp __P((const FTSENT * const *, const FTSENT * const *));
+#else
static int mastercmp __P((const FTSENT **, const FTSENT **));
+#endif
static void traverse __P((int, char **, int));
static void (*printfcn) __P((DISPLAY *));
@@ -76,7 +95,9 @@ int termwidth = 80; /* default terminal
/* flags */
int f_accesstime; /* use time of last access */
int f_column; /* columnated format */
+#ifndef __sun
int f_flags; /* show flags associated with a file */
+#endif
int f_inode; /* print inode */
int f_kblocks; /* print size in kilobytes */
int f_listdir; /* list actual directory, not contents */
@@ -94,6 +115,7 @@ int f_statustime; /* use time of last m
int f_dirname; /* if precede with directory name */
int f_timesort; /* sort by time vice name */
int f_type; /* add type character for non-regular files */
+int f_color; /* add type in color for non-regular files */
#ifndef BSD4_4_LITE
int f_whiteout; /* show whiteout entries */
#endif
@@ -135,9 +157,13 @@ main(argc, argv)
fts_options = FTS_PHYSICAL;
#ifdef BSD4_4_LITE
- while ((ch = getopt(argc, argv, "1ACFLRTacdfgikloqrstu")) != EOF) {
+ while ((ch = getopt(argc, argv, "1ACFGLRTacdfgikloqrstu")) != EOF) {
#else
- while ((ch = getopt(argc, argv, "1ACFLRTWacdfgikloqrstu")) != EOF) {
+#ifndef __sun
+ while ((ch = getopt(argc, argv, "1ACFGLRTWacdfgikloqrstu")) != EOF) {
+#else
+ while ((ch = getopt(argc, argv, "1ACFGLRTWacdfgiklqrstu")) != EOF) {
+#endif
#endif
switch (ch) {
/*
@@ -168,6 +194,10 @@ main(argc, argv)
case 'F':
f_type = 1;
break;
+ case 'G':
+ if (isatty(STDOUT_FILENO))
+ f_color = 1;
+ break;
case 'L':
fts_options &= ~FTS_PHYSICAL;
fts_options |= FTS_LOGICAL;
@@ -197,9 +227,11 @@ main(argc, argv)
case 'k':
f_kblocks = 1;
break;
+#ifndef __sun
case 'o':
f_flags = 1;
break;
+#endif
case 'q':
f_nonprint = 1;
break;
@@ -228,18 +260,21 @@ main(argc, argv)
argc -= optind;
argv += optind;
+ parsecolors(getenv("LSCOLORS"));
+
/*
* If not -F, -i, -l, -s or -t options, don't require stat
* information.
*/
- if (!f_inode && !f_longform && !f_size && !f_timesort && !f_type)
+ if (!f_inode && !f_longform && !f_size && !f_timesort && !f_type
+ && !f_color)
fts_options |= FTS_NOSTAT;
/*
* If not -F, -d or -l options, follow any symbolic links listed on
* the command line.
*/
- if (!f_longform && !f_listdir && !f_type)
+ if (!f_longform && !f_listdir && !f_type && !f_color)
fts_options |= FTS_COMFOLLOW;
#ifndef BSD4_4_LITE
@@ -257,7 +292,11 @@ main(argc, argv)
if (f_kblocks)
blocksize = 2;
else {
+#ifdef __sun
+ blocksize = 512;
+#else
(void)getbsize(¬used, &blocksize);
+#endif
blocksize /= 512;
}
}
@@ -384,7 +423,8 @@ display(p, list)
u_long btotal, maxblock, maxinode, maxlen, maxnlink;
int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser;
int entries, needstats;
- char *user, *group, *flags, buf[20]; /* 32 bits == 10 digits */
+ const char *user, *group;
+ char *flags, buf[20]; /* 32 bits == 10 digits */
/*
* If list is NULL there are two possibilities: that the parent
@@ -452,12 +492,14 @@ display(p, list)
group = group_from_gid(sp->st_gid, 0);
if ((glen = strlen(group)) > maxgroup)
maxgroup = glen;
+#ifndef __sun
if (f_flags) {
flags =
flags_to_string(sp->st_flags, "-");
if ((flen = strlen(flags)) > maxflags)
maxflags = flen;
} else
+#endif
flen = 0;
if ((np = malloc(sizeof(NAMES) +
@@ -473,10 +515,12 @@ display(p, list)
S_ISBLK(sp->st_mode))
bcfile = 1;
+#ifndef __sun
if (f_flags) {
np->flags = &np->data[ulen + glen + 2];
(void)strcpy(np->flags, flags);
}
+#endif
cur->fts_pointer = np;
}
}
@@ -500,7 +544,7 @@ display(p, list)
d.s_inode = strlen(buf);
(void)snprintf(buf, sizeof(buf), "%lu", maxnlink);
d.s_nlink = strlen(buf);
- (void)snprintf(buf, sizeof(buf), "%qu", maxsize);
+ (void)snprintf(buf, sizeof(buf), "%llu", (long long)maxsize);
d.s_size = strlen(buf);
d.s_user = maxuser;
}
@@ -521,7 +565,11 @@ display(p, list)
*/
static int
mastercmp(a, b)
+#ifdef __DragonFly__
+ const FTSENT * const *a, * const *b;
+#else
const FTSENT **a, **b;
+#endif
{
int a_info, b_info;
|