diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 2001-10-09 09:29:55 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 2001-10-09 09:29:55 +0000 |
commit | 55aa69837fe891923d439dd291081f5cd9ae3cd5 (patch) | |
tree | eaeea68a077bb8875aedfe16935a0cc5c183aef5 | |
parent | 205a021049ffe2ff653727563b9cdc4f228f1655 (diff) |
A different fix for #767.
-rw-r--r-- | getdomain.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/getdomain.c b/getdomain.c index 5b2d715f..23b2f48b 100644 --- a/getdomain.c +++ b/getdomain.c @@ -12,11 +12,23 @@ int fclose (); * return the DNS domain, but the NIS domain. */ +static void strip_trailing_dot (char *q) +{ + char *p = q; + + for (; *q; q++) + p = q; + + if (*p == '.') + *p = '\0'; +} + int getdnsdomainname (char *s, size_t l) { FILE *f; char tmp[1024]; char *p = NULL; + char *q; if ((f = fopen ("/etc/resolv.conf", "r")) == NULL) return (-1); @@ -31,24 +43,22 @@ int getdnsdomainname (char *s, size_t l) if (mutt_strncmp ("domain", p, 6) == 0 || mutt_strncmp ("search", p, 6) == 0) { p += 6; - while (ISSPACE (*p)) p++; + + for (q = strtok (p, " \t\n"); q; q = strtok (NULL, " \t\n")) + if (strcmp (q, ".")) + break; - if (*p) + if (q) { - while (*p && !ISSPACE (*p) && l > 0) - { - *s++ = *p++; - l--; - } - if (*(s-1) == '.') s--; - *s = 0; - - fclose (f); - return (0); + strip_trailing_dot (q); + strfcpy (s, q, l); + safe_fclose (&f); + return 0; } + } } - fclose (f); + safe_fclose (&f); return (-1); } |