[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] Use chomp to remove newlines
From: Ron Yorston <rmy () tigress ! co ! uk>
Date: 2014-04-27 16:57:24
Message-ID: 201404271657.s3RGvOm0030616 () helium ! internal ! tigress ! co ! uk
[Download RAW message or body]
Use chomp instead of strchrnul to remove a newline at the end
of a string. The strchrnul calls in man.c and mdev.c aren't
replaced as the newline may not be at the end of the string.
Also use chomp to remove the newline in xmalloc_fgetline. The
argument here may be NULL but chomp can handle that.
function old new delta
unix_do_one 548 540 -8
process_timer_stats 508 500 -8
process_irq_counts 532 524 -8
lpd_main 839 831 -8
hwclock_main 502 494 -8
xmalloc_fgetline 47 37 -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-50) Total: -50 bytes
Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
---
libbb/get_line_from_file.c | 3 +--
networking/netstat.c | 2 +-
printutils/lpd.c | 2 +-
procps/powertop.c | 6 +++---
util-linux/hwclock.c | 2 +-
5 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c
index a98dd35..54fea96 100644
--- a/libbb/get_line_from_file.c
+++ b/libbb/get_line_from_file.c
@@ -55,8 +55,7 @@ char* FAST_FUNC xmalloc_fgetline(FILE *file)
int i;
char *c = bb_get_chunk_from_file(file, &i);
- if (i && c[--i] == '\n')
- c[i] = '\0';
+ chomp(c);
return c;
}
diff --git a/networking/netstat.c b/networking/netstat.c
index f80b845..fccb5be 100644
--- a/networking/netstat.c
+++ b/networking/netstat.c
@@ -622,7 +622,7 @@ static int FAST_FUNC unix_do_one(char *line)
/* TODO: currently we stop at first NUL byte. Is it a problem? */
line += path_ofs;
- *strchrnul(line, '\n') = '\0';
+ chomp(line);
while (*line)
fputc_printable(*line++, stdout);
bb_putchar('\n');
diff --git a/printutils/lpd.c b/printutils/lpd.c
index 642e8a8..eaf42c0 100644
--- a/printutils/lpd.c
+++ b/printutils/lpd.c
@@ -204,7 +204,7 @@ int lpd_main(int argc UNUSED_PARAM, char *argv[])
goto err_exit;
}
// get filename
- *strchrnul(s, '\n') = '\0';
+ chomp(s);
fname = strchr(s, ' ');
if (!fname) {
// bad_fname:
diff --git a/procps/powertop.c b/procps/powertop.c
index e3c29d1..06a94f7 100644
--- a/procps/powertop.c
+++ b/procps/powertop.c
@@ -310,7 +310,7 @@ static void process_irq_counts(void)
while (fgets(buf, sizeof(buf), fp)) {
char irq_desc[sizeof(" <kernel IPI> : ") + sizeof(buf)];
char *p;
- const char *name;
+ char *name;
int nr;
ullong count;
ullong delta;
@@ -360,7 +360,7 @@ static void process_irq_counts(void)
}
name = p;
- strchrnul(name, '\n')[0] = '\0';
+ chomp(name);
/* Save description of the interrupt */
if (nr >= 20000)
sprintf(irq_desc, " <kernel IPI> : %s", name);
@@ -470,7 +470,7 @@ static NOINLINE int process_timer_stats(void)
process = idx < 2 ? "[kernel module]" : "<kernel core>";
}
- strchrnul(p, '\n')[0] = '\0';
+ chomp(p);
// 46D\01136\0kondemand/1\0do_dbs_timer (delayed_work_timer_fn)
// ^ ^ ^
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index 3f53155..6c99977 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -69,7 +69,7 @@ static void show_clock(const char **pp_rtcname, int utc)
strftime(cp, sizeof(cp), "%c", ptm);
#else
char *cp = ctime(&t);
- strchrnul(cp, '\n')[0] = '\0';
+ chomp(cp);
#endif
#if !SHOW_HWCLOCK_DIFF
--
1.9.0
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic