diff options
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/Config.in | 5 | ||||
| -rw-r--r-- | coreutils/tail.c | 22 |
2 files changed, 9 insertions, 18 deletions
diff --git a/coreutils/Config.in b/coreutils/Config.in index 54bdc6868..90f681c04 100644 --- a/coreutils/Config.in +++ b/coreutils/Config.in | |||
| @@ -420,11 +420,12 @@ config CONFIG_TAIL | |||
| 420 | from files. | 420 | from files. |
| 421 | 421 | ||
| 422 | config CONFIG_FEATURE_FANCY_TAIL | 422 | config CONFIG_FEATURE_FANCY_TAIL |
| 423 | bool " Enable extra tail options (-c, -q, -s, and -v)" | 423 | bool " Enable extra tail options (-q, -s, and -v)" |
| 424 | default y | 424 | default y |
| 425 | depends on CONFIG_TAIL | 425 | depends on CONFIG_TAIL |
| 426 | help | 426 | help |
| 427 | Enable tail options (-c, -q, -s, and -v). | 427 | The options (-q, -s, and -v) are provided by GNU tail, but |
| 428 | are not specific in the SUSv3 standard. | ||
| 428 | 429 | ||
| 429 | config CONFIG_TEE | 430 | config CONFIG_TEE |
| 430 | bool "tee" | 431 | bool "tee" |
diff --git a/coreutils/tail.c b/coreutils/tail.c index 10b5cd7a7..d588ccdd1 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
| @@ -89,9 +89,9 @@ static ssize_t tail_read(int fd, char *buf, size_t count) | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | static const char tail_opts[] = | 91 | static const char tail_opts[] = |
| 92 | "fn:" | 92 | "fn:c:" |
| 93 | #ifdef CONFIG_FEATURE_FANCY_TAIL | 93 | #ifdef CONFIG_FEATURE_FANCY_TAIL |
| 94 | "c:qs:v" | 94 | "qs:v" |
| 95 | #endif | 95 | #endif |
| 96 | ; | 96 | ; |
| 97 | 97 | ||
| @@ -104,9 +104,7 @@ int tail_main(int argc, char **argv) | |||
| 104 | int from_top = 0; | 104 | int from_top = 0; |
| 105 | int follow = 0; | 105 | int follow = 0; |
| 106 | int header_threshhold = 1; | 106 | int header_threshhold = 1; |
| 107 | #ifdef CONFIG_FEATURE_FANCY_TAIL | ||
| 108 | int count_bytes = 0; | 107 | int count_bytes = 0; |
| 109 | #endif | ||
| 110 | 108 | ||
| 111 | char *tailbuf; | 109 | char *tailbuf; |
| 112 | size_t tailbufsize; | 110 | size_t tailbufsize; |
| @@ -132,11 +130,9 @@ int tail_main(int argc, char **argv) | |||
| 132 | case 'f': | 130 | case 'f': |
| 133 | follow = 1; | 131 | follow = 1; |
| 134 | break; | 132 | break; |
| 135 | #ifdef CONFIG_FEATURE_FANCY_TAIL | ||
| 136 | case 'c': | 133 | case 'c': |
| 137 | count_bytes = 1; | 134 | count_bytes = 1; |
| 138 | /* FALLS THROUGH */ | 135 | /* FALLS THROUGH */ |
| 139 | #endif | ||
| 140 | case 'n': | 136 | case 'n': |
| 141 | GET_COUNT: | 137 | GET_COUNT: |
| 142 | count = bb_xgetlarg10_sfx(optarg, tail_suffixes); | 138 | count = bb_xgetlarg10_sfx(optarg, tail_suffixes); |
| @@ -201,7 +197,7 @@ int tail_main(int argc, char **argv) | |||
| 201 | } | 197 | } |
| 202 | 198 | ||
| 203 | tailbufsize = BUFSIZ; | 199 | tailbufsize = BUFSIZ; |
| 204 | #ifdef CONFIG_FEATURE_FANCY_TAIL | 200 | |
| 205 | /* tail the files */ | 201 | /* tail the files */ |
| 206 | if (from_top < count_bytes) { /* Each is 0 or 1, so true iff 0 < 1. */ | 202 | if (from_top < count_bytes) { /* Each is 0 or 1, so true iff 0 < 1. */ |
| 207 | /* Hence, !from_top && count_bytes */ | 203 | /* Hence, !from_top && count_bytes */ |
| @@ -209,7 +205,7 @@ int tail_main(int argc, char **argv) | |||
| 209 | tailbufsize = count + BUFSIZ; | 205 | tailbufsize = count + BUFSIZ; |
| 210 | } | 206 | } |
| 211 | } | 207 | } |
| 212 | #endif | 208 | |
| 213 | buf = tailbuf = xmalloc(tailbufsize); | 209 | buf = tailbuf = xmalloc(tailbufsize); |
| 214 | 210 | ||
| 215 | fmt = header_fmt + 1; /* Skip header leading newline on first output. */ | 211 | fmt = header_fmt + 1; /* Skip header leading newline on first output. */ |
| @@ -237,13 +233,10 @@ int tail_main(int argc, char **argv) | |||
| 237 | if (from_top) { | 233 | if (from_top) { |
| 238 | nwrite = nread; | 234 | nwrite = nread; |
| 239 | if (seen < count) { | 235 | if (seen < count) { |
| 240 | #ifdef CONFIG_FEATURE_FANCY_TAIL | ||
| 241 | if (count_bytes) { | 236 | if (count_bytes) { |
| 242 | nwrite -= (count - seen); | 237 | nwrite -= (count - seen); |
| 243 | seen = count; | 238 | seen = count; |
| 244 | } else | 239 | } else { |
| 245 | #endif | ||
| 246 | { | ||
| 247 | s = buf; | 240 | s = buf; |
| 248 | do { | 241 | do { |
| 249 | --nwrite; | 242 | --nwrite; |
| @@ -255,16 +248,13 @@ int tail_main(int argc, char **argv) | |||
| 255 | } | 248 | } |
| 256 | tail_xbb_full_write(buf + nread - nwrite, nwrite); | 249 | tail_xbb_full_write(buf + nread - nwrite, nwrite); |
| 257 | } else if (count) { | 250 | } else if (count) { |
| 258 | #ifdef CONFIG_FEATURE_FANCY_TAIL | ||
| 259 | if (count_bytes) { | 251 | if (count_bytes) { |
| 260 | taillen += nread; | 252 | taillen += nread; |
| 261 | if (taillen > count) { | 253 | if (taillen > count) { |
| 262 | memmove(tailbuf, tailbuf + taillen - count, count); | 254 | memmove(tailbuf, tailbuf + taillen - count, count); |
| 263 | taillen = count; | 255 | taillen = count; |
| 264 | } | 256 | } |
| 265 | } else | 257 | } else { |
| 266 | #endif | ||
| 267 | { | ||
| 268 | int k = nread; | 258 | int k = nread; |
| 269 | int nbuf = 0; | 259 | int nbuf = 0; |
| 270 | 260 | ||
