aboutsummaryrefslogtreecommitdiff
path: root/coreutils/stat.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-08-16 09:42:39 +0100
committerRon Yorston <rmy@pobox.com>2019-08-16 09:45:21 +0100
commit517cf74f6265ec4308b790b637b3f9778cbdc6e0 (patch)
treebe9337069b60ca1bb03565d8575bacfc71181003 /coreutils/stat.c
parentae65dc37bcc9b1d9cef0b111131c79dc4ba1bf51 (diff)
parentac78f2ac96b3efd6551a08e7dc609efa1fb69481 (diff)
downloadbusybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.tar.gz
busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.tar.bz2
busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils/stat.c')
-rw-r--r--coreutils/stat.c75
1 files changed, 36 insertions, 39 deletions
diff --git a/coreutils/stat.c b/coreutils/stat.c
index d9287b34e..c332e5dc8 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -149,20 +149,16 @@ static const char *file_type(const struct stat *st)
149 return "weird file"; 149 return "weird file";
150} 150}
151 151
152static const char *human_time(time_t t) 152static const char *human_time(struct timespec *ts)
153{ 153{
154 /* Old 154 char fmt[sizeof("%Y-%m-%d %H:%M:%S.123456789 %z") + /*paranoia*/ 8];
155 static char *str; 155
156 str = ctime(&t); 156 /* coreutils 6.3 compat */
157 str[strlen(str)-1] = '\0';
158 return str;
159 */
160 /* coreutils 6.3 compat: */
161
162 /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
163#define buf bb_common_bufsiz1 157#define buf bb_common_bufsiz1
164 setup_common_bufsiz(); 158 setup_common_bufsiz();
165 strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000"); 159
160 sprintf(stpcpy(fmt, "%Y-%m-%d %H:%M:%S"), ".%09u %%z", (unsigned)ts->tv_nsec);
161 strftime(buf, COMMON_BUFSIZE, fmt, localtime(&ts->tv_sec));
166 return buf; 162 return buf;
167#undef buf 163#undef buf
168} 164}
@@ -388,19 +384,19 @@ static void FAST_FUNC print_stat(char *pformat, const char m,
388 strcat(pformat, "lu"); 384 strcat(pformat, "lu");
389 printf(pformat, (unsigned long) statbuf->st_blksize); 385 printf(pformat, (unsigned long) statbuf->st_blksize);
390 } else if (m == 'x') { 386 } else if (m == 'x') {
391 printfs(pformat, human_time(statbuf->st_atime)); 387 printfs(pformat, human_time(&statbuf->st_atim));
392 } else if (m == 'X') { 388 } else if (m == 'X') {
393 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); 389 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
394 /* note: (unsigned long) would be wrong: 390 /* note: (unsigned long) would be wrong:
395 * imagine (unsigned long64)int32 */ 391 * imagine (unsigned long64)int32 */
396 printf(pformat, (long) statbuf->st_atime); 392 printf(pformat, (long) statbuf->st_atime);
397 } else if (m == 'y') { 393 } else if (m == 'y') {
398 printfs(pformat, human_time(statbuf->st_mtime)); 394 printfs(pformat, human_time(&statbuf->st_mtim));
399 } else if (m == 'Y') { 395 } else if (m == 'Y') {
400 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); 396 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
401 printf(pformat, (long) statbuf->st_mtime); 397 printf(pformat, (long) statbuf->st_mtime);
402 } else if (m == 'z') { 398 } else if (m == 'z') {
403 printfs(pformat, human_time(statbuf->st_ctime)); 399 printfs(pformat, human_time(&statbuf->st_ctim));
404 } else if (m == 'Z') { 400 } else if (m == 'Z') {
405 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); 401 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
406 printf(pformat, (long) statbuf->st_ctime); 402 printf(pformat, (long) statbuf->st_ctime);
@@ -505,7 +501,7 @@ static bool do_statfs(const char *filename, const char *format)
505 if (format == NULL) { 501 if (format == NULL) {
506# if !ENABLE_SELINUX 502# if !ENABLE_SELINUX
507 format = (option_mask32 & OPT_TERSE 503 format = (option_mask32 & OPT_TERSE
508 ? "%n %i %l %t %s %b %f %a %c %d\n" 504 ? "%n %i %l %t %s %b %f %a %c %d"
509 : " File: \"%n\"\n" 505 : " File: \"%n\"\n"
510 " ID: %-8i Namelen: %-7l Type: %T\n" 506 " ID: %-8i Namelen: %-7l Type: %T\n"
511 "Block size: %-10s\n" 507 "Block size: %-10s\n"
@@ -513,25 +509,26 @@ static bool do_statfs(const char *filename, const char *format)
513 "Inodes: Total: %-10c Free: %d"); 509 "Inodes: Total: %-10c Free: %d");
514# else 510# else
515 format = (option_mask32 & OPT_TERSE 511 format = (option_mask32 & OPT_TERSE
516 ? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n": 512 ? (option_mask32 & OPT_SELINUX
517 "%n %i %l %t %s %b %f %a %c %d\n") 513 ? "%n %i %l %t %s %b %f %a %c %d %C"
518 : (option_mask32 & OPT_SELINUX ? 514 : "%n %i %l %t %s %b %f %a %c %d")
519 " File: \"%n\"\n" 515 : (option_mask32 & OPT_SELINUX
520 " ID: %-8i Namelen: %-7l Type: %T\n" 516 ? " File: \"%n\"\n"
521 "Block size: %-10s\n" 517 " ID: %-8i Namelen: %-7l Type: %T\n"
522 "Blocks: Total: %-10b Free: %-10f Available: %a\n" 518 "Block size: %-10s\n"
523 "Inodes: Total: %-10c Free: %d" 519 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
524 " S_context: %C\n": 520 "Inodes: Total: %-10c Free: %d"
525 " File: \"%n\"\n" 521 " S_context: %C"
526 " ID: %-8i Namelen: %-7l Type: %T\n" 522 : " File: \"%n\"\n"
527 "Block size: %-10s\n" 523 " ID: %-8i Namelen: %-7l Type: %T\n"
528 "Blocks: Total: %-10b Free: %-10f Available: %a\n" 524 "Block size: %-10s\n"
529 "Inodes: Total: %-10c Free: %d\n") 525 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
526 "Inodes: Total: %-10c Free: %d")
530 ); 527 );
531# endif /* SELINUX */ 528# endif /* SELINUX */
532 } 529 }
533 print_it(format, filename, print_statfs, &statfsbuf IF_SELINUX(, scontext)); 530 print_it(format, filename, print_statfs, &statfsbuf IF_SELINUX(, scontext));
534#else /* FEATURE_STAT_FORMAT */ 531#else /* !FEATURE_STAT_FORMAT */
535 format = (option_mask32 & OPT_TERSE 532 format = (option_mask32 & OPT_TERSE
536 ? "%s %llx %lu " 533 ? "%s %llx %lu "
537 : " File: \"%s\"\n" 534 : " File: \"%s\"\n"
@@ -628,14 +625,14 @@ static bool do_stat(const char *filename, const char *format)
628 "Device: %Dh/%dd\tInode: %-10i Links: %-5h" 625 "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
629 " Device type: %t,%T\n" 626 " Device type: %t,%T\n"
630 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" 627 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
631 "Access: %x\n" "Modify: %y\n" "Change: %z\n"; 628 "Access: %x\n" "Modify: %y\n" "Change: %z";
632 } else { 629 } else {
633 format = 630 format =
634 " File: %N\n" 631 " File: %N\n"
635 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" 632 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
636 "Device: %Dh/%dd\tInode: %-10i Links: %h\n" 633 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
637 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" 634 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
638 "Access: %x\n" "Modify: %y\n" "Change: %z\n"; 635 "Access: %x\n" "Modify: %y\n" "Change: %z";
639 } 636 }
640 } 637 }
641# else 638# else
@@ -654,14 +651,14 @@ static bool do_stat(const char *filename, const char *format)
654 " Device type: %t,%T\n" 651 " Device type: %t,%T\n"
655 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" 652 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
656 " S_Context: %C\n" 653 " S_Context: %C\n"
657 "Access: %x\n" "Modify: %y\n" "Change: %z\n" 654 "Access: %x\n" "Modify: %y\n" "Change: %z"
658 : 655 :
659 " File: %N\n" 656 " File: %N\n"
660 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" 657 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
661 "Device: %Dh/%dd\tInode: %-10i Links: %-5h" 658 "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
662 " Device type: %t,%T\n" 659 " Device type: %t,%T\n"
663 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" 660 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
664 "Access: %x\n" "Modify: %y\n" "Change: %z\n" 661 "Access: %x\n" "Modify: %y\n" "Change: %z"
665 ); 662 );
666 } else { 663 } else {
667 format = (option_mask32 & OPT_SELINUX ? 664 format = (option_mask32 & OPT_SELINUX ?
@@ -670,13 +667,13 @@ static bool do_stat(const char *filename, const char *format)
670 "Device: %Dh/%dd\tInode: %-10i Links: %h\n" 667 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
671 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" 668 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
672 "S_Context: %C\n" 669 "S_Context: %C\n"
673 "Access: %x\n" "Modify: %y\n" "Change: %z\n" 670 "Access: %x\n" "Modify: %y\n" "Change: %z"
674 : 671 :
675 " File: %N\n" 672 " File: %N\n"
676 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" 673 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
677 "Device: %Dh/%dd\tInode: %-10i Links: %h\n" 674 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
678 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" 675 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
679 "Access: %x\n" "Modify: %y\n" "Change: %z\n" 676 "Access: %x\n" "Modify: %y\n" "Change: %z"
680 ); 677 );
681 } 678 }
682 } 679 }
@@ -757,9 +754,9 @@ static bool do_stat(const char *filename, const char *format)
757 if (option_mask32 & OPT_SELINUX) 754 if (option_mask32 & OPT_SELINUX)
758 printf(" S_Context: %s\n", scontext); 755 printf(" S_Context: %s\n", scontext);
759# endif 756# endif
760 printf("Access: %s\n", human_time(statbuf.st_atime)); 757 printf("Access: %s\n", human_time(&statbuf.st_atim));
761 printf("Modify: %s\n", human_time(statbuf.st_mtime)); 758 printf("Modify: %s\n", human_time(&statbuf.st_mtim));
762 printf("Change: %s\n", human_time(statbuf.st_ctime)); 759 printf("Change: %s\n", human_time(&statbuf.st_ctim));
763 } 760 }
764#endif /* FEATURE_STAT_FORMAT */ 761#endif /* FEATURE_STAT_FORMAT */
765 return 1; 762 return 1;