From 8a3521bf30812a63d06554a1d7f88325346ba791 Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 14 Mar 2001 20:51:15 +0000 Subject: Move trimdomain() into it's own source file and tidy things up a bit. Fix disorder in the Makefile. Reviewed (mostly) by: bde --- lib/libutil/logwtmp.c | 58 +-------------------------------------------------- 1 file changed, 1 insertion(+), 57 deletions(-) (limited to 'lib/libutil/logwtmp.c') diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c index 2648450..d77f8a4 100644 --- a/lib/libutil/logwtmp.c +++ b/lib/libutil/logwtmp.c @@ -42,16 +42,13 @@ static const char rcsid[] = #include #include -#include #include #include -#include -#include #include #include +#include #include -#include #include #include @@ -60,59 +57,6 @@ static const char rcsid[] = #define NI_WITHSCOPEID 0 #endif -void -trimdomain(char *fullhost, int hostsize) -{ - static char domain[MAXHOSTNAMELEN]; - static int first = 1; - static size_t dlen; - char *s, *end; - int spn, ok; - - if (first) { - first = 0; - if (gethostname(domain, sizeof(domain) - 1) == 0 && - (s = strchr(domain, '.'))) - memmove(domain, s + 1, strlen(s + 1) + 1); - else - domain[0] = '\0'; - dlen = strlen(domain); - } - - if (domain[0] != '\0') { - s = fullhost; - end = s + hostsize + 1; - for (; (s = memchr(s, '.', end - s)) != NULL; s++) - if (!strncasecmp(s + 1, domain, dlen)) { - if (s[dlen + 1] == '\0') { - *s = '\0'; /* Found - lose the domain */ - break; - } else if (s[dlen + 1] == ':') { /* $DISPLAY ? */ - ok = dlen + 2; - spn = strspn(s + ok, "0123456789"); - if (spn > 0 && ok + spn - dlen <= end - s) { - ok += spn; - if (s[ok] == '\0') { - /* host.domain:nn */ - memmove(s, s + dlen + 1, ok - dlen); - break; - } else if (s[ok] == '.') { - ok++; - spn = strspn(s + ok, "0123456789"); - if (spn > 0 && s[ok + spn] == '\0' && - ok + spn - dlen <= end - s) { - /* host.domain:nn.nn */ - memmove(s, s + dlen + 1, ok + spn - dlen); - break; - } - } - } - } - } - } -} - -#include void logwtmp(line, name, host) -- cgit v1.1