dmesg: more correct skipping of <N>; use faster putchar for most output
function old new delta dmesg_main 246 291 +45 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
0016bcee37
commit
f04ca74ab5
@ -45,20 +45,25 @@ int dmesg_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
/* Skip <#> at the start of lines, and make sure we end with a newline */
|
|
||||||
|
|
||||||
if (ENABLE_FEATURE_DMESG_PRETTY) {
|
if (ENABLE_FEATURE_DMESG_PRETTY) {
|
||||||
int last = '\n';
|
int last = '\n';
|
||||||
int in = 0;
|
int in = 0;
|
||||||
|
|
||||||
do {
|
/* Skip <#> at the start of lines */
|
||||||
if (last == '\n' && buf[in] == '<')
|
while (1) {
|
||||||
|
if (last == '\n' && buf[in] == '<') {
|
||||||
in += 3;
|
in += 3;
|
||||||
else {
|
if (in >= len)
|
||||||
last = buf[in++];
|
break;
|
||||||
bb_putchar(last);
|
|
||||||
}
|
}
|
||||||
} while (in < len);
|
last = buf[in];
|
||||||
|
putchar(last);
|
||||||
|
in++;
|
||||||
|
if (in >= len)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* Make sure we end with a newline */
|
||||||
if (last != '\n')
|
if (last != '\n')
|
||||||
bb_putchar('\n');
|
bb_putchar('\n');
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user