]> granicus.if.org Git - neomutt/commitdiff
Convert query_pipe_attachment to use buffer pool
authorKevin McCarthy <kevin@8t8.us>
Thu, 12 Sep 2019 02:40:48 +0000 (19:40 -0700)
committerRichard Russon <rich@flatcap.org>
Sat, 14 Sep 2019 16:33:03 +0000 (17:33 +0100)
Co-authored-by: Richard Russon <rich@flatcap.org>
muttlib.c
recvattach.c

index 5b67f479283c20f1b01eb2d8b40d4e1211ea1e3c..48154fea723544aa4247123bd1e7b45c38c415e8 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -712,10 +712,10 @@ int mutt_check_overwrite(const char *attname, const char *path, struct Buffer *f
 {
   struct stat st;
 
-  mutt_buffer_strcpy (fname, path);
-  if (access (mutt_b2s (fname), F_OK) != 0)
+  mutt_buffer_strcpy(fname, path);
+  if (access(mutt_b2s(fname), F_OK) != 0)
     return 0;
-  if (stat (mutt_b2s (fname), &st) != 0)
+  if (stat(mutt_b2s(fname), &st) != 0)
     return -1;
   if (S_ISDIR(st.st_mode))
   {
@@ -729,7 +729,7 @@ int mutt_check_overwrite(const char *attname, const char *path, struct Buffer *f
               (_("File is a directory, save under it: (y)es, (n)o, (a)ll?"), _("yna")))
       {
         case 3: /* all */
-          mutt_str_replace (directory, mutt_b2s (fname));
+          mutt_str_replace(directory, mutt_b2s(fname));
           break;
         case 1: /* yes */
           FREE(directory);
@@ -747,22 +747,22 @@ int mutt_check_overwrite(const char *attname, const char *path, struct Buffer *f
     else if ((ans = mutt_yesorno(_("File is a directory, save under it?"), MUTT_YES)) != MUTT_YES)
       return (ans == MUTT_NO) ? 1 : -1;
 
-    struct Buffer *tmp = mutt_buffer_pool_get ();
-    mutt_buffer_strcpy (tmp, mutt_path_basename (NONULL (attname)));
-    if (mutt_get_field (_("File under directory: "), tmp->data, tmp->dsize,
-                        MUTT_FILE | MUTT_CLEAR) != 0)
+    struct Buffer *tmp = mutt_buffer_pool_get();
+    mutt_buffer_strcpy(tmp, mutt_path_basename(NONULL(attname)));
+    if (mutt_get_field(_("File under directory: "), tmp->data, tmp->dsize,
+                       MUTT_FILE | MUTT_CLEAR) != 0)
     {
-      mutt_buffer_pool_release (&tmp);
+      mutt_buffer_pool_release(&tmp);
       return -1;
     }
-    mutt_buffer_fix_dptr (tmp);
+    mutt_buffer_fix_dptr(tmp);
     if (mutt_buffer_is_empty(tmp))
     {
-      mutt_buffer_pool_release (&tmp);
+      mutt_buffer_pool_release(&tmp);
       return (-1);
     }
-    mutt_buffer_concat_path (fname, path, mutt_b2s (tmp));
-    mutt_buffer_pool_release (&tmp);
+    mutt_buffer_concat_path(fname, path, mutt_b2s(tmp));
+    mutt_buffer_pool_release(&tmp);
   }
 
   if ((*opt == MUTT_SAVE_NO_FLAGS) && (access(mutt_b2s(fname), F_OK) == 0))
index e1bf1758b1dd5c7b39e17dacc425d40d1caaac30..ff309be24d831823ca741c58dfc83f46d0e0469c 100644 (file)
@@ -657,8 +657,8 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag,
   FILE *fp_out = NULL;
   int saved_attachments = 0;
 
-  struct Buffer *buf = mutt_buffer_pool_get ();
-  struct Buffer *tfile = mutt_buffer_pool_get ();
+  struct Buffer *buf = mutt_buffer_pool_get();
+  struct Buffer *tfile = mutt_buffer_pool_get();
 
   for (int i = 0; !tag || (i < actx->idxlen); i++)
   {
@@ -671,24 +671,25 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag,
     {
       if (!C_AttachSplit)
       {
-        if (mutt_buffer_is_empty (buf))
+        if (mutt_buffer_is_empty(buf))
         {
           enum SaveAttach opt = MUTT_SAVE_NO_FLAGS;
 
-          mutt_buffer_strcpy (buf, mutt_path_basename (NONULL (top->filename)));
+          mutt_buffer_strcpy(buf, mutt_path_basename(NONULL(top->filename)));
           prepend_savedir(buf);
 
-          if (mutt_get_field (_("Save to file: "), buf->data, buf->dsize, MUTT_FILE | MUTT_CLEAR) != 0)
+          if (mutt_get_field(_("Save to file: "), buf->data, buf->dsize,
+                             MUTT_FILE | MUTT_CLEAR) != 0)
           {
             goto cleanup;
           }
-          mutt_buffer_fix_dptr (buf);
-          if (mutt_buffer_is_empty (buf))
-              goto cleanup;
-          mutt_buffer_expand_path (buf);
-          if (mutt_check_overwrite (top->filename, mutt_b2s (buf), tfile, &opt, NULL))
+          mutt_buffer_fix_dptr(buf);
+          if (mutt_buffer_is_empty(buf))
+            goto cleanup;
+          mutt_buffer_expand_path(buf);
+          if (mutt_check_overwrite(top->filename, mutt_b2s(buf), tfile, &opt, NULL))
             goto cleanup;
-          rc = mutt_save_attachment (fp, top, mutt_b2s (tfile), opt, e);
+          rc = mutt_save_attachment(fp, top, mutt_b2s(tfile), opt, e);
           if ((rc == 0) && C_AttachSep && (fp_out = fopen(mutt_b2s(tfile), "a")))
           {
             fprintf(fp_out, "%s", C_AttachSep);
@@ -697,7 +698,7 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag,
         }
         else
         {
-          rc = mutt_save_attachment (fp, top, mutt_b2s (tfile), MUTT_SAVE_APPEND, e);
+          rc = mutt_save_attachment(fp, top, mutt_b2s(tfile), MUTT_SAVE_APPEND, e);
           if ((rc == 0) && C_AttachSep && (fp_out = fopen(mutt_b2s(tfile), "a")))
           {
             fprintf(fp_out, "%s", C_AttachSep);
@@ -755,8 +756,8 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag,
   }
 
 cleanup:
-  mutt_buffer_pool_release (&buf);
-  mutt_buffer_pool_release (&tfile);
+  mutt_buffer_pool_release(&buf);
+  mutt_buffer_pool_release(&tfile);
 }
 
 /**