From 728d043e5b39a81a38d72ccac31e4bc0056ac619 Mon Sep 17 00:00:00 2001 From: Dima Dorfman Date: Sun, 9 Sep 2001 14:23:31 +0000 Subject: [PATCH] - Move the prototype of ttymsg() into ttymsg.h. syslogd and talkd also use this, and they shouldn't have to have their own prototypes. - Silence warnings about constness and signedness in ttymsg(). This includes changing the return value to a `const char *', and changing the types of `left' and `wret' (both byte counts) to ssize_t. Reviewed by: bde --- usr.bin/wall/ttymsg.c | 13 ++++++++----- usr.bin/wall/ttymsg.h | 3 +++ usr.bin/wall/wall.c | 6 ++++-- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 usr.bin/wall/ttymsg.h diff --git a/usr.bin/wall/ttymsg.c b/usr.bin/wall/ttymsg.c index c65cfe8720d6..c03454edeecb 100644 --- a/usr.bin/wall/ttymsg.c +++ b/usr.bin/wall/ttymsg.c @@ -51,6 +51,8 @@ static const char rcsid[] = #include #include +#include "ttymsg.h" + /* * Display the contents of a uio structure on a terminal. Used by wall(1), * syslogd(8), and talkd(8). Forks and finishes in child if write would block, @@ -58,17 +60,18 @@ static const char rcsid[] = * error; string is not newline-terminated. Various "normal" errors are * ignored (exclusive-use, lack of permission, etc.). */ -char * +const char * ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout) { struct iovec localiov[7]; - int cnt, fd, left, wret; + ssize_t left, wret; + int cnt, fd; static char device[MAXNAMLEN] = _PATH_DEV; static char errbuf[1024]; int forked; forked = 0; - if (iovcnt > sizeof(localiov) / sizeof(localiov[0])) + if (iovcnt > (int)(sizeof(localiov) / sizeof(localiov[0]))) return ("too many iov's (change code in wall/ttymsg.c)"); strlcpy(device + sizeof(_PATH_DEV) - 1, line, sizeof(device)); @@ -91,7 +94,7 @@ ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout) return (errbuf); } - for (cnt = left = 0; cnt < iovcnt; ++cnt) + for (cnt = 0, left = 0; cnt < iovcnt; ++cnt) left += iov[cnt].iov_len; for (;;) { @@ -105,7 +108,7 @@ ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout) iovcnt * sizeof(struct iovec)); iov = localiov; } - for (cnt = 0; wret >= iov->iov_len; ++cnt) { + for (cnt = 0; (size_t)wret >= iov->iov_len; ++cnt) { wret -= iov->iov_len; ++iov; --iovcnt; diff --git a/usr.bin/wall/ttymsg.h b/usr.bin/wall/ttymsg.h new file mode 100644 index 000000000000..31312aa94f55 --- /dev/null +++ b/usr.bin/wall/ttymsg.h @@ -0,0 +1,3 @@ +/* $FreeBSD$ */ + +const char *ttymsg(struct iovec *, int, const char *, int); diff --git a/usr.bin/wall/wall.c b/usr.bin/wall/wall.c index b2eec29d5c49..3e25676619d1 100644 --- a/usr.bin/wall/wall.c +++ b/usr.bin/wall/wall.c @@ -67,9 +67,10 @@ static const char rcsid[] = #include #include +#include "ttymsg.h" + static void makemsg(char *); static void usage(void); -char *ttymsg(struct iovec *, int, const char *, int); #define IGNOREUSER "sleeper" @@ -92,7 +93,8 @@ main(int argc, char *argv[]) FILE *fp; struct wallgroup *g; struct group *grp; - char *p, **np; + char **np; + const char *p; struct passwd *pw; char line[sizeof(utmp.ut_line) + 1]; char username[sizeof(utmp.ut_name) + 1];