]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Remove chop().
authorAndre Noll <maan@systemlinux.org>
Tue, 7 Jan 2014 00:25:38 +0000 (00:25 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 4 May 2014 13:48:53 +0000 (15:48 +0200)
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.

gui.c
string.c
string.h

diff --git a/gui.c b/gui.c
index a6bc54a738ff5e255675fbbe9902d09afabc281f..96132589157ab83810da14e3f96e768d80f518ae 100644 (file)
--- 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);
 }
index 8cc7d5d7965e725839375237af3f063b1b44d13b..10b6073fe1ff9960bac98ac473146a8a3e00a575 100644 (file)
--- 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.
  *
index b13a0d86bbe57b2fb7a31e81ad04c3f19ca96bad..11ba1283000d3f382eab71a0463923f2991bed2c 100644 (file)
--- 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);