stat: make output more similar to GNU stat
Signed-off-by: Seb <sbb@tuxfamily.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
e2b41cfb4b
commit
d2d327db6d
@ -216,10 +216,7 @@ static void FAST_FUNC print_stat(char *pformat, const char m,
|
|||||||
char *linkname = xmalloc_readlink_or_warn(filename);
|
char *linkname = xmalloc_readlink_or_warn(filename);
|
||||||
if (linkname == NULL)
|
if (linkname == NULL)
|
||||||
return;
|
return;
|
||||||
/*printf("\"%s\" -> \"%s\"", filename, linkname); */
|
printf("'%s' -> '%s'", filename, linkname);
|
||||||
printf(pformat, filename);
|
|
||||||
printf(" -> ");
|
|
||||||
printf(pformat, linkname);
|
|
||||||
free(linkname);
|
free(linkname);
|
||||||
} else {
|
} else {
|
||||||
printf(pformat, filename);
|
printf(pformat, filename);
|
||||||
@ -320,24 +317,28 @@ static void print_it(const char *masterformat,
|
|||||||
|
|
||||||
b = format;
|
b = format;
|
||||||
while (b) {
|
while (b) {
|
||||||
|
/* Each iteration finds next %spec,
|
||||||
|
* prints preceding string and handles found %spec
|
||||||
|
*/
|
||||||
size_t len;
|
size_t len;
|
||||||
char *p = strchr(b, '%');
|
char *p = strchr(b, '%');
|
||||||
if (!p) {
|
if (!p) {
|
||||||
/* coreutils 6.3 always prints <cr> at the end */
|
/* coreutils 6.3 always prints newline at the end */
|
||||||
/*fputs(b, stdout);*/
|
/*fputs(b, stdout);*/
|
||||||
puts(b);
|
puts(b);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*p++ = '\0';
|
|
||||||
fputs(b, stdout);
|
|
||||||
|
|
||||||
/* dest = "%<modifiers>" */
|
/* dest = "%<modifiers>" */
|
||||||
len = strspn(p, "#-+.I 0123456789");
|
len = 1 + strspn(p + 1, "#-+.I 0123456789");
|
||||||
dest[0] = '%';
|
memcpy(dest, p, len);
|
||||||
memcpy(dest + 1, p, len);
|
dest[len] = '\0';
|
||||||
dest[1 + len] = '\0';
|
|
||||||
p += len;
|
|
||||||
|
|
||||||
|
/* print preceding string */
|
||||||
|
*p = '\0';
|
||||||
|
fputs(b, stdout);
|
||||||
|
|
||||||
|
p += len;
|
||||||
b = p + 1;
|
b = p + 1;
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '\0':
|
case '\0':
|
||||||
@ -508,7 +509,7 @@ static bool do_stat(const char *filename, const char *format)
|
|||||||
} else {
|
} else {
|
||||||
if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
|
if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
|
||||||
format =
|
format =
|
||||||
" File: \"%N\"\n"
|
" File: %N\n"
|
||||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||||
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
|
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
|
||||||
" Device type: %t,%T\n"
|
" Device type: %t,%T\n"
|
||||||
@ -516,7 +517,7 @@ static bool do_stat(const char *filename, const char *format)
|
|||||||
"Access: %x\n" "Modify: %y\n" "Change: %z\n";
|
"Access: %x\n" "Modify: %y\n" "Change: %z\n";
|
||||||
} else {
|
} else {
|
||||||
format =
|
format =
|
||||||
" File: \"%N\"\n"
|
" File: %N\n"
|
||||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||||
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
|
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
|
||||||
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
||||||
@ -531,14 +532,14 @@ static bool do_stat(const char *filename, const char *format)
|
|||||||
} else {
|
} else {
|
||||||
if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
|
if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
|
||||||
format = (option_mask32 & OPT_SELINUX ?
|
format = (option_mask32 & OPT_SELINUX ?
|
||||||
" File: \"%N\"\n"
|
" File: %N\n"
|
||||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||||
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
|
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
|
||||||
" Device type: %t,%T\n"
|
" Device type: %t,%T\n"
|
||||||
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
||||||
" S_Context: %C\n"
|
" S_Context: %C\n"
|
||||||
"Access: %x\n" "Modify: %y\n" "Change: %z\n":
|
"Access: %x\n" "Modify: %y\n" "Change: %z\n":
|
||||||
" File: \"%N\"\n"
|
" File: %N\n"
|
||||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||||
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
|
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
|
||||||
" Device type: %t,%T\n"
|
" Device type: %t,%T\n"
|
||||||
@ -546,13 +547,13 @@ static bool do_stat(const char *filename, const char *format)
|
|||||||
"Access: %x\n" "Modify: %y\n" "Change: %z\n");
|
"Access: %x\n" "Modify: %y\n" "Change: %z\n");
|
||||||
} else {
|
} else {
|
||||||
format = (option_mask32 & OPT_SELINUX ?
|
format = (option_mask32 & OPT_SELINUX ?
|
||||||
" File: \"%N\"\n"
|
" File: %N\n"
|
||||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||||
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
|
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
|
||||||
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
||||||
"S_Context: %C\n"
|
"S_Context: %C\n"
|
||||||
"Access: %x\n" "Modify: %y\n" "Change: %z\n":
|
"Access: %x\n" "Modify: %y\n" "Change: %z\n":
|
||||||
" File: \"%N\"\n"
|
" File: %N\n"
|
||||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||||
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
|
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
|
||||||
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
||||||
@ -601,9 +602,9 @@ static bool do_stat(const char *filename, const char *format)
|
|||||||
if (S_ISLNK(statbuf.st_mode))
|
if (S_ISLNK(statbuf.st_mode))
|
||||||
linkname = xmalloc_readlink_or_warn(filename);
|
linkname = xmalloc_readlink_or_warn(filename);
|
||||||
if (linkname)
|
if (linkname)
|
||||||
printf(" File: \"%s\" -> \"%s\"\n", filename, linkname);
|
printf(" File: '%s' -> '%s'\n", filename, linkname);
|
||||||
else
|
else
|
||||||
printf(" File: \"%s\"\n", filename);
|
printf(" File: '%s'\n", filename);
|
||||||
|
|
||||||
printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n"
|
printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n"
|
||||||
"Device: %llxh/%llud\tInode: %-10llu Links: %-5lu",
|
"Device: %llxh/%llud\tInode: %-10llu Links: %-5lu",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user