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 202945 2010-01-24 19:23:07Z jh $"); |
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> --- 9 unchanged lines hidden (view full) --- 57#include <termcap.h> 58#include <signal.h> 59#endif 60 61#include "ls.h" 62#include "extern.h" 63 64static int printaname(const FTSENT *, u_long, u_long); |
65static void printdev(size_t, dev_t); |
66static void printlink(const FTSENT *); 67static void printtime(time_t); 68static int printtype(u_int); 69static void printsize(size_t, off_t); 70#ifdef COLORLS 71static void endcolor(int); 72static int colortype(mode_t); 73#endif --- 87 unchanged lines hidden (view full) --- 161 (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink, 162 sp->st_nlink, dp->s_user, np->user, dp->s_group, 163 np->group); 164 if (f_flags) 165 (void)printf("%-*s ", dp->s_flags, np->flags); 166 if (f_label) 167 (void)printf("%-*s ", dp->s_label, np->label); 168 if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode)) |
169 printdev(dp->s_size, sp->st_rdev); |
170 else 171 printsize(dp->s_size, sp->st_size); 172 if (f_accesstime) 173 printtime(sp->st_atime); 174 else if (f_birthtime) 175 printtime(sp->st_birthtime); 176 else if (f_statustime) 177 printtime(sp->st_ctime); --- 162 unchanged lines hidden (view full) --- 340 if (f_color && color_printed) 341 endcolor(0); 342#endif 343 if (f_type) 344 chcnt += printtype(sp->st_mode); 345 return (chcnt); 346} 347 |
348/* 349 * Print device special file major and minor numbers. 350 */ |
351static void |
352printdev(size_t width, dev_t dev) 353{ 354 char buf[DEVSTR_HEX_LEN + 1]; 355 356 if (minor(dev) > 255 || minor(dev) < 0) 357 (void)snprintf(buf, sizeof(buf), "%3d, 0x%08x", 358 major(dev), (u_int)minor(dev)); 359 else 360 (void)snprintf(buf, sizeof(buf), "%3d, %3d", 361 major(dev), minor(dev)); 362 363 (void)printf("%*s ", (u_int)width, buf); 364} 365 366static void |
367printtime(time_t ftime) 368{ 369 char longstring[80]; 370 static time_t now = 0; 371 const char *format; 372 static int d_first = -1; 373 374 if (d_first < 0) --- 222 unchanged lines hidden (view full) --- 597 (void)printname(path); 598} 599 600static void 601printsize(size_t width, off_t bytes) 602{ 603 604 if (f_humanval) { |
605 /* 606 * Reserve one space before the size and allocate room for 607 * the trailing '\0'. 608 */ 609 char buf[HUMANVALSTR_LEN - 1 + 1]; |
610 611 humanize_number(buf, sizeof(buf), (int64_t)bytes, "", 612 HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); |
613 (void)printf("%*s ", (u_int)width, buf); |
614 } else 615 (void)printf("%*jd ", (u_int)width, bytes); 616} 617 618/* 619 * Add a + after the standard rwxrwxrwx mode if the file has an 620 * ACL. strmode() reserves space at the end of the string. 621 */ --- 66 unchanged lines hidden --- |