e4c176b3546c224c05a430c5aaae86567caec917 — Kevin McCarthy 8 days ago fe69e4d
Convert main() to use buffers for paths.

Convert fpath (used for checking and creating $folder.

Convert expanded_infile and tempfile which are used for the -i,-H, and
-E options.  We allocate buffers, rather than use the pool, because
they are used for the duration of the compose/send operation.
3 files changed, 35 insertions(+), 34 deletions(-)

M main.c
M protos.h
M send.c
M main.c => main.c +33 -32
@@ 613,6 613,8 @@ int main (int argc, char **argv, char **environ)
  {
    BUFFER *folder = NULL;
+   BUFFER *expanded_infile = NULL;
+   BUFFER *tempfile = NULL;
    char *subject = NULL;
    char *includeFile = NULL;
    char *draftFile = NULL;


@@ 929,24 931,26 @@ if (!option (OPTNOCURSES) && Maildir)
    {
      struct stat sb;
-     char fpath[_POSIX_PATH_MAX];
+     BUFFER *fpath;
      char msg[STRING];
  
-     strfcpy (fpath, Maildir, sizeof (fpath));
-     mutt_expand_path (fpath, sizeof (fpath));
+     fpath = mutt_buffer_pool_get ();
+     mutt_buffer_strcpy (fpath, Maildir);
+     mutt_buffer_expand_path (fpath);
  #ifdef USE_IMAP
      /* we're not connected yet - skip mail folder creation */
-     if (!mx_is_imap (fpath))
+     if (!mx_is_imap (mutt_b2s (fpath)))
  #endif
-       if (stat (fpath, &sb) == -1 && errno == ENOENT)
+       if (stat (mutt_b2s (fpath), &sb) == -1 && errno == ENOENT)
        {
          snprintf (msg, sizeof (msg), _("%s does not exist. Create it?"), Maildir);
          if (mutt_yesorno (msg, MUTT_YES) == MUTT_YES)
          {
-           if (mkdir (fpath, 0700) == -1 && errno != EEXIST)
+           if (mkdir (mutt_b2s (fpath), 0700) == -1 && errno != EEXIST)
              mutt_error ( _("Can't create %s: %s."), Maildir, strerror (errno));
          }
        }
+     mutt_buffer_pool_release (&fpath);
    }
  
    if (sendflags & SENDPOSTPONED)


@@ 960,11 964,10 @@ {
      FILE *fin = NULL;
      FILE *fout = NULL;
-     char buf[LONG_STRING];
-     char *tempfile = NULL, *infile = NULL;
-     char *bodytext = NULL, *bodyfile = NULL;
+     char *infile = NULL;
+     char *bodytext = NULL;
+     const char *bodyfile = NULL;
      int rv = 0;
-     char expanded_infile[_POSIX_PATH_MAX];
  
      if (!option (OPTNOCURSES))
        mutt_flushinp ();


@@ 1033,16 1036,17 @@ }
  	else
  	{
- 	  strfcpy (expanded_infile, infile, sizeof (expanded_infile));
- 	  mutt_expand_path (expanded_infile, sizeof (expanded_infile));
- 	  if ((fin = fopen (expanded_infile, "r")) == NULL)
+           expanded_infile = mutt_buffer_new ();
+ 	  mutt_buffer_strcpy (expanded_infile, infile);
+ 	  mutt_buffer_expand_path (expanded_infile);
+ 	  if ((fin = fopen (mutt_b2s (expanded_infile), "r")) == NULL)
  	  {
  	    if (!option (OPTNOCURSES))
              {
  	      mutt_endwin (NULL);
                set_option (OPTNOCURSES);
              }
- 	    perror (expanded_infile);
+ 	    perror (mutt_b2s (expanded_infile));
              goto cleanup_and_exit;
  	  }
  	}


@@ 1054,19 1058,18 @@ */
        if (!edit_infile)
        {
-         mutt_mktemp (buf, sizeof (buf));
-         tempfile = safe_strdup (buf);
+         tempfile = mutt_buffer_new ();
+         mutt_buffer_mktemp (tempfile);
  
-         if ((fout = safe_fopen (tempfile, "w")) == NULL)
+         if ((fout = safe_fopen (mutt_b2s (tempfile), "w")) == NULL)
          {
            if (!option (OPTNOCURSES))
            {
              mutt_endwin (NULL);
              set_option (OPTNOCURSES);
            }
-           perror (tempfile);
+           perror (mutt_b2s (tempfile));
            safe_fclose (&fin);
-           FREE (&tempfile);
            goto cleanup_and_exit;
          }
          if (fin)


@@ 1079,15 1082,14 @@ fputs (bodytext, fout);
          safe_fclose (&fout);
  
-         if ((fin = fopen (tempfile, "r")) == NULL)
+         if ((fin = fopen (mutt_b2s (tempfile), "r")) == NULL)
          {
            if (!option (OPTNOCURSES))
            {
              mutt_endwin (NULL);
              set_option (OPTNOCURSES);
            }
-           perror (tempfile);
-           FREE (&tempfile);
+           perror (mutt_b2s (tempfile));
            goto cleanup_and_exit;
          }
        }


@@ 1155,11 1157,11 @@ * Note that SENDNOFREEHEADER is set above so it isn't unlinked.
         */
        else if (edit_infile)
-         bodyfile = expanded_infile;
+         bodyfile = mutt_b2s (expanded_infile);
        /* For bodytext and unedited includeFile: use the tempfile.
         */
        else
-         bodyfile = tempfile;
+         bodyfile = mutt_b2s (tempfile);
  
        if (fin)
          safe_fclose (&fin);


@@ 1208,24 1210,24 @@ msg->content->unlink = 0;
        else if (draftFile)
        {
-         if (truncate (expanded_infile, 0) == -1)
+         if (truncate (mutt_b2s (expanded_infile), 0) == -1)
          {
            if (!option (OPTNOCURSES))
            {
              mutt_endwin (NULL);
              set_option (OPTNOCURSES);
            }
-           perror (expanded_infile);
+           perror (mutt_b2s (expanded_infile));
            goto cleanup_and_exit;
          }
-         if ((fout = safe_fopen (expanded_infile, "a")) == NULL)
+         if ((fout = safe_fopen (mutt_b2s (expanded_infile), "a")) == NULL)
          {
            if (!option (OPTNOCURSES))
            {
              mutt_endwin (NULL);
              set_option (OPTNOCURSES);
            }
-           perror (expanded_infile);
+           perror (mutt_b2s (expanded_infile));
            goto cleanup_and_exit;
          }
  


@@ 1261,10 1263,7 @@       /* !edit_infile && draftFile will leave the tempfile around */
      if (tempfile)
-     {
-       unlink (tempfile);
-       FREE (&tempfile);
-     }
+       unlink (mutt_b2s (tempfile));
  
      if (rv)
        goto cleanup_and_exit;


@@ 1354,6 1353,8 @@   cleanup_and_exit:
    mutt_buffer_free (&folder);
+   mutt_buffer_free (&expanded_infile);
+   mutt_buffer_free (&tempfile);
  #ifdef USE_IMAP
    imap_logout_all ();
  #endif

M protos.h => protos.h +1 -1
@@ 578,7 578,7 @@   /* unsorted */
  void ci_bounce_message (HEADER *);
- int ci_send_message (int, HEADER *, char *, CONTEXT *, HEADER *);
+ int ci_send_message (int, HEADER *, const char *, CONTEXT *, HEADER *);
  
  /* prototypes for compatibility functions */
  

M send.c => send.c +1 -1
@@ 1554,7 1554,7 @@ int
  ci_send_message (int flags,		/* send mode */
  		 HEADER *msg,		/* template to use for new message */
- 		 char *tempfile,	/* file specified by -i or -H */
+ 		 const char *tempfile,	/* file specified by -i or -H */
  		 CONTEXT *ctx,		/* current mailbox */
  		 HEADER *cur)		/* current message */
  {