From: Kevin McCarthy Date: Wed, 9 Oct 2019 04:59:41 +0000 (+0800) Subject: Convert main() to use buffers for paths. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e4c176b3546c224c05a430c5aaae86567caec917;p=mutt 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. --- diff --git a/main.c b/main.c index 3b423c2a..7e8b37c4 100644 --- a/main.c +++ b/main.c @@ -613,6 +613,8 @@ static void start_curses (void) 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 @@ int main (int argc, char **argv, char **environ) 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 @@ int main (int argc, char **argv, char **environ) { 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 @@ int main (int argc, char **argv, char **environ) } 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 @@ int main (int argc, char **argv, char **environ) */ 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 @@ int main (int argc, char **argv, char **environ) 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 @@ int main (int argc, char **argv, char **environ) * 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 @@ int main (int argc, char **argv, char **environ) 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 @@ int main (int argc, char **argv, char **environ) /* !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 @@ int main (int argc, char **argv, char **environ) cleanup_and_exit: mutt_buffer_free (&folder); + mutt_buffer_free (&expanded_infile); + mutt_buffer_free (&tempfile); #ifdef USE_IMAP imap_logout_all (); #endif diff --git a/protos.h b/protos.h index 5a99f900..bbf88eac 100644 --- a/protos.h +++ b/protos.h @@ -578,7 +578,7 @@ int ioctl (int, int, ...); /* 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 */ diff --git a/send.c b/send.c index 08c89afd..7299a4e6 100644 --- a/send.c +++ b/send.c @@ -1554,7 +1554,7 @@ static int postpone_message (HEADER *msg, HEADER *cur, char *fcc, int flags) 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 */ {