public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] wall: wrap message header when it exceeds 79 characters
@ 2014-07-27 19:01 Sami Kerola
  2014-07-29  7:44 ` Karel Zak
  0 siblings, 1 reply; 4+ messages in thread
From: Sami Kerola @ 2014-07-27 19:01 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Header truncation started to happen more often after commit
d81c30553f4fb49173d38f69edff4b0b67a18b65 that made the header to be
longer.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/wall.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/term-utils/wall.c b/term-utils/wall.c
index 598e9f2..acada29 100644
--- a/term-utils/wall.c
+++ b/term-utils/wall.c
@@ -202,6 +202,8 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
 		char *whom, *where, *date;
 		struct passwd *pw;
 		time_t now;
+		ssize_t len;
+		int i;
 
 		if (!(whom = getlogin()) || !*whom)
 			whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
@@ -232,7 +234,10 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
 		fprintf(fp, "\r%*s\r\n", TERM_WIDTH, " ");
 		sprintf(lbuf, _("Broadcast message from %s@%s (%s) (%s):"),
 			      whom, hostname, where, date);
-		fprintf(fp, "%-*.*s\007\007\r\n", TERM_WIDTH, TERM_WIDTH, lbuf);
+		len = strlen(lbuf);
+		for (i = 0; 0 < len; i++)
+			len -= fprintf(fp, "%-*.*s\007\007\r\n", TERM_WIDTH, TERM_WIDTH,
+				       lbuf + (i * TERM_WIDTH)) + 4;
 		free(hostname);
 		free(date);
 	}
-- 
2.0.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-07-29 16:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-27 19:01 [PATCH] wall: wrap message header when it exceeds 79 characters Sami Kerola
2014-07-29  7:44 ` Karel Zak
2014-07-29  8:27   ` Sami Kerola
2014-07-29 16:00   ` Dale R. Worley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox