- 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
This commit is contained in:
Dima Dorfman 2001-09-09 14:23:31 +00:00
parent 8b0bff44c7
commit 728d043e5b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83242
3 changed files with 15 additions and 7 deletions

View File

@ -51,6 +51,8 @@ static const char rcsid[] =
#include <stdlib.h>
#include <unistd.h>
#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;

3
usr.bin/wall/ttymsg.h Normal file
View File

@ -0,0 +1,3 @@
/* $FreeBSD$ */
const char *ttymsg(struct iovec *, int, const char *, int);

View File

@ -67,9 +67,10 @@ static const char rcsid[] =
#include <unistd.h>
#include <utmp.h>
#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];