1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
25 * AT&T Bell Laboratories
41 * buf results placed here
45 * link link text if != 0
48 * return end of formatted buf
52 fmtls(char* buf
, const char* name
, register struct stat
* st
, const char* info
, const char* link
, register int flags
)
59 if (flags
& LS_INUMBER
)
60 s
+= sfsprintf(s
, LS_W_MAX
, "%*I*u ", LS_W_INUMBER
- 1, sizeof(st
->st_ino
), st
->st_ino
);
61 if (flags
& LS_BLOCKS
)
64 s
+= sfsprintf(s
, LS_W_MAX
, "%*I*u ", LS_W_BLOCKS
- 1, sizeof(n
), n
);
68 s
+= sfsprintf(s
, LS_W_MAX
, "%s%3u", fmtmode(st
->st_mode
, flags
& LS_EXTERNAL
), (unsigned int)st
->st_nlink
);
69 if (!(flags
& LS_NOUSER
))
71 if (flags
& LS_NUMBER
)
72 s
+= sfsprintf(s
, LS_W_MAX
, " %-*I*d", LS_W_NAME
- 1, sizeof(st
->st_uid
), st
->st_uid
);
74 s
+= sfsprintf(s
, LS_W_MAX
, " %-*s", LS_W_NAME
- 1, fmtuid(st
->st_uid
));
76 if (!(flags
& LS_NOGROUP
))
78 if (flags
& LS_NUMBER
)
79 s
+= sfsprintf(s
, LS_W_MAX
, " %-*I*d", LS_W_NAME
- 1, sizeof(st
->st_gid
), st
->st_gid
);
81 s
+= sfsprintf(s
, LS_W_MAX
, " %-*s", LS_W_NAME
- 1, fmtgid(st
->st_gid
));
83 if (S_ISBLK(st
->st_mode
) || S_ISCHR(st
->st_mode
))
84 s
+= sfsprintf(s
, LS_W_MAX
, "%8s ", fmtdev(st
));
86 s
+= sfsprintf(s
, LS_W_MAX
, "%8I*u ", sizeof(st
->st_size
), st
->st_size
);
87 tm
= (flags
& LS_ATIME
) ? st
->st_atime
: (flags
& LS_CTIME
) ? st
->st_ctime
: st
->st_mtime
;
88 s
= tmfmt(s
, LS_W_LONG
/ 2, "%?%l", &tm
);
101 if (S_ISDIR(st
->st_mode
))
104 else if (S_ISLNK(st
->st_mode
))
107 else if (st
->st_mode
& (S_IXUSR
|S_IXGRP
|S_IXOTH
))
112 s
+= sfsprintf(s
, LS_W_MAX
, " %s %s",
114 S_ISLNK(st
->st_mode
) ? "->" :