From: Pierre Habouzit Date: Fri, 24 Nov 2006 23:52:37 +0000 (+0100) Subject: safe_fclose -> m_fclose, and is now inlined. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=3766db5f849cea008b1cd3d532c712aeb17aa062;p=apps%2Fmadmutt.git safe_fclose -> m_fclose, and is now inlined. --- diff --git a/attach.c b/attach.c index febe91e..1d1ce66 100644 --- a/attach.c +++ b/attach.c @@ -614,7 +614,7 @@ int mutt_pipe_attachment (FILE * fp, BODY * b, const char *path, s.fpin = fp; mutt_decode_attachment (b, &s); - safe_fclose (&s.fpout); + m_fclose(&s.fpout); } else { /* send case */ @@ -638,13 +638,13 @@ int mutt_pipe_attachment (FILE * fp, BODY * b, const char *path, 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; @@ -760,19 +760,19 @@ int mutt_save_attachment (FILE * fp, BODY * m, char *path, int flags, 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; @@ -915,12 +915,12 @@ int mutt_print_attachment (FILE * fp, BODY * a) 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); } @@ -968,16 +968,16 @@ int mutt_print_attachment (FILE * fp, BODY * a) 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; } diff --git a/commands.c b/commands.c index 85ff46a..e0dfe2e 100644 --- a/commands.c +++ b/commands.c @@ -69,7 +69,7 @@ int mutt_display_message (HEADER * cur) -1, fileno (fpfilterout), -1); if (filterpid < 0) { mutt_error (_("Cannot create display filter")); - safe_fclose (&fpfilterout); + m_fclose(&fpfilterout); unlink (tempfile); return 0; } @@ -128,11 +128,11 @@ int mutt_display_message (HEADER * cur) 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 @@ -149,7 +149,7 @@ int mutt_display_message (HEADER * cur) 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 */ @@ -389,7 +389,7 @@ static int _mutt_pipe_message(HEADER * h, char *cmd, int decode, int print, /* add the message separator */ if (sep) fputs (sep, fpout); - safe_fclose (&fpout); + m_fclose(&fpout); if (mutt_wait_filter (thepid) != 0) rc = 1; } @@ -412,7 +412,7 @@ static int _mutt_pipe_message(HEADER * h, char *cmd, int decode, int print, fputs (sep, fpout); } } - safe_fclose (&fpout); + m_fclose(&fpout); if (mutt_wait_filter (thepid) != 0) rc = 1; } diff --git a/handler.c b/handler.c index cc0a3c1..0f37639 100644 --- a/handler.c +++ b/handler.c @@ -1083,7 +1083,7 @@ static int autoview_handler (BODY * a, STATE * s) 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 { @@ -1140,12 +1140,12 @@ static int autoview_handler (BODY * a, STATE * s) } 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); diff --git a/imap/imap.c b/imap/imap.c index c214ddf..e5cf4bf 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1621,7 +1621,7 @@ static int _imap_check_mailbox (CONTEXT* ctx, 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); } diff --git a/imap/message.c b/imap/message.c index 6c1fce7..1ea30c9 100644 --- a/imap/message.c +++ b/imap/message.c @@ -499,7 +499,7 @@ int imap_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) return 0; bail: - safe_fclose (&msg->fp); + m_fclose(&msg->fp); if (cache->path) { unlink (cache->path); p_delete(&cache->path); diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index c5c6986..a348e6f 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -1645,7 +1645,7 @@ static int pgp_check_traditional_one_body (FILE * fp, BODY * b, sgn = 1; } } - safe_fclose (&tfp); + m_fclose(&tfp); unlink (tempfile); if (!enc && !sgn) @@ -1946,7 +1946,7 @@ int pgp_gpgme_application_handler (BODY * m, STATE * s) } if (pgpout) { - safe_fclose (&pgpout); + m_fclose(&pgpout); } } else { diff --git a/lib-crypt/pgp.c b/lib-crypt/pgp.c index 23df747..85725d7 100644 --- a/lib-crypt/pgp.c +++ b/lib-crypt/pgp.c @@ -304,7 +304,7 @@ int pgp_application_pgp_handler (BODY * m, STATE * s) 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; @@ -322,14 +322,14 @@ int pgp_application_pgp_handler (BODY * m, STATE * s) 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) { @@ -430,11 +430,11 @@ out: 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); } @@ -486,7 +486,7 @@ static int pgp_check_traditional_one_body (FILE * fp, BODY * b, key = 1; } } - safe_fclose (&tfp); + m_fclose(&tfp); unlink (tempfile); if (!enc && !sgn && !key) @@ -563,7 +563,7 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) badsig = 0; - safe_fclose (&pgpout); + m_fclose(&pgpout); fflush (pgperr); rewind (pgperr); @@ -574,7 +574,7 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) badsig = -1; } - safe_fclose (&pgperr); + m_fclose(&pgperr); state_attach_puts (_("[-- End of PGP output --]\n\n"), s); @@ -1290,7 +1290,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) 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); diff --git a/lib-crypt/pgpmicalg.c b/lib-crypt/pgpmicalg.c index d2743f3..c30ae75 100644 --- a/lib-crypt/pgpmicalg.c +++ b/lib-crypt/pgpmicalg.c @@ -158,8 +158,8 @@ static short pgp_find_hash (const char *fname) bye: - safe_fclose (&in); - safe_fclose (&out); + m_fclose(&in); + m_fclose(&out); pgp_release_packet (); return rv; } diff --git a/lib-crypt/smime.c b/lib-crypt/smime.c index 82750c6..0080b6a 100644 --- a/lib-crypt/smime.c +++ b/lib-crypt/smime.c @@ -569,7 +569,7 @@ char *smime_get_field_from_db (char *mailbox, char *query, short public, } } - safe_fclose (&fp); + m_fclose(&fp); if (ask) { if (public && *fields[4] == 'u') @@ -1813,7 +1813,7 @@ bail: b->length = tmplength; b->offset = tmpoffset; - safe_fclose (&tmpfp); + m_fclose(&tmpfp); if (*fpout) rewind (*fpout); return (rv); diff --git a/lib-lib/file.c b/lib-lib/file.c index de3c75b..56bcf1f 100644 --- a/lib-lib/file.c +++ b/lib-lib/file.c @@ -232,16 +232,6 @@ FILE *safe_fopen(const char *path, const char *mode) 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. diff --git a/lib-lib/file.h b/lib-lib/file.h index 91a2d2a..2e7fb7e 100644 --- a/lib-lib/file.h +++ b/lib-lib/file.h @@ -48,7 +48,15 @@ void mutt_unlink(const char *); 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 *); diff --git a/lib-mx/mbox.c b/lib-mx/mbox.c index 14f00a9..d1b2746 100644 --- a/lib-mx/mbox.c +++ b/lib-mx/mbox.c @@ -763,7 +763,7 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)) 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) { @@ -1009,7 +1009,7 @@ int mbox_is_magic (const char* path, struct stat* st) { 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 diff --git a/lib-mx/mh.c b/lib-mx/mh.c index 2d79be8..c2abc74 100644 --- a/lib-mx/mh.c +++ b/lib-mx/mh.c @@ -151,7 +151,7 @@ static void mh_read_sequences (struct mh_sequences *mhs, const char *path) } p_delete(&buff); - safe_fclose (&fp); + m_fclose(&fp); } int mh_buffy (const char *path) @@ -292,7 +292,7 @@ static void mh_update_sequences (CONTEXT * ctx) 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++) { @@ -332,7 +332,7 @@ static void mh_update_sequences (CONTEXT * ctx) /* try to commit the changes - no guarantee here */ - safe_fclose (&nfp); + m_fclose(&nfp); unlink (sequences); if (safe_rename (tmpfname, sequences) != 0) { @@ -391,7 +391,7 @@ static void mh_sequences_add_one (CONTEXT * ctx, int n, short unseen, fprintf (nfp, "%s\n", buff); } } - safe_fclose (&ofp); + m_fclose(&ofp); p_delete(&buff); if (!unseen_done && unseen) @@ -401,7 +401,7 @@ static void mh_sequences_add_one (CONTEXT * ctx, int n, short 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) @@ -988,7 +988,7 @@ static int maildir_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr) char full[_POSIX_PATH_MAX]; char *s; - if (safe_fclose (&msg->fp) != 0) + if (m_fclose(&msg->fp) != 0) return -1; /* extract the subdir */ @@ -1056,7 +1056,7 @@ static int _mh_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr, 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) { @@ -1594,7 +1594,7 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint, int unused __attrib 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); diff --git a/lib-mx/mx.c b/lib-mx/mx.c index 3d10313..bd03117 100644 --- a/lib-mx/mx.c +++ b/lib-mx/mx.c @@ -430,7 +430,7 @@ static int mx_open_mailbox_append (CONTEXT * ctx, int flags) mutt_perror (ctx->path); else { mutt_error (_("Couldn't lock %s\n"), ctx->path); - safe_fclose (&ctx->fp); + m_fclose(&ctx->fp); } return (-1); } @@ -568,7 +568,7 @@ void mx_fastclose_mailbox (CONTEXT * ctx) 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); } @@ -1190,7 +1190,7 @@ int mx_close_message (MESSAGE ** msg) || (*msg)->magic == M_NNTP #endif ) { - r = safe_fclose (&(*msg)->fp); + r = m_fclose(&(*msg)->fp); } else (*msg)->fp = NULL; diff --git a/lib-sys/unix.c b/lib-sys/unix.c index 62a2f1e..38389b2 100644 --- a/lib-sys/unix.c +++ b/lib-sys/unix.c @@ -175,7 +175,7 @@ int getdnsdomainname(char *s, ssize_t n) 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; } @@ -183,6 +183,6 @@ int getdnsdomainname(char *s, ssize_t n) } } - safe_fclose (&f); + m_fclose(&f); return -1; } diff --git a/pop/pop.c b/pop/pop.c index be2d105..713743f 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -362,7 +362,7 @@ int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) if (ret == PQ_OK) break; - safe_fclose (&msg->fp); + m_fclose(&msg->fp); unlink (path); if (ret == PQ_ERR) { diff --git a/postpone.c b/postpone.c index 4f57af2..fd06b62 100644 --- a/postpone.c +++ b/postpone.c @@ -622,7 +622,7 @@ int mutt_prepare_template (FILE * fp, CONTEXT * ctx, HEADER * newhdr, 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); diff --git a/recvattach.c b/recvattach.c index 760651c..c07ad2f 100644 --- a/recvattach.c +++ b/recvattach.c @@ -938,7 +938,7 @@ void mutt_view_attachments (HEADER * hdr) secured = !crypt_smime_decrypt_mime (_fp, &fp, _cur, &cur); body_list_wipe(&_cur); - safe_fclose (&_fp); + m_fclose(&_fp); } } else diff --git a/send.c b/send.c index ce83c0c..f86d00c 100644 --- a/send.c +++ b/send.c @@ -1046,7 +1046,7 @@ static void fix_end_of_file (const char *data) 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) @@ -1370,7 +1370,7 @@ int ci_send_message (int flags, /* send mode */ msg->env->from->personal = m_strdup(Realname); if (!(flags & SENDKEY)) - safe_fclose (&tempfp); + m_fclose(&tempfp); if (!(flags & SENDBATCH)) { struct stat st; @@ -1785,7 +1785,7 @@ cleanup: } } - safe_fclose (&tempfp); + m_fclose(&tempfp); header_delete(&msg); return rv; diff --git a/sendlib.c b/sendlib.c index 042ca3a..f5bbd84 100644 --- a/sendlib.c +++ b/sendlib.c @@ -776,7 +776,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b) } b->file_charset = fromcode; p_delete(&tocode); - safe_fclose (&fp); + m_fclose(&fp); return info; } } @@ -786,7 +786,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b) 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",