Deleted Added
full compact
print.c (242840) print.c (284198)
1/*-
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Michael Fischbein.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 */
32
33#if 0
34#ifndef lint
35static char sccsid[] = "@(#)print.c 8.4 (Berkeley) 4/17/94";
36#endif /* not lint */
37#endif
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Michael Fischbein.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 */
32
33#if 0
34#ifndef lint
35static char sccsid[] = "@(#)print.c 8.4 (Berkeley) 4/17/94";
36#endif /* not lint */
37#endif
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/bin/ls/print.c 242840 2012-11-09 20:19:56Z peter $");
39__FBSDID("$FreeBSD: head/bin/ls/print.c 284198 2015-06-10 01:27:38Z marcel $");
40
41#include <sys/param.h>
42#include <sys/stat.h>
43#include <sys/acl.h>
44
45#include <err.h>
46#include <errno.h>
47#include <fts.h>

--- 5 unchanged lines hidden (view full) ---

53#include <string.h>
54#include <time.h>
55#include <unistd.h>
56#ifdef COLORLS
57#include <ctype.h>
58#include <termcap.h>
59#include <signal.h>
60#endif
40
41#include <sys/param.h>
42#include <sys/stat.h>
43#include <sys/acl.h>
44
45#include <err.h>
46#include <errno.h>
47#include <fts.h>

--- 5 unchanged lines hidden (view full) ---

53#include <string.h>
54#include <time.h>
55#include <unistd.h>
56#ifdef COLORLS
57#include <ctype.h>
58#include <termcap.h>
59#include <signal.h>
60#endif
61#include <libxo/xo.h>
61
62#include "ls.h"
63#include "extern.h"
64
65static int printaname(const FTSENT *, u_long, u_long);
66static void printdev(size_t, dev_t);
67static void printlink(const FTSENT *);
62
63#include "ls.h"
64#include "extern.h"
65
66static int printaname(const FTSENT *, u_long, u_long);
67static void printdev(size_t, dev_t);
68static void printlink(const FTSENT *);
68static void printtime(time_t);
69static void printtime(const char *, time_t);
69static int printtype(u_int);
70static int printtype(u_int);
70static void printsize(size_t, off_t);
71static void printsize(const char *, size_t, off_t);
71#ifdef COLORLS
72static void endcolor(int);
73static int colortype(mode_t);
74#endif
75static void aclmode(char *, const FTSENT *);
76
77#define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
78

--- 25 unchanged lines hidden (view full) ---

104} colors[C_NUMCOLORS];
105#endif
106
107void
108printscol(const DISPLAY *dp)
109{
110 FTSENT *p;
111
72#ifdef COLORLS
73static void endcolor(int);
74static int colortype(mode_t);
75#endif
76static void aclmode(char *, const FTSENT *);
77
78#define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
79

--- 25 unchanged lines hidden (view full) ---

105} colors[C_NUMCOLORS];
106#endif
107
108void
109printscol(const DISPLAY *dp)
110{
111 FTSENT *p;
112
113 xo_open_list("entry");
112 for (p = dp->list; p; p = p->fts_link) {
113 if (IS_NOPRINT(p))
114 continue;
114 for (p = dp->list; p; p = p->fts_link) {
115 if (IS_NOPRINT(p))
116 continue;
117 xo_open_instance("entry");
115 (void)printaname(p, dp->s_inode, dp->s_block);
118 (void)printaname(p, dp->s_inode, dp->s_block);
116 (void)putchar('\n');
119 xo_close_instance("entry");
120 xo_emit("\n");
117 }
121 }
122 xo_close_list("entry");
118}
119
120/*
121 * print name in current style
122 */
123int
123}
124
125/*
126 * print name in current style
127 */
128int
124printname(const char *name)
129printname(const char *field, const char *name)
125{
130{
131 char fmt[BUFSIZ];
132 char *s = getname(name);
133 int rc;
134
135 snprintf(fmt, sizeof(fmt), "{:%s/%%hs}", field);
136 rc = xo_emit(fmt, s);
137 free(s);
138 return rc;
139}
140
141/*
142 * print name in current style
143 */
144char *
145getname(const char *name)
146{
126 if (f_octal || f_octal_escape)
147 if (f_octal || f_octal_escape)
127 return prn_octal(name);
148 return get_octal(name);
128 else if (f_nonprint)
149 else if (f_nonprint)
129 return prn_printable(name);
150 return get_printable(name);
130 else
151 else
131 return prn_normal(name);
152 return strdup(name);
132}
133
134void
135printlong(const DISPLAY *dp)
136{
137 struct stat *sp;
138 FTSENT *p;
139 NAMES *np;
140 char buf[20];
141#ifdef COLORLS
142 int color_printed = 0;
143#endif
144
145 if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
146 (f_longform || f_size)) {
153}
154
155void
156printlong(const DISPLAY *dp)
157{
158 struct stat *sp;
159 FTSENT *p;
160 NAMES *np;
161 char buf[20];
162#ifdef COLORLS
163 int color_printed = 0;
164#endif
165
166 if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
167 (f_longform || f_size)) {
147 (void)printf("total %lu\n", howmany(dp->btotal, blocksize));
168 xo_emit("{L:total} {:total-blocks/%lu}\n",
169 howmany(dp->btotal, blocksize));
148 }
149
170 }
171
172 xo_open_list("entry");
150 for (p = dp->list; p; p = p->fts_link) {
173 for (p = dp->list; p; p = p->fts_link) {
174 char *name;
151 if (IS_NOPRINT(p))
152 continue;
175 if (IS_NOPRINT(p))
176 continue;
177 xo_open_instance("entry");
153 sp = p->fts_statp;
178 sp = p->fts_statp;
179 name = getname(p->fts_name);
180 if (name)
181 xo_emit("{ke:name}", name);
154 if (f_inode)
182 if (f_inode)
155 (void)printf("%*ju ",
183 xo_emit("{:inode/%*ju} ",
156 dp->s_inode, (uintmax_t)sp->st_ino);
157 if (f_size)
184 dp->s_inode, (uintmax_t)sp->st_ino);
185 if (f_size)
158 (void)printf("%*jd ",
186 xo_emit("{:blocks/%*jd} ",
159 dp->s_block, howmany(sp->st_blocks, blocksize));
160 strmode(sp->st_mode, buf);
161 aclmode(buf, p);
162 np = p->fts_pointer;
187 dp->s_block, howmany(sp->st_blocks, blocksize));
188 strmode(sp->st_mode, buf);
189 aclmode(buf, p);
190 np = p->fts_pointer;
163 (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink,
164 sp->st_nlink, dp->s_user, np->user, dp->s_group,
165 np->group);
191 xo_attr("value", "%03o", (int) sp->st_mode & ALLPERMS);
192 xo_emit("{t:mode/%s} {:links/%*u} {:user/%-*s} {:group/%-*s} ",
193 buf, dp->s_nlink, sp->st_nlink,
194 dp->s_user, np->user, dp->s_group, np->group);
166 if (f_flags)
195 if (f_flags)
167 (void)printf("%-*s ", dp->s_flags, np->flags);
196 xo_emit("{:flags/%-*s} ", dp->s_flags, np->flags);
168 if (f_label)
197 if (f_label)
169 (void)printf("%-*s ", dp->s_label, np->label);
198 xo_emit("{:label/%-*s} ", dp->s_label, np->label);
170 if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
171 printdev(dp->s_size, sp->st_rdev);
172 else
199 if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
200 printdev(dp->s_size, sp->st_rdev);
201 else
173 printsize(dp->s_size, sp->st_size);
202 printsize("size", dp->s_size, sp->st_size);
174 if (f_accesstime)
203 if (f_accesstime)
175 printtime(sp->st_atime);
204 printtime("access-time", sp->st_atime);
176 else if (f_birthtime)
205 else if (f_birthtime)
177 printtime(sp->st_birthtime);
206 printtime("birth-time", sp->st_birthtime);
178 else if (f_statustime)
207 else if (f_statustime)
179 printtime(sp->st_ctime);
208 printtime("change-time", sp->st_ctime);
180 else
209 else
181 printtime(sp->st_mtime);
210 printtime("modify-time", sp->st_mtime);
182#ifdef COLORLS
183 if (f_color)
184 color_printed = colortype(sp->st_mode);
185#endif
211#ifdef COLORLS
212 if (f_color)
213 color_printed = colortype(sp->st_mode);
214#endif
186 (void)printname(p->fts_name);
215
216 if (name) {
217 xo_emit("{dk:name}", name);
218 free(name);
219 }
220
187#ifdef COLORLS
188 if (f_color && color_printed)
189 endcolor(0);
190#endif
191 if (f_type)
192 (void)printtype(sp->st_mode);
193 if (S_ISLNK(sp->st_mode))
194 printlink(p);
221#ifdef COLORLS
222 if (f_color && color_printed)
223 endcolor(0);
224#endif
225 if (f_type)
226 (void)printtype(sp->st_mode);
227 if (S_ISLNK(sp->st_mode))
228 printlink(p);
195 (void)putchar('\n');
229 xo_close_instance("entry");
230 xo_emit("\n");
196 }
231 }
232 xo_close_list("entry");
197}
198
199void
200printstream(const DISPLAY *dp)
201{
202 FTSENT *p;
203 int chcnt;
204
205 for (p = dp->list, chcnt = 0; p; p = p->fts_link) {
206 if (p->fts_number == NO_PRINT)
207 continue;
208 /* XXX strlen does not take octal escapes into account. */
209 if (strlen(p->fts_name) + chcnt +
210 (p->fts_link ? 2 : 0) >= (unsigned)termwidth) {
233}
234
235void
236printstream(const DISPLAY *dp)
237{
238 FTSENT *p;
239 int chcnt;
240
241 for (p = dp->list, chcnt = 0; p; p = p->fts_link) {
242 if (p->fts_number == NO_PRINT)
243 continue;
244 /* XXX strlen does not take octal escapes into account. */
245 if (strlen(p->fts_name) + chcnt +
246 (p->fts_link ? 2 : 0) >= (unsigned)termwidth) {
211 putchar('\n');
247 xo_emit("\n");
212 chcnt = 0;
213 }
214 chcnt += printaname(p, dp->s_inode, dp->s_block);
215 if (p->fts_link) {
248 chcnt = 0;
249 }
250 chcnt += printaname(p, dp->s_inode, dp->s_block);
251 if (p->fts_link) {
216 printf(", ");
252 xo_emit(", ");
217 chcnt += 2;
218 }
219 }
220 if (chcnt)
253 chcnt += 2;
254 }
255 }
256 if (chcnt)
221 putchar('\n');
257 xo_emit("\n");
222}
223
224void
225printcol(const DISPLAY *dp)
226{
227 static FTSENT **array;
228 static int lastentries = -1;
229 FTSENT *p;

--- 17 unchanged lines hidden (view full) ---

247
248 /*
249 * Have to do random access in the linked list -- build a table
250 * of pointers.
251 */
252 if (dp->entries > lastentries) {
253 if ((narray =
254 realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) {
258}
259
260void
261printcol(const DISPLAY *dp)
262{
263 static FTSENT **array;
264 static int lastentries = -1;
265 FTSENT *p;

--- 17 unchanged lines hidden (view full) ---

283
284 /*
285 * Have to do random access in the linked list -- build a table
286 * of pointers.
287 */
288 if (dp->entries > lastentries) {
289 if ((narray =
290 realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) {
255 warn(NULL);
291 xo_warn(NULL);
256 printscol(dp);
257 return;
258 }
259 lastentries = dp->entries;
260 array = narray;
261 }
262 for (p = dp->list, num = 0; p; p = p->fts_link)
263 if (p->fts_number != NO_PRINT)

--- 14 unchanged lines hidden (view full) ---

278 }
279 numcols = termwidth / colwidth;
280 numrows = num / numcols;
281 if (num % numcols)
282 ++numrows;
283
284 if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
285 (f_longform || f_size)) {
292 printscol(dp);
293 return;
294 }
295 lastentries = dp->entries;
296 array = narray;
297 }
298 for (p = dp->list, num = 0; p; p = p->fts_link)
299 if (p->fts_number != NO_PRINT)

--- 14 unchanged lines hidden (view full) ---

314 }
315 numcols = termwidth / colwidth;
316 numrows = num / numcols;
317 if (num % numcols)
318 ++numrows;
319
320 if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
321 (f_longform || f_size)) {
286 (void)printf("total %lu\n", howmany(dp->btotal, blocksize));
322 xo_emit("{L:total} {:total-blocks/%lu}\n",
323 howmany(dp->btotal, blocksize));
287 }
288
324 }
325
326 xo_open_list("entry");
289 base = 0;
290 for (row = 0; row < numrows; ++row) {
291 endcol = colwidth;
292 if (!f_sortacross)
293 base = row;
294 for (col = 0, chcnt = 0; col < numcols; ++col) {
327 base = 0;
328 for (row = 0; row < numrows; ++row) {
329 endcol = colwidth;
330 if (!f_sortacross)
331 base = row;
332 for (col = 0, chcnt = 0; col < numcols; ++col) {
333 xo_open_instance("entry");
295 chcnt += printaname(array[base], dp->s_inode,
296 dp->s_block);
334 chcnt += printaname(array[base], dp->s_inode,
335 dp->s_block);
336 xo_close_instance("entry");
297 if (f_sortacross)
298 base++;
299 else
300 base += numrows;
301 if (base >= num)
302 break;
303 while ((cnt = ((chcnt + tabwidth) & ~(tabwidth - 1)))
304 <= endcol) {
305 if (f_sortacross && col + 1 >= numcols)
306 break;
337 if (f_sortacross)
338 base++;
339 else
340 base += numrows;
341 if (base >= num)
342 break;
343 while ((cnt = ((chcnt + tabwidth) & ~(tabwidth - 1)))
344 <= endcol) {
345 if (f_sortacross && col + 1 >= numcols)
346 break;
307 (void)putchar(f_notabs ? ' ' : '\t');
347 xo_emit(f_notabs ? " " : "\t");
308 chcnt = cnt;
309 }
310 endcol += colwidth;
311 }
348 chcnt = cnt;
349 }
350 endcol += colwidth;
351 }
312 (void)putchar('\n');
352 xo_emit("\n");
313 }
353 }
354 xo_close_list("entry");
314}
315
316/*
317 * print [inode] [size] name
318 * return # of characters printed, no trailing characters.
319 */
320static int
321printaname(const FTSENT *p, u_long inodefield, u_long sizefield)
322{
323 struct stat *sp;
324 int chcnt;
325#ifdef COLORLS
326 int color_printed = 0;
327#endif
328
329 sp = p->fts_statp;
330 chcnt = 0;
331 if (f_inode)
355}
356
357/*
358 * print [inode] [size] name
359 * return # of characters printed, no trailing characters.
360 */
361static int
362printaname(const FTSENT *p, u_long inodefield, u_long sizefield)
363{
364 struct stat *sp;
365 int chcnt;
366#ifdef COLORLS
367 int color_printed = 0;
368#endif
369
370 sp = p->fts_statp;
371 chcnt = 0;
372 if (f_inode)
332 chcnt += printf("%*ju ",
373 chcnt += xo_emit("{:inode/%*ju} ",
333 (int)inodefield, (uintmax_t)sp->st_ino);
334 if (f_size)
374 (int)inodefield, (uintmax_t)sp->st_ino);
375 if (f_size)
335 chcnt += printf("%*jd ",
376 chcnt += xo_emit("{:size/%*jd} ",
336 (int)sizefield, howmany(sp->st_blocks, blocksize));
337#ifdef COLORLS
338 if (f_color)
339 color_printed = colortype(sp->st_mode);
340#endif
377 (int)sizefield, howmany(sp->st_blocks, blocksize));
378#ifdef COLORLS
379 if (f_color)
380 color_printed = colortype(sp->st_mode);
381#endif
341 chcnt += printname(p->fts_name);
382 chcnt += printname("name", p->fts_name);
342#ifdef COLORLS
343 if (f_color && color_printed)
344 endcolor(0);
345#endif
346 if (f_type)
347 chcnt += printtype(sp->st_mode);
348 return (chcnt);
349}
350
351/*
352 * Print device special file major and minor numbers.
353 */
354static void
355printdev(size_t width, dev_t dev)
356{
383#ifdef COLORLS
384 if (f_color && color_printed)
385 endcolor(0);
386#endif
387 if (f_type)
388 chcnt += printtype(sp->st_mode);
389 return (chcnt);
390}
391
392/*
393 * Print device special file major and minor numbers.
394 */
395static void
396printdev(size_t width, dev_t dev)
397{
357
358 (void)printf("%#*jx ", (u_int)width, (uintmax_t)dev);
398 xo_emit("{:device/%#*jx} ", (u_int)width, (uintmax_t)dev);
359}
360
361static void
399}
400
401static void
362printtime(time_t ftime)
402printtime(const char *field, time_t ftime)
363{
364 char longstring[80];
403{
404 char longstring[80];
405 char fmt[BUFSIZ];
365 static time_t now = 0;
366 const char *format;
367 static int d_first = -1;
368
369 if (d_first < 0)
370 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
371 if (now == 0)
372 now = time(NULL);

--- 6 unchanged lines hidden (view full) ---

379 format = d_first ? "%e %b %T %Y" : "%b %e %T %Y";
380 else if (ftime + SIXMONTHS > now && ftime < now + SIXMONTHS)
381 /* mmm dd hh:mm || dd mmm hh:mm */
382 format = d_first ? "%e %b %R" : "%b %e %R";
383 else
384 /* mmm dd yyyy || dd mmm yyyy */
385 format = d_first ? "%e %b %Y" : "%b %e %Y";
386 strftime(longstring, sizeof(longstring), format, localtime(&ftime));
406 static time_t now = 0;
407 const char *format;
408 static int d_first = -1;
409
410 if (d_first < 0)
411 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
412 if (now == 0)
413 now = time(NULL);

--- 6 unchanged lines hidden (view full) ---

420 format = d_first ? "%e %b %T %Y" : "%b %e %T %Y";
421 else if (ftime + SIXMONTHS > now && ftime < now + SIXMONTHS)
422 /* mmm dd hh:mm || dd mmm hh:mm */
423 format = d_first ? "%e %b %R" : "%b %e %R";
424 else
425 /* mmm dd yyyy || dd mmm yyyy */
426 format = d_first ? "%e %b %Y" : "%b %e %Y";
427 strftime(longstring, sizeof(longstring), format, localtime(&ftime));
387 fputs(longstring, stdout);
388 fputc(' ', stdout);
428
429 snprintf(fmt, sizeof(fmt), "{:%s/%%s} ", field);
430 xo_attr("value", "%ld", (long) ftime);
431 xo_emit(fmt, longstring);
389}
390
391static int
392printtype(u_int mode)
393{
394
395 if (f_slash) {
396 if ((mode & S_IFMT) == S_IFDIR) {
432}
433
434static int
435printtype(u_int mode)
436{
437
438 if (f_slash) {
439 if ((mode & S_IFMT) == S_IFDIR) {
397 (void)putchar('/');
440 xo_emit("{D:\\/}{e:type/directory}");
398 return (1);
399 }
400 return (0);
401 }
402
403 switch (mode & S_IFMT) {
404 case S_IFDIR:
441 return (1);
442 }
443 return (0);
444 }
445
446 switch (mode & S_IFMT) {
447 case S_IFDIR:
405 (void)putchar('/');
448 xo_emit("{D:/\\/}{e:type/directory}");
406 return (1);
407 case S_IFIFO:
449 return (1);
450 case S_IFIFO:
408 (void)putchar('|');
451 xo_emit("{D:|}{e:type/fifo}");
409 return (1);
410 case S_IFLNK:
452 return (1);
453 case S_IFLNK:
411 (void)putchar('@');
454 xo_emit("{D:@}{e:type/link}");
412 return (1);
413 case S_IFSOCK:
455 return (1);
456 case S_IFSOCK:
414 (void)putchar('=');
457 xo_emit("{D:=}{e:type/socket}");
415 return (1);
416 case S_IFWHT:
458 return (1);
459 case S_IFWHT:
417 (void)putchar('%');
460 xo_emit("{D:%}{e:type/whiteout}");
418 return (1);
419 default:
420 break;
421 }
422 if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
461 return (1);
462 default:
463 break;
464 }
465 if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
423 (void)putchar('*');
466 xo_emit("{D:*}{e:executable/}");
424 return (1);
425 }
426 return (0);
427}
428
429#ifdef COLORLS
430static int
431putch(int c)
432{
467 return (1);
468 }
469 return (0);
470}
471
472#ifdef COLORLS
473static int
474putch(int c)
475{
433 (void)putchar(c);
476 xo_emit("{D:/%c}", c);
434 return 0;
435}
436
437static int
438writech(int c)
439{
440 char tmp = (char)c;
441

--- 92 unchanged lines hidden (view full) ---

534 c[0] = cs[2 * i];
535 c[1] = cs[2 * i + 1];
536 }
537 for (j = 0; j < 2; j++) {
538 /* Legacy colours used 0-7 */
539 if (c[j] >= '0' && c[j] <= '7') {
540 colors[i].num[j] = c[j] - '0';
541 if (!legacy_warn) {
477 return 0;
478}
479
480static int
481writech(int c)
482{
483 char tmp = (char)c;
484

--- 92 unchanged lines hidden (view full) ---

577 c[0] = cs[2 * i];
578 c[1] = cs[2 * i + 1];
579 }
580 for (j = 0; j < 2; j++) {
581 /* Legacy colours used 0-7 */
582 if (c[j] >= '0' && c[j] <= '7') {
583 colors[i].num[j] = c[j] - '0';
584 if (!legacy_warn) {
542 warnx("LSCOLORS should use "
585 xo_warnx("LSCOLORS should use "
543 "characters a-h instead of 0-9 ("
544 "see the manual page)");
545 }
546 legacy_warn = 1;
547 } else if (c[j] >= 'a' && c[j] <= 'h')
548 colors[i].num[j] = c[j] - 'a';
549 else if (c[j] >= 'A' && c[j] <= 'H') {
550 colors[i].num[j] = c[j] - 'A';
551 colors[i].bold = 1;
552 } else if (tolower((unsigned char)c[j]) == 'x')
553 colors[i].num[j] = -1;
554 else {
586 "characters a-h instead of 0-9 ("
587 "see the manual page)");
588 }
589 legacy_warn = 1;
590 } else if (c[j] >= 'a' && c[j] <= 'h')
591 colors[i].num[j] = c[j] - 'a';
592 else if (c[j] >= 'A' && c[j] <= 'H') {
593 colors[i].num[j] = c[j] - 'A';
594 colors[i].bold = 1;
595 } else if (tolower((unsigned char)c[j]) == 'x')
596 colors[i].num[j] = -1;
597 else {
555 warnx("invalid character '%c' in LSCOLORS"
598 xo_warnx("invalid character '%c' in LSCOLORS"
556 " env var", c[j]);
557 colors[i].num[j] = -1;
558 }
559 }
560 }
561}
562
563void

--- 15 unchanged lines hidden (view full) ---

579 char path[MAXPATHLEN + 1];
580
581 if (p->fts_level == FTS_ROOTLEVEL)
582 (void)snprintf(name, sizeof(name), "%s", p->fts_name);
583 else
584 (void)snprintf(name, sizeof(name),
585 "%s/%s", p->fts_parent->fts_accpath, p->fts_name);
586 if ((lnklen = readlink(name, path, sizeof(path) - 1)) == -1) {
599 " env var", c[j]);
600 colors[i].num[j] = -1;
601 }
602 }
603 }
604}
605
606void

--- 15 unchanged lines hidden (view full) ---

622 char path[MAXPATHLEN + 1];
623
624 if (p->fts_level == FTS_ROOTLEVEL)
625 (void)snprintf(name, sizeof(name), "%s", p->fts_name);
626 else
627 (void)snprintf(name, sizeof(name),
628 "%s/%s", p->fts_parent->fts_accpath, p->fts_name);
629 if ((lnklen = readlink(name, path, sizeof(path) - 1)) == -1) {
587 (void)fprintf(stderr, "\nls: %s: %s\n", name, strerror(errno));
630 xo_error("\nls: %s: %s\n", name, strerror(errno));
588 return;
589 }
590 path[lnklen] = '\0';
631 return;
632 }
633 path[lnklen] = '\0';
591 (void)printf(" -> ");
592 (void)printname(path);
634 xo_emit(" -> ");
635 (void)printname("target", path);
593}
594
595static void
636}
637
638static void
596printsize(size_t width, off_t bytes)
639printsize(const char *field, size_t width, off_t bytes)
597{
640{
598
641 char fmt[BUFSIZ];
642
599 if (f_humanval) {
600 /*
601 * Reserve one space before the size and allocate room for
602 * the trailing '\0'.
603 */
604 char buf[HUMANVALSTR_LEN - 1 + 1];
605
606 humanize_number(buf, sizeof(buf), (int64_t)bytes, "",
607 HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
643 if (f_humanval) {
644 /*
645 * Reserve one space before the size and allocate room for
646 * the trailing '\0'.
647 */
648 char buf[HUMANVALSTR_LEN - 1 + 1];
649
650 humanize_number(buf, sizeof(buf), (int64_t)bytes, "",
651 HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
608 (void)printf("%*s ", (u_int)width, buf);
609 } else if (f_thousands) { /* with commas */
652 snprintf(fmt, sizeof(fmt), "{:%s/%%%ds} ", field, (int) width);
653 xo_attr("value", "%jd", (intmax_t) bytes);
654 xo_emit(fmt, buf);
655 } else { /* with commas */
610 /* This format assignment needed to work round gcc bug. */
656 /* This format assignment needed to work round gcc bug. */
611 const char *format = "%*j'd ";
612 (void)printf(format, (u_int)width, bytes);
613 } else
614 (void)printf("%*jd ", (u_int)width, bytes);
657 snprintf(fmt, sizeof(fmt), "{:%s/%%%dj%sd} ",
658 field, (int) width, f_thousands ? "'" : "");
659 xo_emit(fmt, (intmax_t) bytes);
660 }
615}
616
617/*
618 * Add a + after the standard rwxrwxrwx mode if the file has an
619 * ACL. strmode() reserves space at the end of the string.
620 */
621static void
622aclmode(char *buf, const FTSENT *p)

--- 26 unchanged lines hidden (view full) ---

649 previous_dev = p->fts_statp->st_dev;
650 supports_acls = 0;
651
652 ret = lpathconf(name, _PC_ACL_NFS4);
653 if (ret > 0) {
654 type = ACL_TYPE_NFS4;
655 supports_acls = 1;
656 } else if (ret < 0 && errno != EINVAL) {
661}
662
663/*
664 * Add a + after the standard rwxrwxrwx mode if the file has an
665 * ACL. strmode() reserves space at the end of the string.
666 */
667static void
668aclmode(char *buf, const FTSENT *p)

--- 26 unchanged lines hidden (view full) ---

695 previous_dev = p->fts_statp->st_dev;
696 supports_acls = 0;
697
698 ret = lpathconf(name, _PC_ACL_NFS4);
699 if (ret > 0) {
700 type = ACL_TYPE_NFS4;
701 supports_acls = 1;
702 } else if (ret < 0 && errno != EINVAL) {
657 warn("%s", name);
703 xo_warn("%s", name);
658 return;
659 }
660 if (supports_acls == 0) {
661 ret = lpathconf(name, _PC_ACL_EXTENDED);
662 if (ret > 0) {
663 type = ACL_TYPE_ACCESS;
664 supports_acls = 1;
665 } else if (ret < 0 && errno != EINVAL) {
704 return;
705 }
706 if (supports_acls == 0) {
707 ret = lpathconf(name, _PC_ACL_EXTENDED);
708 if (ret > 0) {
709 type = ACL_TYPE_ACCESS;
710 supports_acls = 1;
711 } else if (ret < 0 && errno != EINVAL) {
666 warn("%s", name);
712 xo_warn("%s", name);
667 return;
668 }
669 }
670 }
671 if (supports_acls == 0)
672 return;
673 facl = acl_get_link_np(name, type);
674 if (facl == NULL) {
713 return;
714 }
715 }
716 }
717 if (supports_acls == 0)
718 return;
719 facl = acl_get_link_np(name, type);
720 if (facl == NULL) {
675 warn("%s", name);
721 xo_warn("%s", name);
676 return;
677 }
678 if (acl_is_trivial_np(facl, &trivial)) {
679 acl_free(facl);
722 return;
723 }
724 if (acl_is_trivial_np(facl, &trivial)) {
725 acl_free(facl);
680 warn("%s", name);
726 xo_warn("%s", name);
681 return;
682 }
683 if (!trivial)
684 buf[10] = '+';
685 acl_free(facl);
686}
727 return;
728 }
729 if (!trivial)
730 buf[10] = '+';
731 acl_free(facl);
732}