]> granicus.if.org Git - neomutt/commitdiff
A different fix for #767.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 9 Oct 2001 09:29:55 +0000 (09:29 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 9 Oct 2001 09:29:55 +0000 (09:29 +0000)
getdomain.c

index 5b2d715fb9bb85a9a809cc49c3d91321ec235296..23b2f48b5f81ade0943aac57c6b54780dda888a7 100644 (file)
@@ -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);
 }