diff options
author | Ron Yorston <rmy@pobox.com> | 2014-01-02 10:25:11 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-01-02 10:25:11 +0000 |
commit | b8f278ee745778806118f57fb7884d205eba05ad (patch) | |
tree | fef237f6dd302c59918cf389a60c120e58d3e086 /coreutils | |
parent | 3fd34651ea72ea1c335d3170f234cb0517fd897f (diff) | |
parent | 57434022cefde87133b8ad39fb3b79c1274e7684 (diff) | |
download | busybox-w32-b8f278ee745778806118f57fb7884d205eba05ad.tar.gz busybox-w32-b8f278ee745778806118f57fb7884d205eba05ad.tar.bz2 busybox-w32-b8f278ee745778806118f57fb7884d205eba05ad.zip |
Merge branch 'busybox' into merge
Conflicts:
archival/Config.src
shell/ash.c
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cal.c | 2 | ||||
-rw-r--r-- | coreutils/expand.c | 13 | ||||
-rw-r--r-- | coreutils/sum.c | 4 | ||||
-rw-r--r-- | coreutils/tail.c | 5 | ||||
-rw-r--r-- | coreutils/touch.c | 39 |
5 files changed, 45 insertions, 18 deletions
diff --git a/coreutils/cal.c b/coreutils/cal.c index 0d388aa1c..12c46b14f 100644 --- a/coreutils/cal.c +++ b/coreutils/cal.c | |||
@@ -165,7 +165,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv) | |||
165 | char lineout[30]; | 165 | char lineout[30]; |
166 | 166 | ||
167 | day_array(month, year, dp); | 167 | day_array(month, year, dp); |
168 | len = sprintf(lineout, "%s %d", month_names[month - 1], year); | 168 | len = sprintf(lineout, "%s %u", month_names[month - 1], year); |
169 | printf("%*s%s\n%s\n", | 169 | printf("%*s%s\n%s\n", |
170 | ((7*julian + WEEK_LEN) - len) / 2, "", | 170 | ((7*julian + WEEK_LEN) - len) / 2, "", |
171 | lineout, day_headings); | 171 | lineout, day_headings); |
diff --git a/coreutils/expand.c b/coreutils/expand.c index 25bbffc66..8d376ff4e 100644 --- a/coreutils/expand.c +++ b/coreutils/expand.c | |||
@@ -78,11 +78,7 @@ static void expand(FILE *file, unsigned tab_size, unsigned opt) | |||
78 | unsigned len; | 78 | unsigned len; |
79 | *ptr = '\0'; | 79 | *ptr = '\0'; |
80 | # if ENABLE_UNICODE_SUPPORT | 80 | # if ENABLE_UNICODE_SUPPORT |
81 | { | 81 | len = unicode_strwidth(ptr_strbeg); |
82 | uni_stat_t uni_stat; | ||
83 | printable_string(&uni_stat, ptr_strbeg); | ||
84 | len = uni_stat.unicode_width; | ||
85 | } | ||
86 | # else | 82 | # else |
87 | len = ptr - ptr_strbeg; | 83 | len = ptr - ptr_strbeg; |
88 | # endif | 84 | # endif |
@@ -138,12 +134,9 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt) | |||
138 | printf("%*s%.*s", len, "", n, ptr); | 134 | printf("%*s%.*s", len, "", n, ptr); |
139 | # if ENABLE_UNICODE_SUPPORT | 135 | # if ENABLE_UNICODE_SUPPORT |
140 | { | 136 | { |
141 | char c; | 137 | char c = ptr[n]; |
142 | uni_stat_t uni_stat; | ||
143 | c = ptr[n]; | ||
144 | ptr[n] = '\0'; | 138 | ptr[n] = '\0'; |
145 | printable_string(&uni_stat, ptr); | 139 | len = unicode_strwidth(ptr); |
146 | len = uni_stat.unicode_width; | ||
147 | ptr[n] = c; | 140 | ptr[n] = c; |
148 | } | 141 | } |
149 | # else | 142 | # else |
diff --git a/coreutils/sum.c b/coreutils/sum.c index 75f6ef60a..deb068e10 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c | |||
@@ -70,9 +70,9 @@ static unsigned sum_file(const char *file, unsigned type) | |||
70 | if (type >= SUM_SYSV) { | 70 | if (type >= SUM_SYSV) { |
71 | r = (s & 0xffff) + ((s & 0xffffffff) >> 16); | 71 | r = (s & 0xffff) + ((s & 0xffffffff) >> 16); |
72 | s = (r & 0xffff) + (r >> 16); | 72 | s = (r & 0xffff) + (r >> 16); |
73 | printf("%d %llu %s\n", s, (total_bytes + 511) / 512, file); | 73 | printf("%u %llu %s\n", s, (total_bytes + 511) / 512, file); |
74 | } else | 74 | } else |
75 | printf("%05d %5llu %s\n", s, (total_bytes + 1023) / 1024, file); | 75 | printf("%05u %5llu %s\n", s, (total_bytes + 1023) / 1024, file); |
76 | return 1; | 76 | return 1; |
77 | #undef buf | 77 | #undef buf |
78 | } | 78 | } |
diff --git a/coreutils/tail.c b/coreutils/tail.c index 07c71ca4b..eab502beb 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -105,6 +105,7 @@ int tail_main(int argc, char **argv) | |||
105 | 105 | ||
106 | int *fds; | 106 | int *fds; |
107 | const char *fmt; | 107 | const char *fmt; |
108 | int prev_fd; | ||
108 | 109 | ||
109 | INIT_G(); | 110 | INIT_G(); |
110 | 111 | ||
@@ -309,6 +310,7 @@ int tail_main(int argc, char **argv) | |||
309 | xwrite(STDOUT_FILENO, tailbuf, taillen); | 310 | xwrite(STDOUT_FILENO, tailbuf, taillen); |
310 | } | 311 | } |
311 | } while (++i < nfiles); | 312 | } while (++i < nfiles); |
313 | prev_fd = fds[i-1]; | ||
312 | 314 | ||
313 | tailbuf = xrealloc(tailbuf, BUFSIZ); | 315 | tailbuf = xrealloc(tailbuf, BUFSIZ); |
314 | 316 | ||
@@ -365,9 +367,10 @@ int tail_main(int argc, char **argv) | |||
365 | nread = tail_read(fd, tailbuf, BUFSIZ); | 367 | nread = tail_read(fd, tailbuf, BUFSIZ); |
366 | if (nread <= 0) | 368 | if (nread <= 0) |
367 | break; | 369 | break; |
368 | if (fmt) { | 370 | if (fmt && (fd != prev_fd)) { |
369 | tail_xprint_header(fmt, filename); | 371 | tail_xprint_header(fmt, filename); |
370 | fmt = NULL; | 372 | fmt = NULL; |
373 | prev_fd = fd; | ||
371 | } | 374 | } |
372 | xwrite(STDOUT_FILENO, tailbuf, nread); | 375 | xwrite(STDOUT_FILENO, tailbuf, nread); |
373 | } | 376 | } |
diff --git a/coreutils/touch.c b/coreutils/touch.c index 1216ca202..293a96890 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c | |||
@@ -26,6 +26,14 @@ | |||
26 | //config: touch is used to create or change the access and/or | 26 | //config: touch is used to create or change the access and/or |
27 | //config: modification timestamp of specified files. | 27 | //config: modification timestamp of specified files. |
28 | //config: | 28 | //config: |
29 | //config:config FEATURE_TOUCH_NODEREF | ||
30 | //config: bool "Add support for -h" | ||
31 | //config: default y | ||
32 | //config: depends on TOUCH | ||
33 | //config: help | ||
34 | //config: Enable touch to have the -h option. | ||
35 | //config: This requires libc support for lutimes() function. | ||
36 | //config: | ||
29 | //config:config FEATURE_TOUCH_SUSV3 | 37 | //config:config FEATURE_TOUCH_SUSV3 |
30 | //config: bool "Add support for SUSV3 features (-d -t -r)" | 38 | //config: bool "Add support for SUSV3 features (-d -t -r)" |
31 | //config: default y | 39 | //config: default y |
@@ -42,6 +50,9 @@ | |||
42 | //usage:#define touch_full_usage "\n\n" | 50 | //usage:#define touch_full_usage "\n\n" |
43 | //usage: "Update the last-modified date on the given FILE[s]\n" | 51 | //usage: "Update the last-modified date on the given FILE[s]\n" |
44 | //usage: "\n -c Don't create files" | 52 | //usage: "\n -c Don't create files" |
53 | //usage: IF_FEATURE_TOUCH_NODEREF( | ||
54 | //usage: "\n -h Don't follow links" | ||
55 | //usage: ) | ||
45 | //usage: IF_FEATURE_TOUCH_SUSV3( | 56 | //usage: IF_FEATURE_TOUCH_SUSV3( |
46 | //usage: "\n -d DT Date/time to use" | 57 | //usage: "\n -d DT Date/time to use" |
47 | //usage: "\n -t DT Date/time to use" | 58 | //usage: "\n -t DT Date/time to use" |
@@ -65,6 +76,7 @@ | |||
65 | * parse STRING and use it instead of current time | 76 | * parse STRING and use it instead of current time |
66 | * -f (ignored, BSD compat) | 77 | * -f (ignored, BSD compat) |
67 | * -m change only the modification time | 78 | * -m change only the modification time |
79 | * -h, --no-dereference | ||
68 | * -r, --reference=FILE | 80 | * -r, --reference=FILE |
69 | * use this file's times instead of current time | 81 | * use this file's times instead of current time |
70 | * -t STAMP | 82 | * -t STAMP |
@@ -79,6 +91,13 @@ int touch_main(int argc UNUSED_PARAM, char **argv) | |||
79 | int fd; | 91 | int fd; |
80 | int status = EXIT_SUCCESS; | 92 | int status = EXIT_SUCCESS; |
81 | int opts; | 93 | int opts; |
94 | enum { | ||
95 | OPT_c = (1 << 0), | ||
96 | OPT_r = (1 << 1) * ENABLE_FEATURE_TOUCH_SUSV3, | ||
97 | OPT_d = (1 << 2) * ENABLE_FEATURE_TOUCH_SUSV3, | ||
98 | OPT_t = (1 << 3) * ENABLE_FEATURE_TOUCH_SUSV3, | ||
99 | OPT_h = (1 << 4) * ENABLE_FEATURE_TOUCH_NODEREF, | ||
100 | }; | ||
82 | #if ENABLE_FEATURE_TOUCH_SUSV3 | 101 | #if ENABLE_FEATURE_TOUCH_SUSV3 |
83 | # if ENABLE_LONG_OPTS | 102 | # if ENABLE_LONG_OPTS |
84 | static const char touch_longopts[] ALIGN1 = | 103 | static const char touch_longopts[] ALIGN1 = |
@@ -86,6 +105,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv) | |||
86 | "no-create\0" No_argument "c" | 105 | "no-create\0" No_argument "c" |
87 | "reference\0" Required_argument "r" | 106 | "reference\0" Required_argument "r" |
88 | "date\0" Required_argument "d" | 107 | "date\0" Required_argument "d" |
108 | IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h") | ||
89 | ; | 109 | ; |
90 | # endif | 110 | # endif |
91 | char *reference_file = NULL; | 111 | char *reference_file = NULL; |
@@ -105,13 +125,13 @@ int touch_main(int argc UNUSED_PARAM, char **argv) | |||
105 | * accepted data format differs a bit between -d and -t. | 125 | * accepted data format differs a bit between -d and -t. |
106 | * We accept the same formats for both */ | 126 | * We accept the same formats for both */ |
107 | opts = getopt32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:") | 127 | opts = getopt32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:") |
128 | IF_FEATURE_TOUCH_NODEREF("h") | ||
108 | /*ignored:*/ "fma" | 129 | /*ignored:*/ "fma" |
109 | IF_FEATURE_TOUCH_SUSV3(, &reference_file) | 130 | IF_FEATURE_TOUCH_SUSV3(, &reference_file) |
110 | IF_FEATURE_TOUCH_SUSV3(, &date_str) | 131 | IF_FEATURE_TOUCH_SUSV3(, &date_str) |
111 | IF_FEATURE_TOUCH_SUSV3(, &date_str) | 132 | IF_FEATURE_TOUCH_SUSV3(, &date_str) |
112 | ); | 133 | ); |
113 | 134 | ||
114 | opts &= 1; /* only -c bit is left */ | ||
115 | argv += optind; | 135 | argv += optind; |
116 | if (!*argv) { | 136 | if (!*argv) { |
117 | bb_show_usage(); | 137 | bb_show_usage(); |
@@ -121,6 +141,10 @@ int touch_main(int argc UNUSED_PARAM, char **argv) | |||
121 | struct stat stbuf; | 141 | struct stat stbuf; |
122 | xstat(reference_file, &stbuf); | 142 | xstat(reference_file, &stbuf); |
123 | timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime; | 143 | timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime; |
144 | /* Can use .st_mtim.tv_nsec | ||
145 | * (or is it .st_mtimensec?? see date.c) | ||
146 | * to set microseconds too. | ||
147 | */ | ||
124 | } | 148 | } |
125 | 149 | ||
126 | if (date_str) { | 150 | if (date_str) { |
@@ -141,9 +165,16 @@ int touch_main(int argc UNUSED_PARAM, char **argv) | |||
141 | } | 165 | } |
142 | 166 | ||
143 | do { | 167 | do { |
144 | if (utimes(*argv, (reference_file || date_str) ? timebuf : NULL) != 0) { | 168 | int result; |
145 | if (errno == ENOENT) { /* no such file */ | 169 | result = ( |
146 | if (opts) { /* creation is disabled, so ignore */ | 170 | #if ENABLE_FEATURE_TOUCH_NODEREF |
171 | (opts & OPT_h) ? lutimes : | ||
172 | #endif | ||
173 | utimes)(*argv, (reference_file || date_str) ? timebuf : NULL); | ||
174 | if (result != 0) { | ||
175 | if (errno == ENOENT) { /* no such file? */ | ||
176 | if (opts & OPT_c) { | ||
177 | /* Creation is disabled, so ignore */ | ||
147 | continue; | 178 | continue; |
148 | } | 179 | } |
149 | /* Try to create the file */ | 180 | /* Try to create the file */ |