s.fpin = fp;
mutt_decode_attachment (b, &s);
- safe_fclose (&s.fpout);
+ m_fclose(&s.fpout);
}
else {
/* send case */
if (thepid < 0) {
mutt_perror (_("Can't create filter"));
- safe_fclose (&ifp);
+ m_fclose(&ifp);
goto bail;
}
mutt_copy_stream (ifp, ofp);
- safe_fclose (&ofp);
- safe_fclose (&ifp);
+ m_fclose(&ofp);
+ m_fclose(&ifp);
}
rv = 1;
if ((nfp = mutt_save_attachment_open (path, flags)) == NULL) {
mutt_perror ("fopen");
- safe_fclose (&ofp);
+ m_fclose(&ofp);
return (-1);
}
if (mutt_copy_stream (ofp, nfp) == -1) {
mutt_error _("Write fault!");
- safe_fclose (&ofp);
- safe_fclose (&nfp);
+ m_fclose(&ofp);
+ m_fclose(&nfp);
return (-1);
}
- safe_fclose (&ofp);
- safe_fclose (&nfp);
+ m_fclose(&ofp);
+ m_fclose(&nfp);
}
return 0;
mutt_perror (_("Can't create filter"));
rfc1524_entry_delete(&entry);
- safe_fclose (&ifp);
+ m_fclose(&ifp);
return 0;
}
mutt_copy_stream (ifp, fpout);
- safe_fclose (&fpout);
- safe_fclose (&ifp);
+ m_fclose(&fpout);
+ m_fclose(&ifp);
if (mutt_wait_filter (thepid) || option (OPTWAITKEY))
mutt_any_key_to_continue (NULL);
}
mutt_copy_stream (ifp, fpout);
- safe_fclose (&fpout);
- safe_fclose (&ifp);
+ m_fclose(&fpout);
+ m_fclose(&ifp);
if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY))
mutt_any_key_to_continue (NULL);
rc = 1;
}
bail0:
- safe_fclose (&ifp);
- safe_fclose (&fpout);
+ m_fclose(&ifp);
+ m_fclose(&fpout);
mutt_unlink (newfile);
return rc;
}
-1, fileno (fpfilterout), -1);
if (filterpid < 0) {
mutt_error (_("Cannot create display filter"));
- safe_fclose (&fpfilterout);
+ m_fclose(&fpfilterout);
unlink (tempfile);
return 0;
}
mx_close_message (&msg);
}
- if ((safe_fclose (&fpout) != 0 && errno != EPIPE) || res == -1) {
+ if ((m_fclose(&fpout) != 0 && errno != EPIPE) || res == -1) {
mutt_error (_("Could not copy message"));
if (fpfilterout != NULL) {
mutt_wait_filter (filterpid);
- safe_fclose (&fpfilterout);
+ m_fclose(&fpfilterout);
}
#if 0
/* this is maybe just plain wrong but it makes the pager display
if (fpfilterout != NULL && mutt_wait_filter (filterpid) != 0)
mutt_any_key_to_continue (NULL);
- safe_fclose (&fpfilterout); /* XXX - check result? */
+ m_fclose(&fpfilterout); /* XXX - check result? */
/* update crypto information for this message */
/* add the message separator */
if (sep)
fputs (sep, fpout);
- safe_fclose (&fpout);
+ m_fclose(&fpout);
if (mutt_wait_filter (thepid) != 0)
rc = 1;
}
fputs (sep, fpout);
}
}
- safe_fclose (&fpout);
+ m_fclose(&fpout);
if (mutt_wait_filter (thepid) != 0)
rc = 1;
}
mutt_copy_bytes (s->fpin, fpin, a->length);
if (!piped) {
- safe_fclose (&fpin);
+ m_fclose(&fpin);
thepid = mutt_create_filter (command, NULL, &fpout, &fperr);
}
else {
}
bail:
- safe_fclose (&fpout);
- safe_fclose (&fperr);
+ m_fclose(&fpout);
+ m_fclose(&fperr);
mutt_wait_filter (thepid);
if (piped)
- safe_fclose (&fpin);
+ m_fclose(&fpin);
else
mutt_unlink (tempfile);
static int imap_commit_message (MESSAGE* msg, CONTEXT* ctx) {
int r = 0;
- if ((r = safe_fclose (&msg->fp)) == 0)
+ if ((r = m_fclose(&msg->fp)) == 0)
r = imap_append_message (ctx, msg);
return (r);
}
return 0;
bail:
- safe_fclose (&msg->fp);
+ m_fclose(&msg->fp);
if (cache->path) {
unlink (cache->path);
p_delete(&cache->path);
sgn = 1;
}
}
- safe_fclose (&tfp);
+ m_fclose(&tfp);
unlink (tempfile);
if (!enc && !sgn)
}
if (pgpout) {
- safe_fclose (&pgpout);
+ m_fclose(&pgpout);
}
}
else {
if ((thepid = pgp_invoke_decode (&pgpin, NULL, &pgperr, -1,
fileno (pgpout), -1, tmpfname,
needpass)) == -1) {
- safe_fclose (&pgpout);
+ m_fclose(&pgpout);
maybe_goodsig = 0;
pgpin = NULL;
pgperr = NULL;
fprintf (pgpin, "%s\n", PgpPass);
}
- safe_fclose (&pgpin);
+ m_fclose(&pgpin);
if (s->flags & M_DISPLAY) {
crypt_current_time (s, "PGP");
rc = pgp_copy_checksig (pgperr, s->fpout);
}
- safe_fclose (&pgperr);
+ m_fclose(&pgperr);
rv = mutt_wait_filter (thepid);
if (s->flags & M_DISPLAY) {
m->goodsig = (maybe_goodsig && have_any_sigs);
if (tmpfp) {
- safe_fclose (&tmpfp);
+ m_fclose(&tmpfp);
mutt_unlink (tmpfname);
}
if (pgpout) {
- safe_fclose (&pgpout);
+ m_fclose(&pgpout);
mutt_unlink (outfile);
}
key = 1;
}
}
- safe_fclose (&tfp);
+ m_fclose(&tfp);
unlink (tempfile);
if (!enc && !sgn && !key)
badsig = 0;
- safe_fclose (&pgpout);
+ m_fclose(&pgpout);
fflush (pgperr);
rewind (pgperr);
badsig = -1;
}
- safe_fclose (&pgperr);
+ m_fclose(&pgperr);
state_attach_puts (_("[-- End of PGP output --]\n\n"), s);
send_charset = "us-ascii";
mutt_copy_stream (fp, pgpin);
}
- safe_fclose (&fp);
+ m_fclose(&fp);
fclose (pgpin);
pgpout = m_tempfile(pgpoutfile, sizeof(pgpoutfile), NONULL(Tempdir), NULL);
bye:
- safe_fclose (&in);
- safe_fclose (&out);
+ m_fclose(&in);
+ m_fclose(&out);
pgp_release_packet ();
return rv;
}
}
}
- safe_fclose (&fp);
+ m_fclose(&fp);
if (ask) {
if (public && *fields[4] == 'u')
b->length = tmplength;
b->offset = tmpoffset;
- safe_fclose (&tmpfp);
+ m_fclose(&tmpfp);
if (*fpout)
rewind (*fpout);
return (rv);
return fopen(path, mode);
}
-int safe_fclose(FILE **f)
-{
- int r = 0;
-
- if (*f)
- r = fclose (*f);
- *f = NULL;
- return r;
-}
-
/* If rfc1524_expand_command() is used on a recv'd message, then
* the filename doesn't exist yet, but if its used while sending a message,
* then we need to rename the existing file.
FILE *safe_fopen(const char *, const char *);
int mutt_rename_file(char *, char *);
-int safe_fclose(FILE **);
+
+static inline int m_fclose(FILE **f) {
+ if (*f) {
+ int res = fclose(*f);
+ *f = NULL;
+ return res;
+ }
+ return 0;
+}
char *mutt_read_line(char *, ssize_t *, FILE *, int *);
bail: /* Come here in case of disaster */
- safe_fclose (&fp);
+ m_fclose(&fp);
/* restore offsets, as far as they are valid */
if (first >= 0 && oldOffset) {
magic = M_MBOX;
else if (m_strcmp(MMDF_SEP, tmp) == 0)
magic = M_MMDF;
- safe_fclose (&f);
+ m_fclose(&f);
/* need to restore the times here, the file was not really accessed,
* only the type was accessed. This is important, because detection
}
p_delete(&buff);
- safe_fclose (&fp);
+ m_fclose(&fp);
}
int mh_buffy (const char *path)
fprintf (nfp, "%s\n", buff);
}
}
- safe_fclose (&ofp);
+ m_fclose(&ofp);
/* now, update our unseen, flagged, and replied sequences */
for (l = 0; l < ctx->msgcount; l++) {
/* try to commit the changes - no guarantee here */
- safe_fclose (&nfp);
+ m_fclose(&nfp);
unlink (sequences);
if (safe_rename (tmpfname, sequences) != 0) {
fprintf (nfp, "%s\n", buff);
}
}
- safe_fclose (&ofp);
+ m_fclose(&ofp);
p_delete(&buff);
if (!unseen_done && unseen)
if (!replied_done && replied)
fprintf (nfp, "%s: %d\n", NONULL (MhReplied), n);
- safe_fclose (&nfp);
+ m_fclose(&nfp);
unlink (sequences);
if (safe_rename (tmpfname, sequences) != 0)
char full[_POSIX_PATH_MAX];
char *s;
- if (safe_fclose (&msg->fp) != 0)
+ if (m_fclose(&msg->fp) != 0)
return -1;
/* extract the subdir */
char path[_POSIX_PATH_MAX];
char tmp[16];
- if (safe_fclose (&msg->fp) != 0)
+ if (m_fclose(&msg->fp) != 0)
return -1;
if ((dirp = opendir (ctx->path)) == NULL) {
FILE *fp = NULL;
if (mh_mkstemp (ctx, &fp, &tmp) == 0) {
- safe_fclose (&fp);
+ m_fclose(&fp);
if (safe_rename (tmp, buf) == -1)
unlink (tmp);
p_delete(&tmp);
mutt_perror (ctx->path);
else {
mutt_error (_("Couldn't lock %s\n"), ctx->path);
- safe_fclose (&ctx->fp);
+ m_fclose(&ctx->fp);
}
return (-1);
}
p_delete(&ctx->pattern);
if (ctx->limit_pattern)
mutt_pattern_free (&ctx->limit_pattern);
- safe_fclose (&ctx->fp);
+ m_fclose(&ctx->fp);
p_clear(ctx, 1);
}
|| (*msg)->magic == M_NNTP
#endif
) {
- r = safe_fclose (&(*msg)->fp);
+ r = m_fclose(&(*msg)->fp);
}
else
(*msg)->fp = NULL;
trailing_dot = q[-1] == '.';
if (!trailing_dot || q > p + 1) {
m_strncpy(s, n, p, q - trailing_dot - p);
- safe_fclose(&f);
+ m_fclose(&f);
return 0;
}
}
}
- safe_fclose (&f);
+ m_fclose(&f);
return -1;
}
if (ret == PQ_OK)
break;
- safe_fclose (&msg->fp);
+ m_fclose(&msg->fp);
unlink (path);
if (ret == PQ_ERR) {
else
mutt_decode_attachment (b, &s);
- if (safe_fclose (&s.fpout) != 0)
+ if (m_fclose(&s.fpout) != 0)
goto bail;
m_strreplace(&b->filename, file);
secured = !crypt_smime_decrypt_mime (_fp, &fp, _cur, &cur);
body_list_wipe(&_cur);
- safe_fclose (&_fp);
+ m_fclose(&_fp);
}
}
else
fseeko (fp, -1, SEEK_END);
if ((c = fgetc (fp)) != '\n')
fputc ('\n', fp);
- safe_fclose (&fp);
+ m_fclose(&fp);
}
int mutt_resend_message (FILE * fp, CONTEXT * ctx, HEADER * cur)
msg->env->from->personal = m_strdup(Realname);
if (!(flags & SENDKEY))
- safe_fclose (&tempfp);
+ m_fclose(&tempfp);
if (!(flags & SENDBATCH)) {
struct stat st;
}
}
- safe_fclose (&tempfp);
+ m_fclose(&tempfp);
header_delete(&msg);
return rv;
}
b->file_charset = fromcode;
p_delete(&tocode);
- safe_fclose (&fp);
+ m_fclose(&fp);
return info;
}
}
update_content_info (info, &state, buffer, r);
update_content_info (info, &state, 0, 0);
- safe_fclose (&fp);
+ m_fclose(&fp);
if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
parameter_setval(&b->parameter, "charset",