From 37c783b7891d1cfb8771028b6893c5d5d88f804e Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 7 Apr 1999 14:03:31 +0000 Subject: Tidy up trimdomain() and document it. Don't truncate one byte short of the passed length. --- lib/libutil/logwtmp.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'lib/libutil/logwtmp.c') diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index 9759578..acbb4c9 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; #else static const char rcsid[] = - "$Id: logwtmp.c,v 1.8 1998/10/09 11:24:19 jkh Exp $"; + "$Id: logwtmp.c,v 1.9 1999/04/07 08:27:04 brian Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -55,7 +55,7 @@ static const char rcsid[] = #include void -trimdomain( char * fullhost, int hostsize ) +trimdomain(char *fullhost, int hostsize) { static char domain[MAXHOSTNAMELEN]; static int first = 1; @@ -67,21 +67,18 @@ trimdomain( char * fullhost, int hostsize ) (s = strchr(domain, '.'))) bcopy(s + 1, domain, strlen(s + 1) + 1); else - domain[0] = 0; + domain[0] = '\0'; } - if (domain[0]) { - s = fullhost; - while ((fullhost = strchr(fullhost, '.'))) { + if (domain[0] != '\0') { + s = fullhost; + while ((fullhost = strchr(fullhost, '.')) != NULL) if (!strcasecmp(fullhost + 1, domain)) { - if ( fullhost - s < hostsize ) { + if (fullhost - s <= hostsize) *fullhost = '\0'; /* hit it and acceptable size*/ - } break; - } else { + } else fullhost++; - } - } } } -- cgit v1.1