]> granicus.if.org Git - neomutt/commitdiff
Convert maildir_parse_dir to use struct Buffer.
authorKevin McCarthy <kevin@8t8.us>
Sun, 7 Oct 2018 22:31:40 +0000 (15:31 -0700)
committerRichard Russon <rich@flatcap.org>
Sun, 7 Oct 2018 22:31:40 +0000 (15:31 -0700)
Note: the uses of buf and tmp don't overlap, so we only use a single
struct Buffer.

maildir/mh.c

index e1b0593c1f330b7107970be04e2107e3774cedc3..d752c8a51d205d481f5710bf520c4e31c7fccb49 100644 (file)
@@ -740,22 +740,27 @@ static int maildir_parse_dir(struct Mailbox *mailbox, struct Maildir ***last,
                              const char *subdir, int *count, struct Progress *progress)
 {
   struct dirent *de = NULL;
-  char buf[PATH_MAX];
-  int is_old = 0;
+  struct Buffer *buf = NULL;
+  int rc = 0, is_old = 0;
   struct Maildir *entry = NULL;
   struct Email *e = NULL;
 
+  buf = mutt_buffer_pool_get();
+
   if (subdir)
   {
-    snprintf(buf, sizeof(buf), "%s/%s", mailbox->path, subdir);
+    mutt_buffer_printf(buf, "%s/%s", mailbox->path, subdir);
     is_old = MarkOld ? (mutt_str_strcmp("cur", subdir) == 0) : false;
   }
   else
-    mutt_str_strfcpy(buf, mailbox->path, sizeof(buf));
+    mutt_buffer_strcpy(buf, mailbox->path);
 
-  DIR *dirp = opendir(buf);
+  DIR *dirp = opendir(mutt_b2s(buf));
   if (!dirp)
-    return -1;
+  {
+    rc = -1;
+    goto cleanup;
+  }
 
   while (((de = readdir(dirp))) && (SigInt != 1))
   {
@@ -782,9 +787,8 @@ static int maildir_parse_dir(struct Mailbox *mailbox, struct Maildir ***last,
 
     if (subdir)
     {
-      char tmp[LONG_STRING];
-      snprintf(tmp, sizeof(tmp), "%s/%s", subdir, de->d_name);
-      e->path = mutt_str_strdup(tmp);
+      mutt_buffer_printf(buf, "%s/%s", subdir, de->d_name);
+      e->path = mutt_str_strdup(mutt_b2s(buf));
     }
     else
       e->path = mutt_str_strdup(de->d_name);
@@ -804,7 +808,10 @@ static int maildir_parse_dir(struct Mailbox *mailbox, struct Maildir ***last,
     return -2; /* action aborted */
   }
 
-  return 0;
+cleanup:
+  mutt_buffer_pool_release(&buf);
+
+  return rc;
 }
 
 /**