]> granicus.if.org Git - mutt/commitdiff
browser.c: Convert other browser local variables to BUFFER.
authorKevin McCarthy <kevin@8t8.us>
Tue, 12 Mar 2019 05:56:51 +0000 (13:56 +0800)
committerKevin McCarthy <kevin@8t8.us>
Wed, 13 Mar 2019 06:28:31 +0000 (14:28 +0800)
browser.c
muttlib.c
protos.h

index 67c49134d9ae8d3a742684725fa4c1002075d6ae..7eccfd43e404470106e8dfc47490abfdb8528bb7 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -162,14 +162,19 @@ static void browser_sort (struct browser_state *state)
 static int link_is_dir (const char *folder, const char *path)
 {
   struct stat st;
-  char fullpath[_POSIX_PATH_MAX];
+  BUFFER *fullpath = NULL;
+  int retval = 0;
 
-  mutt_concat_path (fullpath, folder, path, sizeof (fullpath));
+  fullpath = mutt_buffer_pool_get ();
 
-  if (stat (fullpath, &st) == 0)
-    return (S_ISDIR (st.st_mode));
-  else
-    return 0;
+  mutt_buffer_concat_path (fullpath, folder, path);
+
+  if (stat (mutt_b2s (fullpath), &st) == 0)
+    retval = S_ISDIR (st.st_mode);
+
+  mutt_buffer_pool_release (&fullpath);
+
+  return retval;
 }
 
 static const char *
@@ -443,7 +448,7 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state,
   struct stat s;
   DIR *dp;
   struct dirent *de;
-  char buffer[_POSIX_PATH_MAX + SHORT_STRING];
+  BUFFER *buffer = NULL;
   BUFFY *tmp;
 
   while (stat (d, &s) == -1)
@@ -477,6 +482,7 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state,
     return (-1);
   }
 
+  buffer = mutt_buffer_pool_get ();
   init_state (state, menu);
 
   while ((de = readdir (dp)) != NULL)
@@ -489,8 +495,8 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state,
     if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not))
       continue;
 
-    mutt_concat_path (buffer, d, de->d_name, sizeof (buffer));
-    if (lstat (buffer, &s) == -1)
+    mutt_buffer_concat_path (buffer, d, de->d_name);
+    if (lstat (mutt_b2s (buffer), &s) == -1)
       continue;
 
     /* No size for directories or symlinks */
@@ -500,7 +506,7 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state,
       continue;
 
     tmp = Incoming;
-    while (tmp && mutt_strcmp (buffer, tmp->path))
+    while (tmp && mutt_strcmp (mutt_b2s (buffer), tmp->path))
       tmp = tmp->next;
     if (tmp && Context &&
         !mutt_strcmp (tmp->realpath, Context->realpath))
@@ -512,6 +518,8 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state,
   }
   closedir (dp);
   browser_sort (state);
+
+  mutt_buffer_pool_release (&buffer);
   return 0;
 }
 
@@ -520,11 +528,13 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
   struct stat s;
   char buffer[LONG_STRING];
   BUFFY *tmp = Incoming;
+  BUFFER *md = NULL;
 
   if (!Incoming)
     return (-1);
   mutt_buffy_check (0);
 
+  md = mutt_buffer_pool_get ();
   init_state (state, menu);
 
   do
@@ -564,13 +574,12 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
     if (mx_is_maildir (tmp->path))
     {
       struct stat st2;
-      char md[_POSIX_PATH_MAX];
 
-      snprintf (md, sizeof (md), "%s/new", tmp->path);
-      if (stat (md, &s) < 0)
+      mutt_buffer_printf (md, "%s/new", tmp->path);
+      if (stat (mutt_b2s (md), &s) < 0)
        s.st_mtime = 0;
-      snprintf (md, sizeof (md), "%s/cur", tmp->path);
-      if (stat (md, &st2) < 0)
+      mutt_buffer_printf (md, "%s/cur", tmp->path);
+      if (stat (mutt_b2s (md), &st2) < 0)
        st2.st_mtime = 0;
       if (st2.st_mtime > s.st_mtime)
        s.st_mtime = st2.st_mtime;
@@ -580,6 +589,8 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
   }
   while ((tmp = tmp->next));
   browser_sort (state);
+
+  mutt_buffer_pool_release (&md);
   return 0;
 }
 
@@ -602,7 +613,9 @@ static void folder_entry (char *s, size_t slen, MUTTMENU *menu, int num)
 static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
                       size_t titlelen, int buffy)
 {
-  char path[_POSIX_PATH_MAX];
+  BUFFER *path = NULL;
+
+  path = mutt_buffer_pool_get ();
 
   menu->max = state->entrylen;
 
@@ -619,18 +632,20 @@ static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
     snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0));
   else
   {
-    strfcpy (path, mutt_b2s (LastDir), sizeof (path));
-    mutt_pretty_mailbox (path, sizeof (path));
+    mutt_buffer_strcpy (path, mutt_b2s (LastDir));
+    mutt_buffer_pretty_mailbox (path);
 #ifdef USE_IMAP
     if (state->imap_browse && option (OPTIMAPLSUB))
       snprintf (title, titlelen, _("Subscribed [%s], File mask: %s"),
-                path, NONULL (Mask.pattern));
+                mutt_b2s (path), NONULL (Mask.pattern));
     else
 #endif
       snprintf (title, titlelen, _("Directory [%s], File mask: %s"),
-                path, NONULL(Mask.pattern));
+                mutt_b2s (path), NONULL(Mask.pattern));
   }
   menu->redraw = REDRAW_FULL;
+
+  mutt_buffer_pool_release (&path);
 }
 
 static int file_tag (MUTTMENU *menu, int n, int m)
@@ -954,12 +969,11 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
            for (i = 0, j = 0; i < state.entrylen; i++)
            {
              struct folder_file ff = state.entry[i];
-             char full[_POSIX_PATH_MAX];
              if (ff.tagged)
              {
-               mutt_concat_path (full, mutt_b2s (LastDir), ff.name, sizeof (full));
-               mutt_expand_path (full, sizeof (full));
-               tfiles[j++] = safe_strdup (full);
+               mutt_buffer_concat_path (tmp, mutt_b2s (LastDir), ff.name);
+               mutt_buffer_expand_path (tmp);
+               tfiles[j++] = safe_strdup (mutt_b2s (tmp));
              }
            }
            *files = tfiles;
index 54e7b72d465e458dae41b3deb7e36e06afdc9b64..4c8a94a85abaf5ab6deb3b2a34c40cb8cc9ff153 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -921,6 +921,15 @@ void mutt_free_alias (ALIAS **p)
   }
 }
 
+void mutt_buffer_pretty_mailbox (BUFFER *s)
+{
+  /* This reduces the size of the BUFFER, so we can pass it through.
+   * We adjust the size just to make sure s->data is not NULL though */
+  mutt_buffer_increase_size (s, _POSIX_PATH_MAX);
+  mutt_pretty_mailbox (s->data, s->dsize);
+  mutt_buffer_fix_dptr (s);
+}
+
 /* collapse the pathname using ~ or = when possible */
 void mutt_pretty_mailbox (char *s, size_t buflen)
 {
index 83726beb85e2b8c21856b7d67bdb71783d792f12..99def0937f16a400a826b9780ec5f2e5eb7f9dd8 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -250,6 +250,7 @@ void mutt_parse_part (FILE *, BODY *);
 void mutt_perror (const char *);
 void mutt_prepare_envelope (ENVELOPE *, int);
 void mutt_unprepare_envelope (ENVELOPE *);
+void mutt_buffer_pretty_mailbox (BUFFER *);
 void mutt_pretty_mailbox (char *, size_t);
 void mutt_pretty_size (char *, size_t, LOFF_T);
 void mutt_pipe_message (HEADER *);