diff options
| author | Seb <sbb@tuxfamily.org> | 2010-06-12 21:57:50 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-12 21:57:50 +0200 |
| commit | d2d327db6d38d5a6e8e253c54d3e97466ce3bc79 (patch) | |
| tree | 38dbae3f18cedd293307a7389d22372d7601e047 | |
| parent | e2b41cfb4be2486d9f2d50a8d750eed15c29320e (diff) | |
| download | busybox-w32-d2d327db6d38d5a6e8e253c54d3e97466ce3bc79.tar.gz busybox-w32-d2d327db6d38d5a6e8e253c54d3e97466ce3bc79.tar.bz2 busybox-w32-d2d327db6d38d5a6e8e253c54d3e97466ce3bc79.zip | |
stat: make output more similar to GNU stat
Signed-off-by: Seb <sbb@tuxfamily.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | coreutils/stat.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/coreutils/stat.c b/coreutils/stat.c index 57f1f145a..e7c24e642 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
| @@ -216,10 +216,7 @@ static void FAST_FUNC print_stat(char *pformat, const char m, | |||
| 216 | char *linkname = xmalloc_readlink_or_warn(filename); | 216 | char *linkname = xmalloc_readlink_or_warn(filename); |
| 217 | if (linkname == NULL) | 217 | if (linkname == NULL) |
| 218 | return; | 218 | return; |
| 219 | /*printf("\"%s\" -> \"%s\"", filename, linkname); */ | 219 | printf("'%s' -> '%s'", filename, linkname); |
| 220 | printf(pformat, filename); | ||
| 221 | printf(" -> "); | ||
| 222 | printf(pformat, linkname); | ||
| 223 | free(linkname); | 220 | free(linkname); |
| 224 | } else { | 221 | } else { |
| 225 | printf(pformat, filename); | 222 | printf(pformat, filename); |
| @@ -320,24 +317,28 @@ static void print_it(const char *masterformat, | |||
| 320 | 317 | ||
| 321 | b = format; | 318 | b = format; |
| 322 | while (b) { | 319 | while (b) { |
| 320 | /* Each iteration finds next %spec, | ||
| 321 | * prints preceding string and handles found %spec | ||
| 322 | */ | ||
| 323 | size_t len; | 323 | size_t len; |
| 324 | char *p = strchr(b, '%'); | 324 | char *p = strchr(b, '%'); |
| 325 | if (!p) { | 325 | if (!p) { |
| 326 | /* coreutils 6.3 always prints <cr> at the end */ | 326 | /* coreutils 6.3 always prints newline at the end */ |
| 327 | /*fputs(b, stdout);*/ | 327 | /*fputs(b, stdout);*/ |
| 328 | puts(b); | 328 | puts(b); |
| 329 | break; | 329 | break; |
| 330 | } | 330 | } |
| 331 | *p++ = '\0'; | ||
| 332 | fputs(b, stdout); | ||
| 333 | 331 | ||
| 334 | /* dest = "%<modifiers>" */ | 332 | /* dest = "%<modifiers>" */ |
| 335 | len = strspn(p, "#-+.I 0123456789"); | 333 | len = 1 + strspn(p + 1, "#-+.I 0123456789"); |
| 336 | dest[0] = '%'; | 334 | memcpy(dest, p, len); |
| 337 | memcpy(dest + 1, p, len); | 335 | dest[len] = '\0'; |
| 338 | dest[1 + len] = '\0'; | ||
| 339 | p += len; | ||
| 340 | 336 | ||
| 337 | /* print preceding string */ | ||
| 338 | *p = '\0'; | ||
| 339 | fputs(b, stdout); | ||
| 340 | |||
| 341 | p += len; | ||
| 341 | b = p + 1; | 342 | b = p + 1; |
| 342 | switch (*p) { | 343 | switch (*p) { |
| 343 | case '\0': | 344 | case '\0': |
| @@ -508,7 +509,7 @@ static bool do_stat(const char *filename, const char *format) | |||
| 508 | } else { | 509 | } else { |
| 509 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { | 510 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { |
| 510 | format = | 511 | format = |
| 511 | " File: \"%N\"\n" | 512 | " File: %N\n" |
| 512 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" | 513 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 513 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" | 514 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" |
| 514 | " Device type: %t,%T\n" | 515 | " Device type: %t,%T\n" |
| @@ -516,7 +517,7 @@ static bool do_stat(const char *filename, const char *format) | |||
| 516 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"; | 517 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"; |
| 517 | } else { | 518 | } else { |
| 518 | format = | 519 | format = |
| 519 | " File: \"%N\"\n" | 520 | " File: %N\n" |
| 520 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" | 521 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 521 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" | 522 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" |
| 522 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" | 523 | "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) | |||
| 531 | } else { | 532 | } else { |
| 532 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { | 533 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { |
| 533 | format = (option_mask32 & OPT_SELINUX ? | 534 | format = (option_mask32 & OPT_SELINUX ? |
| 534 | " File: \"%N\"\n" | 535 | " File: %N\n" |
| 535 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" | 536 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 536 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" | 537 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" |
| 537 | " Device type: %t,%T\n" | 538 | " Device type: %t,%T\n" |
| 538 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" | 539 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 539 | " S_Context: %C\n" | 540 | " S_Context: %C\n" |
| 540 | "Access: %x\n" "Modify: %y\n" "Change: %z\n": | 541 | "Access: %x\n" "Modify: %y\n" "Change: %z\n": |
| 541 | " File: \"%N\"\n" | 542 | " File: %N\n" |
| 542 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" | 543 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 543 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" | 544 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" |
| 544 | " Device type: %t,%T\n" | 545 | " Device type: %t,%T\n" |
| @@ -546,13 +547,13 @@ static bool do_stat(const char *filename, const char *format) | |||
| 546 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"); | 547 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"); |
| 547 | } else { | 548 | } else { |
| 548 | format = (option_mask32 & OPT_SELINUX ? | 549 | format = (option_mask32 & OPT_SELINUX ? |
| 549 | " File: \"%N\"\n" | 550 | " File: %N\n" |
| 550 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" | 551 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 551 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" | 552 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" |
| 552 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" | 553 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 553 | "S_Context: %C\n" | 554 | "S_Context: %C\n" |
| 554 | "Access: %x\n" "Modify: %y\n" "Change: %z\n": | 555 | "Access: %x\n" "Modify: %y\n" "Change: %z\n": |
| 555 | " File: \"%N\"\n" | 556 | " File: %N\n" |
| 556 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" | 557 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 557 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" | 558 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" |
| 558 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" | 559 | "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) | |||
| 601 | if (S_ISLNK(statbuf.st_mode)) | 602 | if (S_ISLNK(statbuf.st_mode)) |
| 602 | linkname = xmalloc_readlink_or_warn(filename); | 603 | linkname = xmalloc_readlink_or_warn(filename); |
| 603 | if (linkname) | 604 | if (linkname) |
| 604 | printf(" File: \"%s\" -> \"%s\"\n", filename, linkname); | 605 | printf(" File: '%s' -> '%s'\n", filename, linkname); |
| 605 | else | 606 | else |
| 606 | printf(" File: \"%s\"\n", filename); | 607 | printf(" File: '%s'\n", filename); |
| 607 | 608 | ||
| 608 | printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" | 609 | printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" |
| 609 | "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", | 610 | "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", |
