Home | History | Annotate | Line # | Download | only in ls
print.c revision 1.54.2.1
      1  1.54.2.1       tls /*	$NetBSD: print.c,v 1.54.2.1 2014/08/10 06:41:18 tls Exp $	*/
      2      1.13       cgd 
      3       1.1       cgd /*
      4      1.11   mycroft  * Copyright (c) 1989, 1993, 1994
      5      1.11   mycroft  *	The Regents of the University of California.  All rights reserved.
      6       1.1       cgd  *
      7       1.1       cgd  * This code is derived from software contributed to Berkeley by
      8       1.1       cgd  * Michael Fischbein.
      9       1.1       cgd  *
     10       1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11       1.1       cgd  * modification, are permitted provided that the following conditions
     12       1.1       cgd  * are met:
     13       1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14       1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15       1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17       1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18      1.35       agc  * 3. Neither the name of the University nor the names of its contributors
     19       1.1       cgd  *    may be used to endorse or promote products derived from this software
     20       1.1       cgd  *    without specific prior written permission.
     21       1.1       cgd  *
     22       1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23       1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24       1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25       1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26       1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27       1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28       1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29       1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30       1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31       1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32       1.1       cgd  * SUCH DAMAGE.
     33       1.1       cgd  */
     34       1.1       cgd 
     35      1.16  christos #include <sys/cdefs.h>
     36       1.1       cgd #ifndef lint
     37      1.13       cgd #if 0
     38      1.14       jtc static char sccsid[] = "@(#)print.c	8.5 (Berkeley) 7/28/94";
     39      1.13       cgd #else
     40  1.54.2.1       tls __RCSID("$NetBSD: print.c,v 1.54.2.1 2014/08/10 06:41:18 tls Exp $");
     41      1.13       cgd #endif
     42       1.1       cgd #endif /* not lint */
     43       1.1       cgd 
     44       1.1       cgd #include <sys/param.h>
     45       1.1       cgd #include <sys/stat.h>
     46      1.11   mycroft 
     47      1.11   mycroft #include <err.h>
     48      1.11   mycroft #include <errno.h>
     49  1.54.2.1       tls #include <inttypes.h>
     50       1.5   mycroft #include <fts.h>
     51       1.1       cgd #include <grp.h>
     52       1.1       cgd #include <pwd.h>
     53      1.11   mycroft #include <stdio.h>
     54       1.5   mycroft #include <stdlib.h>
     55       1.5   mycroft #include <string.h>
     56      1.11   mycroft #include <time.h>
     57      1.11   mycroft #include <tzfile.h>
     58      1.11   mycroft #include <unistd.h>
     59      1.38     grant #include <util.h>
     60      1.11   mycroft 
     61       1.1       cgd #include "ls.h"
     62       1.5   mycroft #include "extern.h"
     63       1.1       cgd 
     64      1.31  christos extern int termwidth;
     65      1.31  christos 
     66      1.30     lukem static int	printaname(FTSENT *, int, int);
     67      1.30     lukem static void	printlink(FTSENT *);
     68      1.30     lukem static void	printtime(time_t);
     69      1.43     ahoka static void	printtotal(DISPLAY *dp);
     70      1.30     lukem static int	printtype(u_int);
     71       1.5   mycroft 
     72      1.20   mycroft static time_t	now;
     73      1.20   mycroft 
     74       1.5   mycroft #define	IS_NOPRINT(p)	((p)->fts_number == NO_PRINT)
     75       1.5   mycroft 
     76      1.53  christos static int
     77      1.53  christos safe_printpath(const FTSENT *p) {
     78      1.53  christos 	int chcnt;
     79      1.53  christos 
     80      1.53  christos 	if (f_fullpath) {
     81      1.53  christos 		chcnt = safe_print(p->fts_path);
     82      1.53  christos 		chcnt += safe_print("/");
     83      1.53  christos 	} else
     84      1.53  christos 		chcnt = 0;
     85      1.53  christos 	return chcnt + safe_print(p->fts_name);
     86      1.53  christos }
     87      1.53  christos 
     88      1.53  christos static int
     89      1.53  christos printescapedpath(const FTSENT *p) {
     90      1.53  christos 	int chcnt;
     91      1.53  christos 
     92      1.53  christos 	if (f_fullpath) {
     93      1.53  christos 		chcnt = printescaped(p->fts_path);
     94      1.53  christos 		chcnt += printescaped("/");
     95      1.53  christos 	} else
     96      1.53  christos 		chcnt = 0;
     97      1.53  christos 
     98      1.53  christos 	return chcnt + printescaped(p->fts_name);
     99      1.53  christos }
    100      1.53  christos 
    101      1.53  christos static int
    102      1.53  christos printpath(const FTSENT *p) {
    103      1.53  christos 	if (f_fullpath)
    104      1.53  christos 		return printf("%s/%s", p->fts_path, p->fts_name);
    105      1.53  christos 	else
    106      1.54   mlelstv 		return printf("%s", p->fts_name);
    107      1.53  christos }
    108      1.53  christos 
    109       1.5   mycroft void
    110      1.30     lukem printscol(DISPLAY *dp)
    111       1.1       cgd {
    112      1.11   mycroft 	FTSENT *p;
    113       1.5   mycroft 
    114       1.5   mycroft 	for (p = dp->list; p; p = p->fts_link) {
    115       1.5   mycroft 		if (IS_NOPRINT(p))
    116       1.5   mycroft 			continue;
    117       1.5   mycroft 		(void)printaname(p, dp->s_inode, dp->s_block);
    118       1.1       cgd 		(void)putchar('\n');
    119       1.1       cgd 	}
    120       1.1       cgd }
    121       1.1       cgd 
    122       1.5   mycroft void
    123      1.30     lukem printlong(DISPLAY *dp)
    124       1.5   mycroft {
    125      1.11   mycroft 	struct stat *sp;
    126      1.11   mycroft 	FTSENT *p;
    127       1.5   mycroft 	NAMES *np;
    128      1.38     grant 	char buf[20], szbuf[5];
    129       1.5   mycroft 
    130      1.22   mycroft 	now = time(NULL);
    131      1.20   mycroft 
    132      1.53  christos 	if (!f_leafonly)
    133      1.53  christos 		printtotal(dp);		/* "total: %u\n" */
    134      1.43     ahoka 
    135       1.5   mycroft 	for (p = dp->list; p; p = p->fts_link) {
    136       1.5   mycroft 		if (IS_NOPRINT(p))
    137       1.5   mycroft 			continue;
    138       1.5   mycroft 		sp = p->fts_statp;
    139       1.1       cgd 		if (f_inode)
    140  1.54.2.1       tls 			(void)printf("%*"PRIu64" ", dp->s_inode, sp->st_ino);
    141      1.41  jschauma 		if (f_size) {
    142      1.41  jschauma 			if (f_humanize) {
    143      1.41  jschauma 				if ((humanize_number(szbuf, sizeof(szbuf),
    144      1.48     enami 				    sp->st_blocks * S_BLKSIZE,
    145      1.48     enami 				    "", HN_AUTOSCALE,
    146      1.48     enami 				    (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
    147      1.48     enami 					err(1, "humanize_number");
    148      1.48     enami 				(void)printf("%*s ", dp->s_block, szbuf);
    149      1.41  jschauma 			} else {
    150      1.50  christos 				(void)printf(f_commas ? "%'*llu " : "%*llu ",
    151      1.50  christos 				    dp->s_block,
    152      1.50  christos 				    (unsigned long long)howmany(sp->st_blocks,
    153      1.48     enami 				    blocksize));
    154      1.41  jschauma 			}
    155      1.38     grant 		}
    156       1.5   mycroft 		(void)strmode(sp->st_mode, buf);
    157       1.5   mycroft 		np = p->fts_pointer;
    158      1.34     grant 		(void)printf("%s %*lu ", buf, dp->s_nlink,
    159      1.34     grant 		    (unsigned long)sp->st_nlink);
    160      1.34     grant 		if (!f_grouponly)
    161      1.34     grant 			(void)printf("%-*s  ", dp->s_user, np->user);
    162      1.34     grant 		(void)printf("%-*s  ", dp->s_group, np->group);
    163       1.5   mycroft 		if (f_flags)
    164       1.5   mycroft 			(void)printf("%-*s ", dp->s_flags, np->flags);
    165       1.5   mycroft 		if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
    166      1.44  christos 			(void)printf("%*lld, %*lld ",
    167      1.44  christos 			    dp->s_major, (long long)major(sp->st_rdev),
    168      1.44  christos 			    dp->s_minor, (long long)minor(sp->st_rdev));
    169       1.1       cgd 		else
    170      1.38     grant 			if (f_humanize) {
    171      1.38     grant 				if ((humanize_number(szbuf, sizeof(szbuf),
    172      1.38     grant 				    sp->st_size, "", HN_AUTOSCALE,
    173      1.38     grant 				    (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
    174      1.38     grant 					err(1, "humanize_number");
    175      1.38     grant 				(void)printf("%*s ", dp->s_size, szbuf);
    176      1.38     grant 			} else {
    177      1.50  christos 				(void)printf(f_commas ? "%'*llu " : "%*llu ",
    178      1.50  christos 				    dp->s_size, (unsigned long long)
    179      1.50  christos 				    sp->st_size);
    180      1.38     grant 			}
    181       1.1       cgd 		if (f_accesstime)
    182       1.5   mycroft 			printtime(sp->st_atime);
    183       1.1       cgd 		else if (f_statustime)
    184       1.5   mycroft 			printtime(sp->st_ctime);
    185       1.1       cgd 		else
    186       1.5   mycroft 			printtime(sp->st_mtime);
    187      1.37  jschauma 		if (f_octal || f_octal_escape)
    188      1.53  christos 			(void)safe_printpath(p);
    189      1.36  jschauma 		else if (f_nonprint)
    190      1.53  christos 			(void)printescapedpath(p);
    191      1.28     assar 		else
    192      1.53  christos 			(void)printpath(p);
    193      1.28     assar 
    194      1.26    kleink 		if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
    195       1.5   mycroft 			(void)printtype(sp->st_mode);
    196       1.5   mycroft 		if (S_ISLNK(sp->st_mode))
    197       1.5   mycroft 			printlink(p);
    198       1.1       cgd 		(void)putchar('\n');
    199       1.1       cgd 	}
    200       1.1       cgd }
    201       1.1       cgd 
    202       1.5   mycroft void
    203      1.30     lukem printcol(DISPLAY *dp)
    204       1.1       cgd {
    205       1.5   mycroft 	static FTSENT **array;
    206       1.5   mycroft 	static int lastentries = -1;
    207      1.11   mycroft 	FTSENT *p;
    208      1.16  christos 	int base, chcnt, col, colwidth, num;
    209      1.15   thorpej 	int numcols, numrows, row;
    210       1.1       cgd 
    211      1.19     lukem 	colwidth = dp->maxlen;
    212      1.19     lukem 	if (f_inode)
    213      1.19     lukem 		colwidth += dp->s_inode + 1;
    214      1.38     grant 	if (f_size) {
    215      1.38     grant 		if (f_humanize)
    216      1.38     grant 			colwidth += dp->s_size + 1;
    217      1.38     grant 		else
    218      1.38     grant 			colwidth += dp->s_block + 1;
    219      1.38     grant 	}
    220      1.26    kleink 	if (f_type || f_typedir)
    221      1.19     lukem 		colwidth += 1;
    222      1.19     lukem 
    223      1.19     lukem 	colwidth += 1;
    224      1.19     lukem 
    225      1.19     lukem 	if (termwidth < 2 * colwidth) {
    226      1.19     lukem 		printscol(dp);
    227      1.19     lukem 		return;
    228      1.19     lukem 	}
    229      1.19     lukem 
    230       1.5   mycroft 	/*
    231       1.5   mycroft 	 * Have to do random access in the linked list -- build a table
    232       1.5   mycroft 	 * of pointers.
    233       1.5   mycroft 	 */
    234       1.5   mycroft 	if (dp->entries > lastentries) {
    235      1.51      yamt 		FTSENT **newarray;
    236      1.51      yamt 
    237      1.51      yamt 		newarray = realloc(array, dp->entries * sizeof(FTSENT *));
    238      1.51      yamt 		if (newarray == NULL) {
    239      1.27  drochner 			warn(NULL);
    240       1.5   mycroft 			printscol(dp);
    241      1.51      yamt 			return;
    242       1.5   mycroft 		}
    243      1.51      yamt 		lastentries = dp->entries;
    244      1.51      yamt 		array = newarray;
    245       1.5   mycroft 	}
    246       1.5   mycroft 	for (p = dp->list, num = 0; p; p = p->fts_link)
    247       1.5   mycroft 		if (p->fts_number != NO_PRINT)
    248       1.5   mycroft 			array[num++] = p;
    249       1.5   mycroft 
    250      1.19     lukem 	numcols = termwidth / colwidth;
    251      1.19     lukem 	colwidth = termwidth / numcols;		/* spread out if possible */
    252      1.19     lukem 	numrows = num / numcols;
    253      1.19     lukem 	if (num % numcols)
    254      1.19     lukem 		++numrows;
    255      1.19     lukem 
    256      1.43     ahoka 	printtotal(dp);				/* "total: %u\n" */
    257      1.43     ahoka 
    258      1.19     lukem 	for (row = 0; row < numrows; ++row) {
    259      1.19     lukem 		for (base = row, chcnt = col = 0; col < numcols; ++col) {
    260      1.19     lukem 			chcnt = printaname(array[base], dp->s_inode,
    261      1.38     grant 			    f_humanize ? dp->s_size : dp->s_block);
    262      1.19     lukem 			if ((base += numrows) >= num)
    263      1.19     lukem 				break;
    264      1.19     lukem 			while (chcnt++ < colwidth)
    265      1.22   mycroft 				(void)putchar(' ');
    266      1.19     lukem 		}
    267      1.19     lukem 		(void)putchar('\n');
    268      1.19     lukem 	}
    269      1.19     lukem }
    270      1.19     lukem 
    271      1.19     lukem void
    272      1.30     lukem printacol(DISPLAY *dp)
    273      1.19     lukem {
    274      1.19     lukem 	FTSENT *p;
    275      1.19     lukem 	int chcnt, col, colwidth;
    276      1.19     lukem 	int numcols;
    277      1.19     lukem 
    278       1.5   mycroft 	colwidth = dp->maxlen;
    279       1.1       cgd 	if (f_inode)
    280       1.5   mycroft 		colwidth += dp->s_inode + 1;
    281      1.38     grant 	if (f_size) {
    282      1.38     grant 		if (f_humanize)
    283      1.38     grant 			colwidth += dp->s_size + 1;
    284      1.38     grant 		else
    285      1.38     grant 			colwidth += dp->s_block + 1;
    286      1.38     grant 	}
    287      1.26    kleink 	if (f_type || f_typedir)
    288       1.1       cgd 		colwidth += 1;
    289       1.1       cgd 
    290      1.15   thorpej 	colwidth += 1;
    291      1.15   thorpej 
    292       1.1       cgd 	if (termwidth < 2 * colwidth) {
    293       1.5   mycroft 		printscol(dp);
    294       1.1       cgd 		return;
    295       1.1       cgd 	}
    296       1.1       cgd 
    297       1.1       cgd 	numcols = termwidth / colwidth;
    298      1.15   thorpej 	colwidth = termwidth / numcols;		/* spread out if possible */
    299       1.1       cgd 
    300      1.43     ahoka 	printtotal(dp);				/* "total: %u\n" */
    301      1.43     ahoka 
    302      1.19     lukem 	chcnt = col = 0;
    303      1.19     lukem 	for (p = dp->list; p; p = p->fts_link) {
    304      1.19     lukem 		if (IS_NOPRINT(p))
    305      1.19     lukem 			continue;
    306      1.19     lukem 		if (col >= numcols) {
    307      1.19     lukem 			chcnt = col = 0;
    308      1.22   mycroft 			(void)putchar('\n');
    309       1.1       cgd 		}
    310      1.38     grant 		chcnt = printaname(p, dp->s_inode,
    311      1.38     grant 		    f_humanize ? dp->s_size : dp->s_block);
    312      1.19     lukem 		while (chcnt++ < colwidth)
    313      1.22   mycroft 			(void)putchar(' ');
    314      1.19     lukem 		col++;
    315      1.25    kleink 	}
    316      1.25    kleink 	(void)putchar('\n');
    317      1.25    kleink }
    318      1.25    kleink 
    319      1.25    kleink void
    320      1.30     lukem printstream(DISPLAY *dp)
    321      1.25    kleink {
    322      1.25    kleink 	FTSENT *p;
    323      1.25    kleink 	int col;
    324      1.25    kleink 	int extwidth;
    325      1.25    kleink 
    326      1.25    kleink 	extwidth = 0;
    327      1.25    kleink 	if (f_inode)
    328      1.25    kleink 		extwidth += dp->s_inode + 1;
    329      1.38     grant 	if (f_size) {
    330      1.38     grant 		if (f_humanize)
    331      1.38     grant 			extwidth += dp->s_size + 1;
    332      1.38     grant 		else
    333      1.38     grant 			extwidth += dp->s_block + 1;
    334      1.38     grant 	}
    335      1.25    kleink 	if (f_type)
    336      1.25    kleink 		extwidth += 1;
    337      1.25    kleink 
    338      1.25    kleink 	for (col = 0, p = dp->list; p != NULL; p = p->fts_link) {
    339      1.25    kleink 		if (IS_NOPRINT(p))
    340      1.25    kleink 			continue;
    341      1.25    kleink 		if (col > 0) {
    342      1.25    kleink 			(void)putchar(','), col++;
    343      1.45     lukem 			if (col + 1 + extwidth + (int)p->fts_namelen >= termwidth)
    344      1.25    kleink 				(void)putchar('\n'), col = 0;
    345      1.25    kleink 			else
    346      1.25    kleink 				(void)putchar(' '), col++;
    347      1.25    kleink 		}
    348      1.38     grant 		col += printaname(p, dp->s_inode,
    349      1.38     grant 		    f_humanize ? dp->s_size : dp->s_block);
    350       1.1       cgd 	}
    351      1.22   mycroft 	(void)putchar('\n');
    352       1.1       cgd }
    353       1.1       cgd 
    354       1.1       cgd /*
    355       1.1       cgd  * print [inode] [size] name
    356       1.5   mycroft  * return # of characters printed, no trailing characters.
    357       1.1       cgd  */
    358       1.5   mycroft static int
    359      1.30     lukem printaname(FTSENT *p, int inodefield, int sizefield)
    360       1.1       cgd {
    361       1.5   mycroft 	struct stat *sp;
    362       1.1       cgd 	int chcnt;
    363      1.38     grant 	char szbuf[5];
    364       1.1       cgd 
    365       1.5   mycroft 	sp = p->fts_statp;
    366       1.1       cgd 	chcnt = 0;
    367       1.1       cgd 	if (f_inode)
    368  1.54.2.1       tls 		chcnt += printf("%*"PRIu64" ", inodefield, sp->st_ino);
    369      1.38     grant 	if (f_size) {
    370      1.38     grant 		if (f_humanize) {
    371      1.38     grant 			if ((humanize_number(szbuf, sizeof(szbuf), sp->st_size,
    372      1.38     grant 			    "", HN_AUTOSCALE,
    373      1.38     grant 			    (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
    374      1.38     grant 				err(1, "humanize_number");
    375      1.38     grant 			chcnt += printf("%*s ", sizefield, szbuf);
    376      1.38     grant 		} else {
    377      1.50  christos 			chcnt += printf(f_commas ? "%'*llu " : "%*llu ",
    378      1.50  christos 			    sizefield, (unsigned long long)
    379      1.50  christos 			    howmany(sp->st_blocks, blocksize));
    380      1.38     grant 		}
    381      1.38     grant 	}
    382      1.37  jschauma 	if (f_octal || f_octal_escape)
    383      1.53  christos 		chcnt += safe_printpath(p);
    384      1.36  jschauma 	else if (f_nonprint)
    385      1.53  christos 		chcnt += printescapedpath(p);
    386      1.29     assar 	else
    387      1.53  christos 		chcnt += printpath(p);
    388      1.26    kleink 	if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
    389       1.5   mycroft 		chcnt += printtype(sp->st_mode);
    390       1.5   mycroft 	return (chcnt);
    391       1.1       cgd }
    392       1.1       cgd 
    393       1.5   mycroft static void
    394      1.30     lukem printtime(time_t ftime)
    395       1.1       cgd {
    396       1.1       cgd 	int i;
    397      1.46  christos 	const char *longstring;
    398       1.1       cgd 
    399      1.47  christos 	if ((longstring = ctime(&ftime)) == NULL) {
    400      1.46  christos 			   /* 012345678901234567890123 */
    401      1.46  christos 		longstring = "????????????????????????";
    402      1.46  christos 	}
    403       1.1       cgd 	for (i = 4; i < 11; ++i)
    404       1.1       cgd 		(void)putchar(longstring[i]);
    405       1.1       cgd 
    406       1.1       cgd #define	SIXMONTHS	((DAYSPERNYEAR / 2) * SECSPERDAY)
    407       1.1       cgd 	if (f_sectime)
    408       1.1       cgd 		for (i = 11; i < 24; i++)
    409       1.1       cgd 			(void)putchar(longstring[i]);
    410      1.40   mycroft 	else if (ftime + SIXMONTHS > now && ftime - SIXMONTHS < now)
    411       1.1       cgd 		for (i = 11; i < 16; ++i)
    412       1.1       cgd 			(void)putchar(longstring[i]);
    413       1.1       cgd 	else {
    414       1.1       cgd 		(void)putchar(' ');
    415       1.1       cgd 		for (i = 20; i < 24; ++i)
    416       1.1       cgd 			(void)putchar(longstring[i]);
    417       1.1       cgd 	}
    418       1.1       cgd 	(void)putchar(' ');
    419       1.1       cgd }
    420       1.1       cgd 
    421      1.43     ahoka /*
    422      1.43     ahoka  * Display total used disk space in the form "total: %u\n".
    423      1.43     ahoka  * Note: POSIX (IEEE Std 1003.1-2001) says this should be always in 512 blocks,
    424      1.49       erh  * but we humanise it with -h, or separate it with commas with -M, and use 1024
    425      1.49       erh  * with -k.
    426      1.43     ahoka  */
    427      1.43     ahoka static void
    428      1.43     ahoka printtotal(DISPLAY *dp)
    429      1.43     ahoka {
    430      1.43     ahoka 	char szbuf[5];
    431      1.43     ahoka 
    432      1.43     ahoka 	if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) {
    433      1.43     ahoka 		if (f_humanize) {
    434      1.43     ahoka 			if ((humanize_number(szbuf, sizeof(szbuf), (int64_t)dp->stotal,
    435      1.43     ahoka 			    "", HN_AUTOSCALE,
    436      1.43     ahoka 			    (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
    437      1.43     ahoka 				err(1, "humanize_number");
    438      1.43     ahoka 			(void)printf("total %s\n", szbuf);
    439      1.43     ahoka 		} else {
    440      1.50  christos 			(void)printf(f_commas ? "total %'llu\n" :
    441      1.50  christos 			    "total %llu\n", (unsigned long long)
    442      1.50  christos 			    howmany(dp->btotal, blocksize));
    443      1.43     ahoka 		}
    444      1.43     ahoka 	}
    445      1.43     ahoka }
    446      1.43     ahoka 
    447       1.5   mycroft static int
    448      1.30     lukem printtype(u_int mode)
    449       1.1       cgd {
    450      1.11   mycroft 	switch (mode & S_IFMT) {
    451       1.1       cgd 	case S_IFDIR:
    452       1.1       cgd 		(void)putchar('/');
    453       1.5   mycroft 		return (1);
    454      1.11   mycroft 	case S_IFIFO:
    455      1.11   mycroft 		(void)putchar('|');
    456      1.11   mycroft 		return (1);
    457       1.1       cgd 	case S_IFLNK:
    458       1.1       cgd 		(void)putchar('@');
    459       1.5   mycroft 		return (1);
    460       1.1       cgd 	case S_IFSOCK:
    461       1.1       cgd 		(void)putchar('=');
    462      1.12   mycroft 		return (1);
    463      1.12   mycroft 	case S_IFWHT:
    464      1.12   mycroft 		(void)putchar('%');
    465       1.6       jtc 		return (1);
    466       1.1       cgd 	}
    467       1.1       cgd 	if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
    468       1.1       cgd 		(void)putchar('*');
    469       1.5   mycroft 		return (1);
    470       1.1       cgd 	}
    471       1.5   mycroft 	return (0);
    472       1.1       cgd }
    473       1.1       cgd 
    474       1.5   mycroft static void
    475      1.30     lukem printlink(FTSENT *p)
    476       1.1       cgd {
    477       1.1       cgd 	int lnklen;
    478       1.5   mycroft 	char name[MAXPATHLEN + 1], path[MAXPATHLEN + 1];
    479       1.5   mycroft 
    480       1.5   mycroft 	if (p->fts_level == FTS_ROOTLEVEL)
    481       1.5   mycroft 		(void)snprintf(name, sizeof(name), "%s", p->fts_name);
    482      1.33     enami 	else
    483      1.11   mycroft 		(void)snprintf(name, sizeof(name),
    484      1.11   mycroft 		    "%s/%s", p->fts_parent->fts_accpath, p->fts_name);
    485      1.11   mycroft 	if ((lnklen = readlink(name, path, sizeof(path) - 1)) == -1) {
    486       1.1       cgd 		(void)fprintf(stderr, "\nls: %s: %s\n", name, strerror(errno));
    487       1.1       cgd 		return;
    488       1.1       cgd 	}
    489       1.1       cgd 	path[lnklen] = '\0';
    490      1.28     assar 	(void)printf(" -> ");
    491      1.37  jschauma 	if (f_octal || f_octal_escape)
    492      1.36  jschauma 		(void)safe_print(path);
    493      1.36  jschauma 	else if (f_nonprint)
    494      1.36  jschauma 		(void)printescaped(path);
    495      1.28     assar 	else
    496      1.28     assar 		(void)printf("%s", path);
    497       1.1       cgd }
    498