From: Andre Noll Date: Tue, 7 Jan 2014 00:25:38 +0000 (+0000) Subject: Remove chop(). X-Git-Tag: v0.5.3~12^2~33 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=efbb7fcd1fc143a046cfa4b44dbb527b248e110b;hp=3d9df3244a04aaf5c0c216f2e475f5355cf9721b Remove chop(). In curses_log() we currently we call chop(), which calls strlen() to find the last character of the given string. This is unnecessary since xvasprintf() returns this information anyway, we just have to remember it. With this change the last user of chop() is gone, so this patch removes chop() from string.c. --- diff --git a/gui.c b/gui.c index a6bc54a7..96132589 100644 --- a/gui.c +++ b/gui.c @@ -519,6 +519,7 @@ static __printf_2_3 void curses_log(int ll, const char *fmt,...) int color; char *msg; va_list ap; + unsigned bytes; if (ll < loglevel || !curses_active) return; @@ -532,9 +533,10 @@ static __printf_2_3 void curses_log(int ll, const char *fmt,...) color = COLOR_ERRMSG; } va_start(ap, fmt); - xvasprintf(&msg, fmt, ap); + bytes = xvasprintf(&msg, fmt, ap); va_end(ap); - chop(msg); + if (bytes > 0 && msg[bytes - 1] == '\n') + msg[bytes - 1] = '\0'; /* cut trailing newline */ rb_add_entry(color, msg); wrefresh(bot.win); } diff --git a/string.c b/string.c index 8cc7d5d7..10b6073f 100644 --- a/string.c +++ b/string.c @@ -298,24 +298,6 @@ __must_check char *para_basename(const char *name) return ret; } -/** - * Cut trailing newline. - * - * \param buf The string to be chopped. - * - * Replace the last character in \p buf by zero if it is equal to - * the newline character. - */ -void chop(char *buf) -{ - int n = strlen(buf); - - if (!n) - return; - if (buf[n - 1] == '\n') - buf[n - 1] = '\0'; -} - /** * Get the logname of the current user. * diff --git a/string.h b/string.h index b13a0d86..11ba1283 100644 --- a/string.h +++ b/string.h @@ -84,7 +84,6 @@ __must_check __malloc __printf_1_2 char *make_message(const char *fmt, ...); __must_check __malloc char *para_strcat(char *a, const char *b); __must_check __malloc char *para_dirname(const char *name); __must_check char *para_basename(const char *name); -void chop(char *buf); __must_check __malloc char *para_logname(void); __must_check __malloc char *para_homedir(void); __malloc char *para_hostname(void);