there is absolutely *NO* reason for a separate pop library.
[apps/madmutt.git] / lib-sys / unix.c
index 4f189c1..3e2c23d 100644 (file)
@@ -8,16 +8,7 @@
  * please see the file GPL in the top level source directory.
  */
 
-#include <errno.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include <lib-lib/macros.h>
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/file.h>
+#include <lib-lib/lib-lib.h>
 
 #include "unix.h"
 #include "mutt_signal.h"
@@ -40,7 +31,7 @@ ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, rx_t *rx)
     if (!pw->pw_gecos)
         return 0;
 
-    if (rx) {
+    if (rx->rx) {
         regmatch_t pat_match[1];
 
         if (regexec(rx->rx, pw->pw_gecos, 1, pat_match, 0)) {
@@ -48,16 +39,16 @@ ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, rx_t *rx)
         }
 
         p   = pw->pw_gecos + pat_match[0].rm_so;
-        end = pw->pw_gecos + pat_match[0].rm_so;
+        end = pw->pw_gecos + pat_match[0].rm_eo;
     } else {
         p   = pw->pw_gecos;
         end = m_strchrnul(pw->pw_gecos, ',');
     }
 
     for (;;) {
-        const char *q = MIN(end, m_strchrnul(p, '&'));
+        const char *q = m_strchrnul(p, '&');
 
-        len += m_strncpy(dst + len, n - len, p, q - p);
+        len += m_strncpy(dst + len, n - len, p, MIN(end, q) - p);
         p = q + 1;
 
         if (!p[-1] || p >= end)
@@ -183,8 +174,8 @@ int getdnsdomainname(char *s, ssize_t n)
 
             trailing_dot = q[-1] == '.';
             if (!trailing_dot || q > p + 1) {
-                m_strncpy(s, n, p, p - q - trailing_dot);
-                safe_fclose(&f);
+                m_strncpy(s, n, p, q - trailing_dot - p);
+                m_fclose(&f);
                 return 0;
             }
 
@@ -192,6 +183,6 @@ int getdnsdomainname(char *s, ssize_t n)
         }
     }
 
-    safe_fclose (&f);
+    m_fclose(&f);
     return -1;
 }