aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-14 12:56:34 +1000
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-14 12:56:34 +1000
commitc31744ca1a86b2276c37c6d9a884660185debed6 (patch)
treebb051c35c3430a3793ceef173a01cb522fb4ae05 /coreutils
parent1a286d510c2125bdab601ce47afd4d27b6ce6f41 (diff)
parente329089c62ed813e97344f8c61d7dc34221fd5ee (diff)
downloadbusybox-w32-c31744ca1a86b2276c37c6d9a884660185debed6.tar.gz
busybox-w32-c31744ca1a86b2276c37c6d9a884660185debed6.tar.bz2
busybox-w32-c31744ca1a86b2276c37c6d9a884660185debed6.zip
Merge branch 'origin/master' (early part)
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/Kbuild.src1
-rw-r--r--coreutils/basename.c12
-rw-r--r--coreutils/date.c13
-rw-r--r--coreutils/libcoreutils/Kbuild.src2
-rw-r--r--coreutils/stat.c41
5 files changed, 36 insertions, 33 deletions
diff --git a/coreutils/Kbuild.src b/coreutils/Kbuild.src
index 57ea7d6c4..1c846a75f 100644
--- a/coreutils/Kbuild.src
+++ b/coreutils/Kbuild.src
@@ -7,6 +7,7 @@
7libs-y += libcoreutils/ 7libs-y += libcoreutils/
8 8
9lib-y:= 9lib-y:=
10
10INSERT 11INSERT
11lib-$(CONFIG_CAL) += cal.o 12lib-$(CONFIG_CAL) += cal.o
12lib-$(CONFIG_CATV) += catv.o 13lib-$(CONFIG_CATV) += catv.o
diff --git a/coreutils/basename.c b/coreutils/basename.c
index d1ad91ba1..b79d561c2 100644
--- a/coreutils/basename.c
+++ b/coreutils/basename.c
@@ -5,13 +5,8 @@
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 *
9 */ 8 */
10 9
11/* BB_AUDIT SUSv3 compliant */
12/* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */
13
14
15/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) 10/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
16 * 11 *
17 * Changes: 12 * Changes:
@@ -20,6 +15,9 @@
20 * 3) Save some space by using strcmp(). Calling strncmp() here was silly. 15 * 3) Save some space by using strcmp(). Calling strncmp() here was silly.
21 */ 16 */
22 17
18/* BB_AUDIT SUSv3 compliant */
19/* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */
20
23//kbuild:lib-$(CONFIG_BASENAME) += basename.o 21//kbuild:lib-$(CONFIG_BASENAME) += basename.o
24 22
25//config:config BASENAME 23//config:config BASENAME
@@ -40,7 +38,7 @@ int basename_main(int argc, char **argv)
40 size_t m, n; 38 size_t m, n;
41 char *s; 39 char *s;
42 40
43 if (((unsigned int)(argc-2)) >= 2) { 41 if ((unsigned)(argc-2) >= 2) {
44 bb_show_usage(); 42 bb_show_usage();
45 } 43 }
46 44
@@ -50,7 +48,7 @@ int basename_main(int argc, char **argv)
50 m = strlen(s); 48 m = strlen(s);
51 if (*++argv) { 49 if (*++argv) {
52 n = strlen(*argv); 50 n = strlen(*argv);
53 if ((m > n) && ((strcmp)(s+m-n, *argv) == 0)) { 51 if ((m > n) && (strcmp(s+m-n, *argv) == 0)) {
54 m -= n; 52 m -= n;
55 /*s[m] = '\0'; - redundant */ 53 /*s[m] = '\0'; - redundant */
56 } 54 }
diff --git a/coreutils/date.c b/coreutils/date.c
index 3d78a5336..c737f09f3 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -93,6 +93,9 @@
93//config: MMDDhhmm[[YY]YY][.ss] format. 93//config: MMDDhhmm[[YY]YY][.ss] format.
94 94
95#include "libbb.h" 95#include "libbb.h"
96#if ENABLE_FEATURE_DATE_NANO
97# include <sys/syscall.h>
98#endif
96 99
97enum { 100enum {
98 OPT_RFC2822 = (1 << 0), /* R */ 101 OPT_RFC2822 = (1 << 0), /* R */
@@ -204,17 +207,15 @@ int date_main(int argc UNUSED_PARAM, char **argv)
204 xstat(filename, &statbuf); 207 xstat(filename, &statbuf);
205 ts.tv_sec = statbuf.st_mtime; 208 ts.tv_sec = statbuf.st_mtime;
206#if ENABLE_FEATURE_DATE_NANO 209#if ENABLE_FEATURE_DATE_NANO
207# if defined __GLIBC__ && !defined __UCLIBC__
208 ts.tv_nsec = statbuf.st_mtim.tv_nsec; 210 ts.tv_nsec = statbuf.st_mtim.tv_nsec;
209# else
210 ts.tv_nsec = statbuf.st_mtimensec;
211# endif
212#endif 211#endif
213 } else { 212 } else {
214#if ENABLE_FEATURE_DATE_NANO 213#if ENABLE_FEATURE_DATE_NANO
215 clock_gettime(CLOCK_REALTIME, &ts); 214 /* libc has incredibly messy way of doing this,
215 * typically requiring -lrt. We just skip all this mess */
216 syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
216#else 217#else
217 time(&ts.tv_nsec); 218 time(&ts.tv_sec);
218#endif 219#endif
219 } 220 }
220 localtime_r(&ts.tv_sec, &tm_time); 221 localtime_r(&ts.tv_sec, &tm_time);
diff --git a/coreutils/libcoreutils/Kbuild.src b/coreutils/libcoreutils/Kbuild.src
index 755d01f86..981b60628 100644
--- a/coreutils/libcoreutils/Kbuild.src
+++ b/coreutils/libcoreutils/Kbuild.src
@@ -5,6 +5,8 @@
5# Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 5# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6 6
7lib-y:= 7lib-y:=
8
9INSERT
8lib-$(CONFIG_MKFIFO) += getopt_mk_fifo_nod.o 10lib-$(CONFIG_MKFIFO) += getopt_mk_fifo_nod.o
9lib-$(CONFIG_MKNOD) += getopt_mk_fifo_nod.o 11lib-$(CONFIG_MKNOD) += getopt_mk_fifo_nod.o
10lib-$(CONFIG_INSTALL) += cp_mv_stat.o 12lib-$(CONFIG_INSTALL) += cp_mv_stat.o
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",