From cfcc2d2009dedd885e3d1d99b118ba16c034979b Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Thu, 16 Nov 2017 02:07:04 +0000 Subject: [PATCH] rename file functions --- alias.c | 8 +- attach.c | 107 ++++++++-------- bcache.c | 6 +- browser.c | 19 +-- buffy.c | 2 +- commands.c | 18 +-- complete.c | 6 +- compose.c | 8 +- compress.c | 12 +- conn/ssl.c | 8 +- conn/ssl_gnutls.c | 12 +- copy.c | 14 +-- curs_lib.c | 2 +- edit.c | 2 +- editmsg.c | 6 +- handler.c | 38 +++--- hcache/bdb.c | 6 +- hcache/hcache.c | 2 +- header.c | 26 ++-- help.c | 4 +- history.c | 20 +-- hook.c | 2 +- imap/imap.c | 2 +- imap/message.c | 16 +-- init.c | 22 ++-- mailbox.h | 2 +- main.c | 18 +-- mbox.c | 31 ++--- mh.c | 38 +++--- mutt/file.c | 250 ++++++++++++++++++------------------ mutt/file.h | 60 ++++----- mutt_notmuch.c | 2 +- muttlib.c | 14 +-- mx.c | 8 +- ncrypt/crypt.c | 14 +-- ncrypt/crypt_gpgme.c | 82 ++++++------ ncrypt/gnupgparse.c | 2 +- ncrypt/pgp.c | 162 ++++++++++++------------ ncrypt/pgpinvoke.c | 6 +- ncrypt/pgpkey.c | 24 ++-- ncrypt/pgpmicalg.c | 6 +- ncrypt/smime.c | 294 +++++++++++++++++++++---------------------- newsrc.c | 30 ++--- nntp.c | 36 +++--- pager.c | 6 +- pattern.c | 8 +- pgppubring.c | 2 +- pop.c | 10 +- postpone.c | 6 +- query.c | 4 +- recvattach.c | 31 ++--- recvcmd.c | 18 +-- remailer.c | 2 +- rfc1524.c | 16 +-- rfc3676.c | 14 +-- send.c | 32 ++--- sendlib.c | 46 +++---- smtp.c | 12 +- 58 files changed, 832 insertions(+), 822 deletions(-) diff --git a/alias.c b/alias.c index 3e334e99c28..38234d0a86f 100644 --- a/alias.c +++ b/alias.c @@ -415,7 +415,7 @@ void mutt_create_alias(struct Envelope *cur, struct Address *iadr) if (fread(buf, 1, 1, rc) != 1) { mutt_perror(_("Error reading alias file")); - safe_fclose(&rc); + mutt_file_fclose(&rc); return; } if (fseek(rc, 0, SEEK_END) < 0) @@ -425,7 +425,7 @@ void mutt_create_alias(struct Envelope *cur, struct Address *iadr) } if (check_alias_name(new->name, NULL, 0)) - mutt_quote_filename(buf, sizeof(buf), new->name); + mutt_file_quote_filename(buf, sizeof(buf), new->name); else strfcpy(buf, new->name, sizeof(buf)); recode_buf(buf, sizeof(buf)); @@ -435,7 +435,7 @@ void mutt_create_alias(struct Envelope *cur, struct Address *iadr) recode_buf(buf, sizeof(buf)); write_safe_address(rc, buf); fputc('\n', rc); - if (safe_fsync_close(&rc) != 0) + if (mutt_file_fsync_close(&rc) != 0) mutt_message("Trouble adding alias: %s.", strerror(errno)); else mutt_message(_("Alias added.")); @@ -447,7 +447,7 @@ void mutt_create_alias(struct Envelope *cur, struct Address *iadr) fseek_err: mutt_perror(_("Error seeking in alias file")); - safe_fclose(&rc); + mutt_file_fclose(&rc); return; } diff --git a/attach.c b/attach.c index 223abd5b859..6358fb87031 100644 --- a/attach.c +++ b/attach.c @@ -70,9 +70,9 @@ int mutt_get_tmp_attachment(struct Body *a) if (stat(a->filename, &st) == -1) return -1; - if ((fpin = fopen(a->filename, "r")) && (fpout = safe_fopen(tempfile, "w"))) + if ((fpin = fopen(a->filename, "r")) && (fpout = mutt_file_fopen(tempfile, "w"))) { - mutt_copy_stream(fpin, fpout); + mutt_file_copy_stream(fpin, fpout); mutt_str_replace(&a->filename, tempfile); a->unlink = true; @@ -83,9 +83,9 @@ int mutt_get_tmp_attachment(struct Body *a) mutt_perror(fpin ? tempfile : a->filename); if (fpin) - safe_fclose(&fpin); + mutt_file_fclose(&fpin); if (fpout) - safe_fclose(&fpout); + mutt_file_fclose(&fpout); return a->unlink ? 0 : -1; } @@ -116,7 +116,7 @@ int mutt_compose_attachment(struct Body *a) if (rfc1524_expand_filename(entry->nametemplate, a->filename, newfile, sizeof(newfile))) { mutt_debug(1, "oldfile: %s\t newfile: %s\n", a->filename, newfile); - if (safe_symlink(a->filename, newfile) == -1) + if (mutt_file_symlink(a->filename, newfile) == -1) { if (mutt_yesorno(_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES) goto bailout; @@ -147,7 +147,7 @@ int mutt_compose_attachment(struct Body *a) FILE *fp = NULL, *tfp = NULL; char tempfile[_POSIX_PATH_MAX]; - fp = safe_fopen(a->filename, "r"); + fp = mutt_file_fopen(a->filename, "r"); if (!fp) { mutt_perror(_("Failure to open file to parse headers.")); @@ -181,17 +181,17 @@ int mutt_compose_attachment(struct Body *a) fseeko(fp, b->offset, SEEK_SET); mutt_free_body(&b); mutt_mktemp(tempfile, sizeof(tempfile)); - tfp = safe_fopen(tempfile, "w"); + tfp = mutt_file_fopen(tempfile, "w"); if (!tfp) { mutt_perror(_("Failure to open file to strip headers.")); goto bailout; } - mutt_copy_stream(fp, tfp); - safe_fclose(&fp); - safe_fclose(&tfp); - mutt_unlink(a->filename); - if (mutt_rename_file(tempfile, a->filename) != 0) + mutt_file_copy_stream(fp, tfp); + mutt_file_fclose(&fp); + mutt_file_fclose(&tfp); + mutt_file_unlink(a->filename); + if (mutt_file_rename(tempfile, a->filename) != 0) { mutt_perror(_("Failure to rename file.")); goto bailout; @@ -250,7 +250,7 @@ int mutt_edit_attachment(struct Body *a) if (rfc1524_expand_filename(entry->nametemplate, a->filename, newfile, sizeof(newfile))) { mutt_debug(1, "oldfile: %s\t newfile: %s\n", a->filename, newfile); - if (safe_symlink(a->filename, newfile) == -1) + if (mutt_file_symlink(a->filename, newfile) == -1) { if (mutt_yesorno(_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES) goto bailout; @@ -423,7 +423,7 @@ int mutt_view_attachment(FILE *fp, struct Body *a, int flag, struct Header *hdr, if (fp) { fname = safe_strdup(a->filename); - mutt_sanitize_filename(fname, 1); + mutt_file_sanitize_filename(fname, 1); } else fname = a->filename; @@ -433,7 +433,7 @@ int mutt_view_attachment(FILE *fp, struct Body *a, int flag, struct Header *hdr, if (fp == NULL && (mutt_strcmp(tempfile, a->filename) != 0)) { /* send case: the file is already there */ - if (safe_symlink(a->filename, tempfile) == -1) + if (mutt_file_symlink(a->filename, tempfile) == -1) { if (mutt_yesorno(_("Can't match nametemplate, continue?"), MUTT_YES) == MUTT_YES) strfcpy(tempfile, a->filename, sizeof(tempfile)); @@ -483,7 +483,7 @@ int mutt_view_attachment(FILE *fp, struct Body *a, int flag, struct Header *hdr, if (use_pager || use_pipe) { if (use_pager && - ((pagerfd = safe_open(pagerfile, O_CREAT | O_EXCL | O_WRONLY)) == -1)) + ((pagerfd = mutt_file_open(pagerfile, O_CREAT | O_EXCL | O_WRONLY)) == -1)) { mutt_perror("open"); goto return_error; @@ -555,11 +555,12 @@ int mutt_view_attachment(FILE *fp, struct Body *a, int flag, struct Header *hdr, struct State decode_state; memset(&decode_state, 0, sizeof(decode_state)); - decode_state.fpout = safe_fopen(pagerfile, "w"); + decode_state.fpout = mutt_file_fopen(pagerfile, "w"); if (!decode_state.fpout) { - mutt_debug(1, "mutt_view_attachment:%d safe_fopen(%s) errno=%d %s\n", - __LINE__, pagerfile, errno, strerror(errno)); + mutt_debug( + 1, "mutt_view_attachment:%d mutt_file_fopen(%s) errno=%d %s\n", + __LINE__, pagerfile, errno, strerror(errno)); mutt_perror(pagerfile); mutt_sleep(1); goto return_error; @@ -629,15 +630,15 @@ int mutt_view_attachment(FILE *fp, struct Body *a, int flag, struct Header *hdr, rfc1524_free_entry(&entry); if (fp && tempfile[0]) { - /* Restore write permission so mutt_unlink can open the file for writing */ + /* Restore write permission so mutt_file_unlink can open the file for writing */ chmod(tempfile, 0600); - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); } else if (unlink_tempfile) unlink(tempfile); if (pagerfile[0]) - mutt_unlink(pagerfile); + mutt_file_unlink(pagerfile); return rc; } @@ -655,7 +656,7 @@ int mutt_pipe_attachment(FILE *fp, struct Body *b, const char *path, char *outfi if (outfile && *outfile) { - out = safe_open(outfile, O_CREAT | O_EXCL | O_WRONLY); + out = mutt_file_open(outfile, O_CREAT | O_EXCL | O_WRONLY); if (out < 0) { mutt_perror("open"); @@ -688,7 +689,7 @@ int mutt_pipe_attachment(FILE *fp, struct Body *b, const char *path, char *outfi s.fpin = fp; mutt_decode_attachment(b, &s); - safe_fclose(&s.fpout); + mutt_file_fclose(&s.fpout); } else { @@ -716,13 +717,13 @@ int mutt_pipe_attachment(FILE *fp, struct Body *b, const char *path, char *outfi if (thepid < 0) { mutt_perror(_("Can't create filter")); - safe_fclose(&ifp); + mutt_file_fclose(&ifp); goto bail; } - mutt_copy_stream(ifp, ofp); - safe_fclose(&ofp); - safe_fclose(&ifp); + mutt_file_copy_stream(ifp, ofp); + mutt_file_fclose(&ofp); + mutt_file_fclose(&ifp); } rv = 1; @@ -750,7 +751,7 @@ static FILE *save_attachment_open(char *path, int flags) if (flags == MUTT_SAVE_OVERWRITE) return fopen(path, "w"); - return safe_fopen(path, "w"); + return mutt_file_fopen(path, "w"); } /** @@ -830,7 +831,7 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct fseeko((s.fpin = fp), m->offset, SEEK_SET); mutt_decode_attachment(m, &s); - if (safe_fsync_close(&s.fpout) != 0) + if (mutt_file_fsync_close(&s.fpout) != 0) { mutt_perror("fclose"); mutt_sleep(2); @@ -858,19 +859,19 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct if (!nfp) { mutt_perror("fopen"); - safe_fclose(&ofp); + mutt_file_fclose(&ofp); return -1; } - if (mutt_copy_stream(ofp, nfp) == -1) + if (mutt_file_copy_stream(ofp, nfp) == -1) { mutt_error(_("Write fault!")); - safe_fclose(&ofp); - safe_fclose(&nfp); + mutt_file_fclose(&ofp); + mutt_file_fclose(&nfp); return -1; } - safe_fclose(&ofp); - if (safe_fsync_close(&nfp) != 0) + mutt_file_fclose(&ofp); + if (mutt_file_fsync_close(&nfp) != 0) { mutt_error(_("Write fault!")); return -1; @@ -901,7 +902,7 @@ int mutt_decode_save_attachment(FILE *fp, struct Body *m, char *path, int displa else if (flags == MUTT_SAVE_OVERWRITE) s.fpout = fopen(path, "w"); else - s.fpout = safe_fopen(path, "w"); + s.fpout = mutt_file_fopen(path, "w"); if (!s.fpout) { @@ -918,7 +919,7 @@ int mutt_decode_save_attachment(FILE *fp, struct Body *m, char *path, int displa if (stat(m->filename, &st) == -1) { mutt_perror("stat"); - safe_fclose(&s.fpout); + mutt_file_fclose(&s.fpout); return -1; } @@ -950,7 +951,7 @@ int mutt_decode_save_attachment(FILE *fp, struct Body *m, char *path, int displa mutt_body_handler(m, &s); - if (safe_fsync_close(&s.fpout) != 0) + if (mutt_file_fsync_close(&s.fpout) != 0) { mutt_perror("fclose"); ret = -1; @@ -965,7 +966,7 @@ int mutt_decode_save_attachment(FILE *fp, struct Body *m, char *path, int displa m->parts = saved_parts; m->hdr = saved_hdr; } - safe_fclose(&s.fpin); + mutt_file_fclose(&s.fpin); } return ret; @@ -1004,7 +1005,7 @@ int mutt_print_attachment(FILE *fp, struct Body *a) { if (!fp) { - if (safe_symlink(a->filename, newfile) == -1) + if (mutt_file_symlink(a->filename, newfile) == -1) { if (mutt_yesorno(_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES) { @@ -1043,12 +1044,12 @@ int mutt_print_attachment(FILE *fp, struct Body *a) { mutt_perror(_("Can't create filter")); rfc1524_free_entry(&entry); - safe_fclose(&ifp); + mutt_file_fclose(&ifp); return 0; } - mutt_copy_stream(ifp, fpout); - safe_fclose(&fpout); - safe_fclose(&ifp); + mutt_file_copy_stream(ifp, fpout); + mutt_file_fclose(&fpout); + mutt_file_fclose(&ifp); if (mutt_wait_filter(thepid) || option(OPT_WAIT_KEY)) mutt_any_key_to_continue(NULL); } @@ -1063,7 +1064,7 @@ int mutt_print_attachment(FILE *fp, struct Body *a) } if (fp) - mutt_unlink(newfile); + mutt_file_unlink(newfile); else if (unlink_newfile) unlink(newfile); @@ -1109,19 +1110,19 @@ int mutt_print_attachment(FILE *fp, struct Body *a) mutt_debug(2, "Filter created.\n"); - mutt_copy_stream(ifp, fpout); + mutt_file_copy_stream(ifp, fpout); - safe_fclose(&fpout); - safe_fclose(&ifp); + mutt_file_fclose(&fpout); + mutt_file_fclose(&ifp); if (mutt_wait_filter(thepid) != 0 || option(OPT_WAIT_KEY)) mutt_any_key_to_continue(NULL); rc = 1; } bail0: - safe_fclose(&ifp); - safe_fclose(&fpout); - mutt_unlink(newfile); + mutt_file_fclose(&ifp); + mutt_file_fclose(&fpout); + mutt_file_unlink(newfile); return rc; } else @@ -1192,7 +1193,7 @@ void mutt_actx_free_entries(struct AttachCtx *actx) actx->vcount = 0; for (i = 0; i < actx->fp_len; i++) - safe_fclose(&actx->fp_idx[i]); + mutt_file_fclose(&actx->fp_idx[i]); actx->fp_len = 0; for (i = 0; i < actx->body_len; i++) diff --git a/bcache.c b/bcache.c index 0f970f717e9..1dd6bb8b1e8 100644 --- a/bcache.c +++ b/bcache.c @@ -143,7 +143,7 @@ FILE *mutt_bcache_get(struct BodyCache *bcache, const char *id) safe_strncat(path, sizeof(path), bcache->path, bcache->pathlen); safe_strncat(path, sizeof(path), id, mutt_strlen(id)); - fp = safe_fopen(path, "r"); + fp = mutt_file_fopen(path, "r"); mutt_debug(3, "bcache: get: '%s': %s\n", path, fp == NULL ? "no" : "yes"); @@ -174,7 +174,7 @@ FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id) } else { - if (mutt_mkdir(bcache->path, S_IRWXU | S_IRWXG | S_IRWXO) < 0) + if (mutt_file_mkdir(bcache->path, S_IRWXU | S_IRWXG | S_IRWXO) < 0) { mutt_error(_("Can't create %s %s"), bcache->path, strerror(errno)); return NULL; @@ -183,7 +183,7 @@ FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id) mutt_debug(3, "bcache: put: '%s'\n", path); - return safe_fopen(path, "w+"); + return mutt_file_fopen(path, "w+"); } int mutt_bcache_commit(struct BodyCache *bcache, const char *id) diff --git a/browser.c b/browser.c index d46209ee875..dd661f7405f 100644 --- a/browser.c +++ b/browser.c @@ -265,7 +265,7 @@ static int link_is_dir(const char *folder, const char *path) struct stat st; char fullpath[_POSIX_PATH_MAX]; - mutt_concat_path(fullpath, folder, path, sizeof(fullpath)); + mutt_file_concat_path(fullpath, folder, path, sizeof(fullpath)); if (stat(fullpath, &st) == 0) return (S_ISDIR(st.st_mode)); @@ -735,7 +735,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state, if (!((regexec(Mask.regex, de->d_name, 0, NULL, 0) == 0) ^ Mask.not)) continue; - mutt_concat_path(buffer, d, de->d_name, sizeof(buffer)); + mutt_file_concat_path(buffer, d, de->d_name, sizeof(buffer)); if (lstat(buffer, &s) == -1) continue; @@ -1347,7 +1347,8 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi } #endif else - mutt_concat_path(buf, LastDir, state.entry[menu->current].name, sizeof(buf)); + mutt_file_concat_path(buf, LastDir, state.entry[menu->current].name, + sizeof(buf)); if ((mx_get_magic(buf) <= 0) #ifdef USE_IMAP @@ -1406,7 +1407,8 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi else { char tmp[_POSIX_PATH_MAX]; - mutt_concat_path(tmp, LastDir, state.entry[menu->current].name, sizeof(tmp)); + mutt_file_concat_path(tmp, LastDir, + state.entry[menu->current].name, sizeof(tmp)); strfcpy(LastDir, tmp, sizeof(LastDir)); } @@ -1460,7 +1462,7 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi strfcpy(f, state.entry[menu->current].name, flen); #endif else - mutt_concat_path(f, LastDir, state.entry[menu->current].name, flen); + mutt_file_concat_path(f, LastDir, state.entry[menu->current].name, flen); /* Fall through to OP_EXIT */ @@ -1480,7 +1482,7 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi char full[_POSIX_PATH_MAX]; if (ff.tagged) { - mutt_concat_path(full, LastDir, ff.name, sizeof(full)); + mutt_file_concat_path(full, LastDir, ff.name, sizeof(full)); mutt_expand_path(full, sizeof(full)); tfiles[k++] = safe_strdup(full); } @@ -1647,7 +1649,7 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi /* in case dir is relative, make it relative to LastDir, * not current working dir */ char tmp[_POSIX_PATH_MAX]; - mutt_concat_path(tmp, LastDir, buf, sizeof(tmp)); + mutt_file_concat_path(tmp, LastDir, buf, sizeof(tmp)); strfcpy(buf, tmp, sizeof(buf)); } if (stat(buf, &st) == 0) @@ -1900,7 +1902,8 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi struct Body *b = NULL; char buf2[_POSIX_PATH_MAX]; - mutt_concat_path(buf2, LastDir, state.entry[menu->current].name, sizeof(buf2)); + mutt_file_concat_path(buf2, LastDir, state.entry[menu->current].name, + sizeof(buf2)); b = mutt_make_file_attach(buf2); if (b) { diff --git a/buffy.c b/buffy.c index 5e26c641118..97037c4df8a 100644 --- a/buffy.c +++ b/buffy.c @@ -148,7 +148,7 @@ static int test_new_folder(const char *path) if ((f = fopen(path, "rb"))) { rc = test_last_status_new(f); - safe_fclose(&f); + mutt_file_fclose(&f); } return rc; diff --git a/commands.c b/commands.c index e6e445d9cff..488282113be 100644 --- a/commands.c +++ b/commands.c @@ -126,7 +126,7 @@ int mutt_display_message(struct Header *cur) } mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = safe_fopen(tempfile, "w"); + fpout = mutt_file_fopen(tempfile, "w"); if (!fpout) { mutt_error(_("Could not create temporary file!")); @@ -142,7 +142,7 @@ int mutt_display_message(struct Header *cur) if (filterpid < 0) { mutt_error(_("Cannot create display filter")); - safe_fclose(&fpfilterout); + mutt_file_fclose(&fpfilterout); unlink(tempfile); return 0; } @@ -169,22 +169,22 @@ int mutt_display_message(struct Header *cur) #endif res = mutt_copy_message_ctx(fpout, Context, cur, cmflags, chflags); - if ((safe_fclose(&fpout) != 0 && errno != EPIPE) || res < 0) + if ((mutt_file_fclose(&fpout) != 0 && errno != EPIPE) || res < 0) { mutt_error(_("Could not copy message")); if (fpfilterout) { mutt_wait_filter(filterpid); - safe_fclose(&fpfilterout); + mutt_file_fclose(&fpfilterout); } - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); return 0; } if (fpfilterout != NULL && mutt_wait_filter(filterpid) != 0) mutt_any_key_to_continue(NULL); - safe_fclose(&fpfilterout); /* XXX - check result? */ + mutt_file_fclose(&fpfilterout); /* XXX - check result? */ if (WithCrypto) { @@ -420,7 +420,7 @@ static int pipe_message(struct Header *h, char *cmd, int decode, int print, set_option(OPT_KEEP_QUIET); pipe_msg(h, fpout, decode, print); - safe_fclose(&fpout); + mutt_file_fclose(&fpout); rc = mutt_wait_filter(thepid); unset_option(OPT_KEEP_QUIET); } @@ -464,7 +464,7 @@ static int pipe_message(struct Header *h, char *cmd, int decode, int print, /* add the message separator */ if (sep) fputs(sep, fpout); - safe_fclose(&fpout); + mutt_file_fclose(&fpout); if (mutt_wait_filter(thepid) != 0) rc = 1; unset_option(OPT_KEEP_QUIET); @@ -491,7 +491,7 @@ static int pipe_message(struct Header *h, char *cmd, int decode, int print, if (sep) fputs(sep, fpout); } - safe_fclose(&fpout); + mutt_file_fclose(&fpout); if (mutt_wait_filter(thepid) != 0) rc = 1; unset_option(OPT_KEEP_QUIET); diff --git a/complete.c b/complete.c index 9358ee756e4..a7b02ba785d 100644 --- a/complete.c +++ b/complete.c @@ -131,7 +131,7 @@ int mutt_complete(char *s, size_t slen) else p = NONULL(Folder); - mutt_concat_path(imap_path, p, s + 1, sizeof(imap_path)); + mutt_file_concat_path(imap_path, p, s + 1, sizeof(imap_path)); } else strfcpy(imap_path, s, sizeof(imap_path)); @@ -151,8 +151,8 @@ int mutt_complete(char *s, size_t slen) if ((p = strrchr(s, '/'))) { char buf[_POSIX_PATH_MAX]; - if (mutt_concatn_path(buf, sizeof(buf), exp_dirpart, strlen(exp_dirpart), - s + 1, (size_t)(p - s - 1)) == NULL) + if (mutt_file_concatn_path(buf, sizeof(buf), exp_dirpart, strlen(exp_dirpart), + s + 1, (size_t)(p - s - 1)) == NULL) { return -1; } diff --git a/compose.c b/compose.c index eca9724da68..af7d89471f9 100644 --- a/compose.c +++ b/compose.c @@ -1353,7 +1353,7 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ src = CURATTACH->content->d_filename; else src = CURATTACH->content->filename; - strfcpy(fname, mutt_basename(NONULL(src)), sizeof(fname)); + strfcpy(fname, mutt_file_basename(NONULL(src)), sizeof(fname)); ret = mutt_get_field(_("Send attachment with name: "), fname, sizeof(fname), MUTT_FILE); if (ret == 0) { @@ -1383,7 +1383,7 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ } mutt_expand_path(fname, sizeof(fname)); - if (mutt_rename_file(CURATTACH->content->filename, fname)) + if (mutt_file_rename(CURATTACH->content->filename, fname)) break; mutt_str_replace(&CURATTACH->content->filename, fname); @@ -1429,14 +1429,14 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ } new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); /* Touch the file */ - fp = safe_fopen(fname, "w"); + fp = mutt_file_fopen(fname, "w"); if (!fp) { mutt_error(_("Can't create file %s"), fname); FREE(&new); continue; } - safe_fclose(&fp); + mutt_file_fclose(&fp); new->content = mutt_make_file_attach(fname); if (!new->content) diff --git a/compress.c b/compress.c index 0e6f7b33bd3..b0ff20f3420 100644 --- a/compress.c +++ b/compress.c @@ -96,13 +96,13 @@ static int lock_realpath(struct Context *ctx, int excl) return 0; } - int r = mutt_lock_file(ctx->realpath, fileno(ci->lockfp), excl, 1); + int r = mutt_file_lock(ctx->realpath, fileno(ci->lockfp), excl, 1); if (r == 0) ci->locked = 1; else if (excl == 0) { - safe_fclose(&ci->lockfp); + mutt_file_fclose(&ci->lockfp); ctx->readonly = true; return 1; } @@ -128,10 +128,10 @@ static void unlock_realpath(struct Context *ctx) if (!ci->locked) return; - mutt_unlock_file(ctx->realpath, fileno(ci->lockfp)); + mutt_file_unlock(ctx->realpath, fileno(ci->lockfp)); ci->locked = 0; - safe_fclose(&ci->lockfp); + mutt_file_fclose(&ci->lockfp); } /** @@ -160,11 +160,11 @@ static int setup_paths(struct Context *ctx) mutt_mktemp(tmppath, sizeof(tmppath)); ctx->path = safe_strdup(tmppath); - tmpfp = safe_fopen(ctx->path, "w"); + tmpfp = mutt_file_fopen(ctx->path, "w"); if (!tmpfp) return -1; - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); return 0; } diff --git a/conn/ssl.c b/conn/ssl.c index 04b0a444c6e..049f62b773e 100644 --- a/conn/ssl.c +++ b/conn/ssl.c @@ -165,7 +165,7 @@ static int ssl_load_certificates(SSL_CTX *ctx) ERR_clear_error(); X509_free(cert); - safe_fclose(&fp); + mutt_file_fclose(&fp); return rv; } @@ -784,7 +784,7 @@ static int check_certificate_file(X509 *peercert) if (!X509_digest(peercert, EVP_sha256(), peermd, &peermdlen)) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return 0; } @@ -801,7 +801,7 @@ static int check_certificate_file(X509 *peercert) if (!pass) ERR_clear_error(); X509_free(cert); - safe_fclose(&fp); + mutt_file_fclose(&fp); return pass; } @@ -1079,7 +1079,7 @@ static int interactive_check_cert(X509 *cert, int idx, int len, SSL *ssl, int al { if (PEM_write_X509(fp, cert)) done = 1; - safe_fclose(&fp); + mutt_file_fclose(&fp); } if (!done) { diff --git a/conn/ssl_gnutls.c b/conn/ssl_gnutls.c index 972256e4432..1379750fe92 100644 --- a/conn/ssl_gnutls.c +++ b/conn/ssl_gnutls.c @@ -324,13 +324,13 @@ static int tls_check_stored_hostname(const gnutls_datum_t *cert, const char *hos "^#H ([a-zA-Z0-9_\\.-]+) ([0-9A-F]{4}( [0-9A-F]{4}){7})[ \t]*$", REG_ICASE) != 0) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return 0; } buf[0] = '\0'; tls_fingerprint(GNUTLS_DIG_MD5, buf, sizeof(buf), cert); - while ((linestr = mutt_read_line(linestr, &linestrsize, fp, &linenum, 0)) != NULL) + while ((linestr = mutt_file_read_line(linestr, &linestrsize, fp, &linenum, 0)) != NULL) { if (linestr[0] == '#' && linestr[1] == 'H') { @@ -343,7 +343,7 @@ static int tls_check_stored_hostname(const gnutls_datum_t *cert, const char *hos { regfree(&preg); FREE(&linestr); - safe_fclose(&fp); + mutt_file_fclose(&fp); return 1; } } @@ -351,7 +351,7 @@ static int tls_check_stored_hostname(const gnutls_datum_t *cert, const char *hos } regfree(&preg); - safe_fclose(&fp); + mutt_file_fclose(&fp); } /* not found a matching name */ @@ -389,7 +389,7 @@ static int tls_compare_certificates(const gnutls_datum_t *peercert) } b64_data.size = fread(b64_data.data, 1, b64_data.size, fd1); - safe_fclose(&fd1); + mutt_file_fclose(&fd1); do { @@ -849,7 +849,7 @@ static int tls_check_one_certificate(const gnutls_datum_t *certdata, gnutls_free(pemdata.data); } } - safe_fclose(&fp); + mutt_file_fclose(&fp); } if (!done) { diff --git a/copy.c b/copy.c index 9f6d06b52a9..7dfe711389d 100644 --- a/copy.c +++ b/copy.c @@ -700,14 +700,14 @@ int mutt_copy_message_fp(FILE *fpout, FILE *fpin, struct Header *hdr, int flags, if (fseeko(fp, cur->offset, SEEK_SET) < 0) return -1; - if (mutt_copy_bytes(fp, fpout, cur->length) == -1) + if (mutt_file_copy_bytes(fp, fpout, cur->length) == -1) { - safe_fclose(&fp); + mutt_file_fclose(&fp); mutt_free_body(&cur); return -1; } mutt_free_body(&cur); - safe_fclose(&fp); + mutt_file_fclose(&fp); } else { @@ -729,7 +729,7 @@ int mutt_copy_message_fp(FILE *fpout, FILE *fpin, struct Header *hdr, int flags, } } } - else if (mutt_copy_bytes(fpin, fpout, body->length) == -1) + else if (mutt_file_copy_bytes(fpin, fpout, body->length) == -1) return -1; } @@ -842,7 +842,7 @@ static int copy_delete_attach(struct Body *b, FILE *fpin, FILE *fpout, char *dat if (part->deleted || part->parts) { /* Copy till start of this part */ - if (mutt_copy_bytes(fpin, fpout, part->hdr_offset - ftello(fpin))) + if (mutt_file_copy_bytes(fpin, fpout, part->hdr_offset - ftello(fpin))) return -1; if (part->deleted) @@ -857,7 +857,7 @@ static int copy_delete_attach(struct Body *b, FILE *fpin, FILE *fpout, char *dat return -1; /* Copy the original mime headers */ - if (mutt_copy_bytes(fpin, fpout, part->offset - ftello(fpin))) + if (mutt_file_copy_bytes(fpin, fpout, part->offset - ftello(fpin))) return -1; /* Skip the deleted body */ @@ -872,7 +872,7 @@ static int copy_delete_attach(struct Body *b, FILE *fpin, FILE *fpout, char *dat } /* Copy the last parts */ - if (mutt_copy_bytes(fpin, fpout, b->offset + b->length - ftello(fpin))) + if (mutt_file_copy_bytes(fpin, fpout, b->offset + b->length - ftello(fpin))) return -1; return 0; diff --git a/curs_lib.c b/curs_lib.c index dc2ed1d82e9..2daa0da8514 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -890,7 +890,7 @@ int mutt_do_pager(const char *banner, const char *tempfile, int do_color, struct } else rc = 0; - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); } return rc; diff --git a/edit.c b/edit.c index edab0756bac..6027e64eca7 100644 --- a/edit.c +++ b/edit.c @@ -123,7 +123,7 @@ static char **be_snarf_file(const char *path, char **buf, int *max, int *len, in snprintf(tmp, sizeof(tmp), "\"%s\" %lu bytes\n", path, (unsigned long) sb.st_size); addstr(tmp); } - safe_fclose(&f); + mutt_file_fclose(&f); } else { diff --git a/editmsg.c b/editmsg.c index 629ea7a6262..5a787b4c72d 100644 --- a/editmsg.c +++ b/editmsg.c @@ -133,7 +133,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade } /* Do not reuse the stat sb here as it is outdated. */ - mtime = mutt_decrease_mtime(tmp, NULL); + mtime = mutt_file_decrease_mtime(tmp, NULL); mutt_edit_file(NONULL(Editor), tmp); @@ -220,7 +220,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade if (rc == 0) { fputc('\n', msg->fp); - mutt_copy_stream(fp, msg->fp); + mutt_file_copy_stream(fp, msg->fp); } rc = mx_commit_message(msg, &tmpctx); @@ -230,7 +230,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade bail: if (fp) - safe_fclose(&fp); + mutt_file_fclose(&fp); if (rc >= 0) unlink(tmp); diff --git a/handler.c b/handler.c index 3de4f14ae7e..aff2cde2330 100644 --- a/handler.c +++ b/handler.c @@ -164,7 +164,7 @@ static void decode_xbit(struct State *s, long len, int istext, iconv_t cd) state_reset_prefix(s); } else - mutt_copy_bytes(s->fpin, s->fpout, len); + mutt_file_copy_bytes(s->fpin, s->fpout, len); } static int qp_decode_triple(char *s, char *d) @@ -1155,7 +1155,7 @@ static int alternative_handler(struct Body *a, struct State *s) if (s->flags & MUTT_DISPLAY && !option(OPT_WEED)) { fseeko(s->fpin, choice->hdr_offset, SEEK_SET); - mutt_copy_bytes(s->fpin, s->fpout, choice->offset - choice->hdr_offset); + mutt_file_copy_bytes(s->fpin, s->fpout, choice->offset - choice->hdr_offset); } if (mutt_strcmp("info", ShowMultipartAlternative) == 0) @@ -1321,7 +1321,7 @@ static int multipart_handler(struct Body *a, struct State *s) if (!option(OPT_WEED)) { fseeko(s->fpin, p->hdr_offset, SEEK_SET); - mutt_copy_bytes(s->fpin, s->fpout, p->offset - p->hdr_offset); + mutt_file_copy_bytes(s->fpin, s->fpout, p->offset - p->hdr_offset); } else state_putc('\n', s); @@ -1370,7 +1370,7 @@ static int autoview_handler(struct Body *a, struct State *s) rfc1524_mailcap_lookup(a, type, entry, MUTT_AUTOVIEW); fname = safe_strdup(a->filename); - mutt_sanitize_filename(fname, 1); + mutt_file_sanitize_filename(fname, 1); rfc1524_expand_filename(entry->nametemplate, fname, tempfile, sizeof(tempfile)); FREE(&fname); @@ -1388,7 +1388,7 @@ static int autoview_handler(struct Body *a, struct State *s) mutt_message(_("Invoking autoview command: %s"), command); } - fpin = safe_fopen(tempfile, "w+"); + fpin = mutt_file_fopen(tempfile, "w+"); if (!fpin) { mutt_perror("fopen"); @@ -1396,11 +1396,11 @@ static int autoview_handler(struct Body *a, struct State *s) return -1; } - mutt_copy_bytes(s->fpin, fpin, a->length); + mutt_file_copy_bytes(s->fpin, fpin, a->length); if (!piped) { - safe_fclose(&fpin); + mutt_file_fclose(&fpin); thepid = mutt_create_filter(command, NULL, &fpout, &fperr); } else @@ -1450,7 +1450,7 @@ static int autoview_handler(struct Body *a, struct State *s) } else { - mutt_copy_stream(fpout, s->fpout); + mutt_file_copy_stream(fpout, s->fpout); /* Check for stderr messages */ if (fgets(buffer, sizeof(buffer), fperr)) { @@ -1461,19 +1461,19 @@ static int autoview_handler(struct Body *a, struct State *s) } state_puts(buffer, s); - mutt_copy_stream(fperr, s->fpout); + mutt_file_copy_stream(fperr, s->fpout); } } bail: - safe_fclose(&fpout); - safe_fclose(&fperr); + mutt_file_fclose(&fpout); + mutt_file_fclose(&fperr); mutt_wait_filter(thepid); if (piped) - safe_fclose(&fpin); + mutt_file_fclose(&fpin); else - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); if (s->flags & MUTT_DISPLAY) mutt_clear_error(); @@ -1634,7 +1634,7 @@ static int text_plain_handler(struct Body *b, struct State *s) char *buf = NULL; size_t l = 0, sz = 0; - while ((buf = mutt_read_line(buf, &sz, s->fpin, NULL, 0))) + while ((buf = mutt_file_read_line(buf, &sz, s->fpin, NULL, 0))) { if ((mutt_strcmp(buf, "-- ") != 0) && option(OPT_TEXT_FLOWED)) { @@ -1697,7 +1697,7 @@ static int run_decode_and_handler(struct Body *b, struct State *s, } #else mutt_mktemp(tempfile, sizeof(tempfile)); - s->fpout = safe_fopen(tempfile, "w"); + s->fpout = mutt_file_fopen(tempfile, "w"); if (!s->fpout) { mutt_error(_("Unable to open temporary file!")); @@ -1729,12 +1729,12 @@ static int run_decode_and_handler(struct Body *b, struct State *s, b->length = ftello(s->fpout); b->offset = 0; #ifdef USE_FMEMOPEN - /* When running under torify, safe_fclose(&s->fpout) does not seem to + /* When running under torify, mutt_file_fclose(&s->fpout) does not seem to * update tempsize. On the other hand, fflush does. See * https://github.com/neomutt/neomutt/issues/440 */ fflush(s->fpout); #endif - safe_fclose(&s->fpout); + mutt_file_fclose(&s->fpout); /* restore final destination and substitute the tempfile for input */ s->fpout = fp; @@ -1746,7 +1746,7 @@ static int run_decode_and_handler(struct Body *b, struct State *s, } else { /* fmemopen cannot handle zero-length buffers */ - s->fpin = safe_fopen("/dev/null", "r"); + s->fpin = mutt_file_fopen("/dev/null", "r"); } if (!s->fpin) { @@ -1780,7 +1780,7 @@ static int run_decode_and_handler(struct Body *b, struct State *s, b->offset = tmpoffset; /* restore the original source stream */ - safe_fclose(&s->fpin); + mutt_file_fclose(&s->fpin); #ifdef USE_FMEMOPEN FREE(&temp); #endif diff --git a/hcache/bdb.c b/hcache/bdb.c index 0f3b96cfb9f..830eeab58dc 100644 --- a/hcache/bdb.c +++ b/hcache/bdb.c @@ -91,7 +91,7 @@ static void *hcache_bdb_open(const char *path) return NULL; } - if (mutt_lock_file(ctx->lockfile, ctx->fd, 1, 5)) + if (mutt_file_lock(ctx->lockfile, ctx->fd, 1, 5)) goto fail_close; ret = db_env_create(&ctx->env, 0); @@ -124,7 +124,7 @@ static void *hcache_bdb_open(const char *path) fail_env: ctx->env->close(ctx->env, 0); fail_unlock: - mutt_unlock_file(ctx->lockfile, ctx->fd); + mutt_file_unlock(ctx->lockfile, ctx->fd); fail_close: close(ctx->fd); unlink(ctx->lockfile); @@ -199,7 +199,7 @@ static void hcache_bdb_close(void **vctx) ctx->db->close(ctx->db, 0); ctx->env->close(ctx->env, 0); - mutt_unlock_file(ctx->lockfile, ctx->fd); + mutt_file_unlock(ctx->lockfile, ctx->fd); close(ctx->fd); unlink(ctx->lockfile); FREE(vctx); diff --git a/hcache/hcache.c b/hcache/hcache.c index 57c1de43dd1..0c02d8d0c7a 100644 --- a/hcache/hcache.c +++ b/hcache/hcache.c @@ -545,7 +545,7 @@ static bool create_hcache_dir(const char *path) return true; *p = '\0'; - if (mutt_mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) == 0) + if (mutt_file_mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) == 0) return true; mutt_error(_("Can't create %s: %s."), dir, strerror(errno)); diff --git a/header.c b/header.c index c2f7de9df7e..53e681ee81d 100644 --- a/header.c +++ b/header.c @@ -55,7 +55,7 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, struct stat st; mutt_mktemp(path, sizeof(path)); - ofp = safe_fopen(path, "w"); + ofp = mutt_file_fopen(path, "w"); if (!ofp) { mutt_perror(path); @@ -71,14 +71,14 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, if (!ifp) { mutt_perror(body); - safe_fclose(&ofp); + mutt_file_fclose(&ofp); return; } - mutt_copy_stream(ifp, ofp); + mutt_file_copy_stream(ifp, ofp); - safe_fclose(&ifp); - safe_fclose(&ofp); + mutt_file_fclose(&ifp); + mutt_file_fclose(&ofp); if (stat(path, &st) == -1) { @@ -86,7 +86,7 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, return; } - mtime = mutt_decrease_mtime(path, &st); + mtime = mutt_file_decrease_mtime(path, &st); mutt_edit_file(editor, path); stat(path, &st); @@ -94,11 +94,11 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, { mutt_debug(1, "ci_edit_headers(): temp file was not modified.\n"); /* the file has not changed! */ - mutt_unlink(path); + mutt_file_unlink(path); return; } - mutt_unlink(body); + mutt_file_unlink(body); mutt_list_free(&msg->env->userhdrs); /* Read the temp file back in */ @@ -109,11 +109,11 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, return; } - ofp = safe_fopen(body, "w"); + ofp = mutt_file_fopen(body, "w"); if (!ofp) { /* intentionally leak a possible temporary file here */ - safe_fclose(&ifp); + mutt_file_fclose(&ifp); mutt_perror(body); return; } @@ -121,9 +121,9 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, n = mutt_read_rfc822_header(ifp, NULL, 1, 0); while ((i = fread(buffer, 1, sizeof(buffer), ifp)) > 0) fwrite(buffer, 1, i, ofp); - safe_fclose(&ofp); - safe_fclose(&ifp); - mutt_unlink(path); + mutt_file_fclose(&ofp); + mutt_file_fclose(&ifp); + mutt_file_unlink(path); /* in case the user modifies/removes the In-Reply-To header with $edit_headers set, we remove References: as they're likely invalid; diff --git a/help.c b/help.c index 318ba5d8e13..f5deea8173e 100644 --- a/help.c +++ b/help.c @@ -358,7 +358,7 @@ void mutt_help(int menu) do { - f = safe_fopen(t, "w"); + f = mutt_file_fopen(t, "w"); if (!f) { mutt_perror(t); @@ -378,7 +378,7 @@ void mutt_help(int menu) if (menu != MENU_PAGER) dump_unbound(f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]); - safe_fclose(&f); + mutt_file_fclose(&f); snprintf(buf, sizeof(buf), _("Help for %s"), desc); } while (mutt_do_pager(buf, t, MUTT_PAGER_RETWINCH | MUTT_PAGER_MARKER | MUTT_PAGER_NSKIP | MUTT_PAGER_NOWRAP, diff --git a/history.c b/history.c index 68701c27d8c..434b9a3c91d 100644 --- a/history.c +++ b/history.c @@ -124,7 +124,7 @@ void mutt_read_histfile(void) if (!f) return; - while ((linebuf = mutt_read_line(linebuf, &buflen, f, &line, 0)) != NULL) + while ((linebuf = mutt_file_read_line(linebuf, &buflen, f, &line, 0)) != NULL) { read = 0; if (sscanf(linebuf, "%d:%n", &hclass, &read) < 1 || read == 0 || @@ -146,7 +146,7 @@ void mutt_read_histfile(void) } } - safe_fclose(&f); + mutt_file_fclose(&f); FREE(&linebuf); } @@ -210,7 +210,7 @@ static void shrink_histfile(void) dup_hashes[hclass] = hash_create(MAX(10, SaveHistory * 2), MUTT_HASH_STRDUP_KEYS); line = 0; - while ((linebuf = mutt_read_line(linebuf, &buflen, f, &line, 0)) != NULL) + while ((linebuf = mutt_file_read_line(linebuf, &buflen, f, &line, 0)) != NULL) { if (sscanf(linebuf, "%d:%n", &hclass, &read) < 1 || read == 0 || *(p = linebuf + strlen(linebuf) - 1) != '|' || hclass < 0) @@ -242,7 +242,7 @@ static void shrink_histfile(void) if (regen_file) { mutt_mktemp(tmpfname, sizeof(tmpfname)); - tmp = safe_fopen(tmpfname, "w+"); + tmp = mutt_file_fopen(tmpfname, "w+"); if (!tmp) { mutt_perror(tmpfname); @@ -250,7 +250,7 @@ static void shrink_histfile(void) } rewind(f); line = 0; - while ((linebuf = mutt_read_line(linebuf, &buflen, f, &line, 0)) != NULL) + while ((linebuf = mutt_file_read_line(linebuf, &buflen, f, &line, 0)) != NULL) { if (sscanf(linebuf, "%d:%n", &hclass, &read) < 1 || read == 0 || *(p = linebuf + strlen(linebuf) - 1) != '|' || hclass < 0) @@ -271,17 +271,17 @@ static void shrink_histfile(void) } cleanup: - safe_fclose(&f); + mutt_file_fclose(&f); FREE(&linebuf); if (tmp) { if (fflush(tmp) == 0 && (f = fopen(HistoryFile, "w")) != NULL) { rewind(tmp); - mutt_copy_stream(tmp, f); - safe_fclose(&f); + mutt_file_copy_stream(tmp, f); + mutt_file_fclose(&f); } - safe_fclose(&tmp); + mutt_file_fclose(&tmp); unlink(tmpfname); } if (option(OPT_HISTORY_REMOVE_DUPS)) @@ -321,7 +321,7 @@ static void save_history(enum HistoryClass hclass, const char *s) } fputs("|\n", f); - safe_fclose(&f); + mutt_file_fclose(&f); FREE(&tmp); if (--n < 0) diff --git a/hook.c b/hook.c index d949eaa2a88..98c355ee922 100644 --- a/hook.c +++ b/hook.c @@ -490,7 +490,7 @@ void mutt_select_fcc(char *path, size_t pathlen, struct Header *hdr) { adr = env->to ? env->to : (env->cc ? env->cc : env->bcc); mutt_safe_path(buf, sizeof(buf), adr); - mutt_concat_path(path, NONULL(Folder), buf, pathlen); + mutt_file_concat_path(path, NONULL(Folder), buf, pathlen); if (!option(OPT_FORCE_NAME) && mx_access(path, W_OK) != 0) strfcpy(path, NONULL(Record), pathlen); } diff --git a/imap/imap.c b/imap/imap.c index f18005c72fc..239692685fc 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2367,7 +2367,7 @@ static int imap_open_new_message(struct Message *msg, struct Context *dest, stru char tmp[_POSIX_PATH_MAX]; mutt_mktemp(tmp, sizeof(tmp)); - msg->fp = safe_fopen(tmp, "w"); + msg->fp = mutt_file_fopen(tmp, "w"); if (!msg->fp) { mutt_perror(tmp); diff --git a/imap/message.c b/imap/message.c index ed98e6fe2b6..c3fb77af229 100644 --- a/imap/message.c +++ b/imap/message.c @@ -664,7 +664,7 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i /* instead of downloading all headers and then parsing them, we parse them * as they come in. */ mutt_mktemp(tempfile, sizeof(tempfile)); - fp = safe_fopen(tempfile, "w+"); + fp = mutt_file_fopen(tempfile, "w+"); if (!fp) { mutt_error(_("Could not create temporary file %s"), tempfile); @@ -978,7 +978,7 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i retval = msn_end; error_out_1: - safe_fclose(&fp); + mutt_file_fclose(&fp); error_out_0: FREE(&hdrreq); @@ -1055,7 +1055,7 @@ int imap_fetch_message(struct Context *ctx, struct Message *msg, int msgno) cache->uid = HEADER_DATA(h)->uid; mutt_mktemp(path, sizeof(path)); cache->path = safe_strdup(path); - msg->fp = safe_fopen(path, "w+"); + msg->fp = mutt_file_fopen(path, "w+"); if (!msg->fp) { FREE(&cache->path); @@ -1195,7 +1195,7 @@ int imap_fetch_message(struct Context *ctx, struct Message *msg, int msgno) return 0; bail: - safe_fclose(&msg->fp); + mutt_file_fclose(&msg->fp); imap_cache_del(idata, h); if (cache->path) { @@ -1215,7 +1215,7 @@ int imap_fetch_message(struct Context *ctx, struct Message *msg, int msgno) */ int imap_close_message(struct Context *ctx, struct Message *msg) { - return safe_fclose(&msg->fp); + return mutt_file_fclose(&msg->fp); } /** @@ -1228,7 +1228,7 @@ int imap_close_message(struct Context *ctx, struct Message *msg) */ int imap_commit_message(struct Context *ctx, struct Message *msg) { - int r = safe_fclose(&msg->fp); + int r = mutt_file_fclose(&msg->fp); if (r) return r; @@ -1326,7 +1326,7 @@ int imap_append_message(struct Context *ctx, struct Message *msg) pc = imap_next_word(pc); mutt_error("%s", pc); mutt_sleep(1); - safe_fclose(&fp); + mutt_file_fclose(&fp); goto fail; } @@ -1349,7 +1349,7 @@ int imap_append_message(struct Context *ctx, struct Message *msg) flush_buffer(buf, &len, idata->conn); mutt_socket_write(idata->conn, "\r\n"); - safe_fclose(&fp); + mutt_file_fclose(&fp); do rc = imap_cmd_step(idata); diff --git a/init.c b/init.c index 55f80b4f967..66c5fc029bf 100644 --- a/init.c +++ b/init.c @@ -630,8 +630,8 @@ int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags) /* read line */ mutt_buffer_init(&expn); - expn.data = mutt_read_line(NULL, &expn.dsize, fp, &line, 0); - safe_fclose(&fp); + expn.data = mutt_file_read_line(NULL, &expn.dsize, fp, &line, 0); + mutt_file_fclose(&fp); mutt_wait_filter(pid); /* if we got output, make a new string consisting of the shell output @@ -2319,7 +2319,7 @@ static void start_debug(void) rename(debugfilename, buf); } - debugfile = safe_fopen(debugfilename, "w"); + debugfile = mutt_file_fopen(debugfilename, "w"); if (debugfile) { setbuf(debugfile, NULL); /* don't buffer the debugging output! */ @@ -2345,7 +2345,7 @@ static void restart_debug(void) if (disable_debug || file_changed) { mutt_debug(1, "NeoMutt/%s stop debugging\n", PACKAGE_VERSION); - safe_fclose(&debugfile); + mutt_file_fclose(&debugfile); } if (!enable_debug && !disable_debug && debuglevel != DebugLevel) @@ -3139,7 +3139,7 @@ static int source_rc(const char *rcfile_path, struct Buffer *err) if (!ispipe) { struct ListNode *np = STAILQ_FIRST(&MuttrcStack); - if (!to_absolute_path(rcfile, np ? NONULL(np->data) : "")) + if (!mutt_file_to_absolute_path(rcfile, np ? NONULL(np->data) : "")) { mutt_error("Error: impossible to build path of '%s'.", rcfile_path); return -1; @@ -3173,7 +3173,7 @@ static int source_rc(const char *rcfile_path, struct Buffer *err) } mutt_buffer_init(&token); - while ((linebuf = mutt_read_line(linebuf, &buflen, f, &line, MUTT_CONT)) != NULL) + while ((linebuf = mutt_file_read_line(linebuf, &buflen, f, &line, MUTT_CONT)) != NULL) { conv = ConfigCharset && (*ConfigCharset) && Charset; if (conv) @@ -3217,7 +3217,7 @@ static int source_rc(const char *rcfile_path, struct Buffer *err) } FREE(&token.data); FREE(&linebuf); - safe_fclose(&f); + mutt_file_fclose(&f); if (pid != -1) mutt_wait_filter(pid); if (rc) @@ -4141,7 +4141,7 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) } else { - p = file_read_keyword(SYSCONFDIR "/nntpserver", buffer, sizeof(buffer)); + p = mutt_file_read_keyword(SYSCONFDIR "/nntpserver", buffer, sizeof(buffer)); NewsServer = safe_strdup(p); } #endif @@ -4153,9 +4153,9 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) else { #ifdef HOMESPOOL - mutt_concat_path(buffer, NONULL(HomeDir), MAILPATH, sizeof(buffer)); + mutt_file_concat_path(buffer, NONULL(HomeDir), MAILPATH, sizeof(buffer)); #else - mutt_concat_path(buffer, MAILPATH, NONULL(Username), sizeof(buffer)); + mutt_file_concat_path(buffer, MAILPATH, NONULL(Username), sizeof(buffer)); #endif SpoolFile = safe_strdup(buffer); } @@ -4346,7 +4346,7 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) mutt_exit(1); } - mutt_mkdir(Tmpdir, S_IRWXU); + mutt_file_mkdir(Tmpdir, S_IRWXU); mutt_read_histfile(); diff --git a/mailbox.h b/mailbox.h index dce45fba9e7..5a6cb22400e 100644 --- a/mailbox.h +++ b/mailbox.h @@ -36,7 +36,7 @@ struct Context; #define MUTT_READONLY (1 << 2) /**< open in read-only mode */ #define MUTT_QUIET (1 << 3) /**< do not print any messages */ #define MUTT_NEWFOLDER (1 << 4) /**< create a new folder - same as MUTT_APPEND, but uses - * safe_fopen() with mode "w" for mbox-style folders. + * mutt_file_fopen() with mode "w" for mbox-style folders. * This will truncate an existing file. */ #define MUTT_PEEK (1 << 5) /**< revert atime back after taking a look (if applicable) */ #define MUTT_APPENDNEW (1 << 6) /**< set in mx_open_mailbox_append if the mailbox doesn't diff --git a/main.c b/main.c index 5b6033b5e80..2104497647e 100644 --- a/main.c +++ b/main.c @@ -650,25 +650,25 @@ int main(int argc, char **argv, char **env) mutt_mktemp(buf, sizeof(buf)); tempfile = safe_strdup(buf); - fout = safe_fopen(tempfile, "w"); + fout = mutt_file_fopen(tempfile, "w"); if (!fout) { if (!option(OPT_NO_CURSES)) mutt_endwin(NULL); perror(tempfile); - safe_fclose(&fin); + mutt_file_fclose(&fin); FREE(&tempfile); exit(1); } if (fin) { - mutt_copy_stream(fin, fout); + mutt_file_copy_stream(fin, fout); if (fin != stdin) - safe_fclose(&fin); + mutt_file_fclose(&fin); } else if (bodytext) fputs(bodytext, fout); - safe_fclose(&fout); + mutt_file_fclose(&fout); fin = fopen(tempfile, "r"); if (!fin) @@ -748,7 +748,7 @@ int main(int argc, char **argv, char **env) bodyfile = tempfile; if (fin) - safe_fclose(&fin); + mutt_file_fclose(&fin); } FREE(&bodytext); @@ -797,7 +797,7 @@ int main(int argc, char **argv, char **env) perror(expanded_infile); exit(1); } - fout = safe_fopen(expanded_infile, "a"); + fout = mutt_file_fopen(expanded_infile, "a"); if (!fout) { if (!option(OPT_NO_CURSES)) @@ -826,10 +826,10 @@ int main(int argc, char **argv, char **env) { if (!option(OPT_NO_CURSES)) mutt_endwin(NULL); - safe_fclose(&fout); + mutt_file_fclose(&fout); exit(1); } - safe_fclose(&fout); + mutt_file_fclose(&fout); } mutt_free_header(&msg); diff --git a/mbox.c b/mbox.c index 7f128ed30e6..f1b1cb46b6f 100644 --- a/mbox.c +++ b/mbox.c @@ -74,7 +74,7 @@ static int mbox_lock_mailbox(struct Context *ctx, int excl, int retry) { int r; - r = mutt_lock_file(ctx->path, fileno(ctx->fp), excl, retry); + r = mutt_file_lock(ctx->path, fileno(ctx->fp), excl, retry); if (r == 0) ctx->locked = true; else if (retry && !excl) @@ -92,7 +92,7 @@ static void mbox_unlock_mailbox(struct Context *ctx) { fflush(ctx->fp); - mutt_unlock_file(ctx->path, fileno(ctx->fp)); + mutt_file_unlock(ctx->path, fileno(ctx->fp)); ctx->locked = false; } } @@ -459,7 +459,7 @@ static int mbox_open_mailbox(struct Context *ctx) rc = mmdf_parse_mailbox(ctx); else rc = -1; - mutt_touch_atime(fileno(ctx->fp)); + mutt_file_touch_atime(fileno(ctx->fp)); mbox_unlock_mailbox(ctx); mutt_unblock_signals(); @@ -468,7 +468,7 @@ static int mbox_open_mailbox(struct Context *ctx) static int mbox_open_mailbox_append(struct Context *ctx, int flags) { - ctx->fp = safe_fopen(ctx->path, flags & MUTT_NEWFOLDER ? "w" : "a"); + ctx->fp = mutt_file_fopen(ctx->path, flags & MUTT_NEWFOLDER ? "w" : "a"); if (!ctx->fp) { mutt_perror(ctx->path); @@ -478,7 +478,7 @@ static int mbox_open_mailbox_append(struct Context *ctx, int flags) if (mbox_lock_mailbox(ctx, 1, 1) != 0) { mutt_error(_("Couldn't lock %s\n"), ctx->path); - safe_fclose(&ctx->fp); + mutt_file_fclose(&ctx->fp); return -1; } @@ -496,11 +496,11 @@ static int mbox_close_mailbox(struct Context *ctx) if (ctx->append) { - mutt_unlock_file(ctx->path, fileno(ctx->fp)); + mutt_file_unlock(ctx->path, fileno(ctx->fp)); mutt_unblock_signals(); } - safe_fclose(&ctx->fp); + mutt_file_fclose(&ctx->fp); return 0; } @@ -730,8 +730,8 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint) case MUTT_MBOX: case MUTT_MMDF: cmp_headers = mbox_strict_cmp_headers; - safe_fclose(&ctx->fp); - ctx->fp = safe_fopen(ctx->path, "r"); + mutt_file_fclose(&ctx->fp); + ctx->fp = mutt_file_fopen(ctx->path, "r"); if (!ctx->fp) rc = -1; else @@ -754,7 +754,7 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint) return -1; } - mutt_touch_atime(fileno(ctx->fp)); + mutt_file_touch_atime(fileno(ctx->fp)); /* now try to recover the old flags */ @@ -1200,7 +1200,8 @@ static int mbox_sync_mailbox(struct Context *ctx, int *index_hint) if (fclose(fp) != 0) { fp = NULL; - mutt_debug(1, "mbox_sync_mailbox: safe_fclose (&) returned non-zero.\n"); + mutt_debug(1, + "mbox_sync_mailbox: mutt_file_fclose (&) returned non-zero.\n"); unlink(tempfile); mutt_perror(tempfile); mutt_sleep(5); @@ -1255,7 +1256,7 @@ static int mbox_sync_mailbox(struct Context *ctx, int *index_hint) */ if (!ctx->quiet) mutt_message(_("Committing changes...")); - i = mutt_copy_stream(fp, ctx->fp); + i = mutt_file_copy_stream(fp, ctx->fp); if (ferror(ctx->fp)) i = -1; @@ -1271,11 +1272,11 @@ static int mbox_sync_mailbox(struct Context *ctx, int *index_hint) } } - safe_fclose(&fp); + mutt_file_fclose(&fp); fp = NULL; mbox_unlock_mailbox(ctx); - if (safe_fclose(&ctx->fp) != 0 || i == -1) + if (mutt_file_fclose(&ctx->fp) != 0 || i == -1) { /* error occurred while writing the mailbox back, so keep the temp copy * around @@ -1339,7 +1340,7 @@ static int mbox_sync_mailbox(struct Context *ctx, int *index_hint) bail: /* Come here in case of disaster */ - safe_fclose(&fp); + mutt_file_fclose(&fp); /* restore offsets, as far as they are valid */ if (first >= 0 && oldOffset) diff --git a/mh.c b/mh.c index 28f5670ba7e..341be34ecc1 100644 --- a/mh.c +++ b/mh.c @@ -182,7 +182,7 @@ static int mh_read_sequences(struct MhSequences *mhs, const char *path) if (!fp) return 0; /* yes, ask callers to silently ignore the error */ - while ((buff = mutt_read_line(buff, &sz, fp, &line, 0))) + while ((buff = mutt_file_read_line(buff, &sz, fp, &line, 0))) { t = strtok(buff, " \t:"); if (!t) @@ -214,7 +214,7 @@ static int mh_read_sequences(struct MhSequences *mhs, const char *path) out: FREE(&buff); - safe_fclose(&fp); + mutt_file_fclose(&fp); return rc; } @@ -500,7 +500,7 @@ static void mh_update_sequences(struct Context *ctx) /* first, copy unknown sequences */ if ((ofp = fopen(sequences, "r"))) { - while ((buff = mutt_read_line(buff, &s, ofp, &l, 0))) + while ((buff = mutt_file_read_line(buff, &s, ofp, &l, 0))) { if (mutt_strncmp(buff, seq_unseen, mutt_strlen(seq_unseen)) == 0) continue; @@ -512,7 +512,7 @@ static void mh_update_sequences(struct Context *ctx) fprintf(nfp, "%s\n", buff); } } - safe_fclose(&ofp); + mutt_file_fclose(&ofp); /* now, update our unseen, flagged, and replied sequences */ for (l = 0; l < ctx->msgcount; l++) @@ -556,10 +556,10 @@ static void mh_update_sequences(struct Context *ctx) mhs_free_sequences(&mhs); /* try to commit the changes - no guarantee here */ - safe_fclose(&nfp); + mutt_file_fclose(&nfp); unlink(sequences); - if (safe_rename(tmpfname, sequences) != 0) + if (mutt_file_safe_rename(tmpfname, sequences) != 0) { /* report an error? */ unlink(tmpfname); @@ -598,7 +598,7 @@ static void mh_sequences_add_one(struct Context *ctx, int n, short unseen, snprintf(sequences, sizeof(sequences), "%s/.mh_sequences", ctx->path); if ((ofp = fopen(sequences, "r"))) { - while ((buff = mutt_read_line(buff, &sz, ofp, &line, 0))) + while ((buff = mutt_file_read_line(buff, &sz, ofp, &line, 0))) { if (unseen && (strncmp(buff, seq_unseen, mutt_strlen(seq_unseen)) == 0)) { @@ -619,7 +619,7 @@ static void mh_sequences_add_one(struct Context *ctx, int n, short unseen, fprintf(nfp, "%s\n", buff); } } - safe_fclose(&ofp); + mutt_file_fclose(&ofp); FREE(&buff); if (!unseen_done && unseen) @@ -629,10 +629,10 @@ static void mh_sequences_add_one(struct Context *ctx, int n, short unseen, if (!replied_done && replied) fprintf(nfp, "%s: %d\n", NONULL(MhSeqReplied), n); - safe_fclose(&nfp); + mutt_file_fclose(&nfp); unlink(sequences); - if (safe_rename(tmpfname, sequences) != 0) + if (mutt_file_safe_rename(tmpfname, sequences) != 0) unlink(tmpfname); FREE(&tmpfname); @@ -826,7 +826,7 @@ struct Header *maildir_parse_message(int magic, const char *fname, bool is_old, if (f) { h = maildir_parse_stream(magic, f, fname, is_old, h); - safe_fclose(&f); + mutt_file_fclose(&f); return h; } return NULL; @@ -1481,7 +1481,7 @@ static int mh_open_message(struct Context *ctx, struct Message *msg, int msgno) static int mh_close_message(struct Context *ctx, struct Message *msg) { - return safe_fclose(&msg->fp); + return mutt_file_fclose(&msg->fp); } /** @@ -1584,7 +1584,7 @@ static int md_commit_message(struct Context *ctx, struct Message *msg, struct He char full[_POSIX_PATH_MAX]; char *s = NULL; - if (safe_fsync_close(&msg->fp)) + if (mutt_file_fsync_close(&msg->fp)) { mutt_perror(_("Could not flush message to disk")); return -1; @@ -1609,7 +1609,7 @@ static int md_commit_message(struct Context *ctx, struct Message *msg, struct He mutt_debug(2, "md_commit_message (): renaming %s to %s.\n", msg->path, full); - if (safe_rename(msg->path, full) == 0) + if (mutt_file_safe_rename(msg->path, full) == 0) { /* * Adjust the mtime on the file to match the time at which this @@ -1671,7 +1671,7 @@ static int mh_commit_msg(struct Context *ctx, struct Message *msg, char path[_POSIX_PATH_MAX]; char tmp[16]; - if (safe_fsync_close(&msg->fp)) + if (mutt_file_fsync_close(&msg->fp)) { mutt_perror(_("Could not flush message to disk")); return -1; @@ -1718,7 +1718,7 @@ static int mh_commit_msg(struct Context *ctx, struct Message *msg, hi++; snprintf(tmp, sizeof(tmp), "%d", hi); snprintf(path, sizeof(path), "%s/%s", ctx->path, tmp); - if (safe_rename(msg->path, path) == 0) + if (mutt_file_safe_rename(msg->path, path) == 0) { if (hdr) mutt_str_replace(&hdr->path, tmp); @@ -1804,7 +1804,7 @@ static int mh_rewrite_message(struct Context *ctx, int msgno) if (ctx->magic == MUTT_MH && rc == 0) { snprintf(newpath, _POSIX_PATH_MAX, "%s/%s", ctx->path, h->path); - rc = safe_rename(newpath, oldpath); + rc = mutt_file_safe_rename(newpath, oldpath); if (rc == 0) mutt_str_replace(&h->path, partpath); } @@ -2218,8 +2218,8 @@ static int mh_check_mailbox(struct Context *ctx, int *index_hint) if (mh_mkstemp(ctx, &fp, &tmp) == 0) { - safe_fclose(&fp); - if (safe_rename(tmp, buf) == -1) + mutt_file_fclose(&fp); + if (mutt_file_safe_rename(tmp, buf) == -1) unlink(tmp); FREE(&tmp); } diff --git a/mutt/file.c b/mutt/file.c index 2c1ea43b8cd..2f0ffac9930 100644 --- a/mutt/file.c +++ b/mutt/file.c @@ -25,37 +25,37 @@ * * Commonly used file/dir management routines. * - * | Function | Description - * | :--------------------------- | :----------------------------------------------------------- - * | file_read_keyword() | Read a keyword from a file - * | mbox_check_empty() | Is the mailbox empty - * | mutt_basename() | Find the last component for a pathname - * | mutt_concatn_path() | Concatenate directory and filename - * | mutt_concat_path() | Join a directory name and a filename - * | mutt_copy_bytes() | Copy some content from one file to another - * | mutt_copy_stream() | Copy the contents of one file into another - * | mutt_decrease_mtime() | Decrease a file's modification time by 1 second - * | mutt_dirname() | Return a path up to, but not including, the final '/' - * | mutt_lock_file() | (try to) lock a file - * | mutt_mkdir() | Recursively create directories - * | mutt_quote_filename() | Quote a filename to survive the shell's quoting rules - * | mutt_read_line() | Read a line from a file - * | mutt_regex_sanitize_string() | Escape any regex-magic characters in a string - * | mutt_rename_file() | Rename a file - * | mutt_rmtree() | Recursively remove a directory - * | mutt_sanitize_filename() | Replace unsafe characters in a filename - * | mutt_set_mtime() | Set the modification time of one file from another - * | mutt_touch_atime() | Set the access time to current time - * | mutt_unlink() | Delete a file, carefully - * | mutt_unlink_empty() | Delete a file if it's empty - * | mutt_unlock_file() | Unlock a file previously locked by mutt_lock_file() - * | safe_fclose() | Close a FILE handle (and NULL the pointer) - * | safe_fopen() | Call fopen() safely - * | safe_fsync_close() | Flush the data, before closing a file (and NULL the pointer) - * | safe_open() | Open a file - * | safe_rename() | NFS-safe renaming of files - * | safe_symlink() | Create a symlink - * | to_absolute_path() | Convert relative filepath to an absolute path + * | Function | Description + * | :---------------------------- | :----------------------------------------------------------- + * | mutt_file_basename() | Find the last component for a pathname + * | mutt_file_check_empty() | Is the mailbox empty + * | mutt_file_concatn_path() | Concatenate directory and filename + * | mutt_file_concat_path() | Join a directory name and a filename + * | mutt_file_copy_bytes() | Copy some content from one file to another + * | mutt_file_copy_stream() | Copy the contents of one file into another + * | mutt_file_decrease_mtime() | Decrease a file's modification time by 1 second + * | mutt_file_dirname() | Return a path up to, but not including, the final '/' + * | mutt_file_fclose() | Close a FILE handle (and NULL the pointer) + * | mutt_file_fopen() | Call fopen() safely + * | mutt_file_fsync_close() | Flush the data, before closing a file (and NULL the pointer) + * | mutt_file_lock() | (try to) lock a file + * | mutt_file_mkdir() | Recursively create directories + * | mutt_file_open() | Open a file + * | mutt_file_quote_filename() | Quote a filename to survive the shell's quoting rules + * | mutt_file_read_keyword() | Read a keyword from a file + * | mutt_file_read_line() | Read a line from a file + * | mutt_file_rename() | Rename a file + * | mutt_file_rmtree() | Recursively remove a directory + * | mutt_file_safe_rename() | NFS-safe renaming of files + * | mutt_file_sanitize_filename() | Replace unsafe characters in a filename + * | mutt_file_sanitize_regex() | Escape any regex-magic characters in a string + * | mutt_file_set_mtime() | Set the modification time of one file from another + * | mutt_file_symlink() | Create a symlink + * | mutt_file_touch_atime() | Set the access time to current time + * | mutt_file_to_absolute_path() | Convert relative filepath to an absolute path + * | mutt_file_unlink() | Delete a file, carefully + * | mutt_file_unlink_empty() | Delete a file if it's empty + * | mutt_file_unlock() | Unlock a file previously locked by mutt_file_lock() */ #include "config.h" @@ -165,19 +165,19 @@ static int put_file_in_place(const char *path, const char *safe_file, const char { int rv; - rv = safe_rename(safe_file, path); + rv = mutt_file_safe_rename(safe_file, path); unlink(safe_file); rmdir(safe_dir); return rv; } /** - * safe_fclose - Close a FILE handle (and NULL the pointer) + * mutt_file_fclose - Close a FILE handle (and NULL the pointer) * @param f FILE handle to close * @retval 0 Success * @retval EOF Error, see errno */ -int safe_fclose(FILE **f) +int mutt_file_fclose(FILE **f) { int r = 0; @@ -189,12 +189,12 @@ int safe_fclose(FILE **f) } /** - * safe_fsync_close - Flush the data, before closing a file (and NULL the pointer) + * mutt_file_fsync_close - Flush the data, before closing a file (and NULL the pointer) * @param f FILE handle to close * @retval 0 Success * @retval EOF Error, see errno */ -int safe_fsync_close(FILE **f) +int mutt_file_fsync_close(FILE **f) { int r = 0; @@ -204,23 +204,23 @@ int safe_fsync_close(FILE **f) { int save_errno = errno; r = -1; - safe_fclose(f); + mutt_file_fclose(f); errno = save_errno; } else - r = safe_fclose(f); + r = mutt_file_fclose(f); } return r; } /** - * mutt_unlink - Delete a file, carefully + * mutt_file_unlink - Delete a file, carefully * @param s Filename * * This won't follow symlinks. */ -void mutt_unlink(const char *s) +void mutt_file_unlink(const char *s) { int fd; FILE *f = NULL; @@ -252,20 +252,20 @@ void mutt_unlink(const char *s) fwrite(buf, 1, MIN(sizeof(buf), sb.st_size), f); sb.st_size -= MIN(sizeof(buf), sb.st_size); } - safe_fclose(&f); + mutt_file_fclose(&f); } } } /** - * mutt_copy_bytes - Copy some content from one file to another + * mutt_file_copy_bytes - Copy some content from one file to another * @param in Source file * @param out Destination file * @param size Maximum number of bytes to copy * @retval 0 Success * @retval -1 Error, see errno */ -int mutt_copy_bytes(FILE *in, FILE *out, size_t size) +int mutt_file_copy_bytes(FILE *in, FILE *out, size_t size) { char buf[2048]; size_t chunk; @@ -288,13 +288,13 @@ int mutt_copy_bytes(FILE *in, FILE *out, size_t size) } /** - * mutt_copy_stream - Copy the contents of one file into another + * mutt_file_copy_stream - Copy the contents of one file into another * @param fin Source file * @param fout Destination file * @retval 0 Success * @retval -1 Error, see errno */ -int mutt_copy_stream(FILE *fin, FILE *fout) +int mutt_file_copy_stream(FILE *fin, FILE *fout) { size_t l; char buf[LONG_STRING]; @@ -311,13 +311,13 @@ int mutt_copy_stream(FILE *fin, FILE *fout) } /** - * safe_symlink - Create a symlink + * mutt_file_symlink - Create a symlink * @param oldpath Existing pathname * @param newpath New pathname * @retval 0 Success * @retval -1 Error, see errno */ -int safe_symlink(const char *oldpath, const char *newpath) +int mutt_file_symlink(const char *oldpath, const char *newpath) { struct stat osb, nsb; @@ -359,7 +359,7 @@ int safe_symlink(const char *oldpath, const char *newpath) } /** - * safe_rename - NFS-safe renaming of files + * mutt_file_safe_rename - NFS-safe renaming of files * @param src Original filename * @param target New filename * @retval 0 Success @@ -367,7 +367,7 @@ int safe_symlink(const char *oldpath, const char *newpath) * * Warning: We don't check whether src and target are equal. */ -int safe_rename(const char *src, const char *target) +int mutt_file_safe_rename(const char *src, const char *target) { struct stat ssb, tsb; @@ -384,8 +384,8 @@ int safe_rename(const char *src, const char *target) * With other file systems, rename should just fail when * the files reside on different file systems, so it's safe * to try it here. */ - mutt_debug(1, "safe_rename: link (%s, %s) failed: %s (%d)\n", src, target, - strerror(errno), errno); + mutt_debug(1, "mutt_file_safe_rename: link (%s, %s) failed: %s (%d)\n", src, + target, strerror(errno), errno); /* FUSE may return ENOSYS. VFAT may return EPERM. FreeBSD's * msdosfs may return EOPNOTSUPP. ENOTSUP can also appear. */ @@ -398,14 +398,15 @@ int safe_rename(const char *src, const char *target) #endif ) { - mutt_debug(1, "safe_rename: trying rename...\n"); + mutt_debug(1, "mutt_file_safe_rename: trying rename...\n"); if (rename(src, target) == -1) { - mutt_debug(1, "safe_rename: rename (%s, %s) failed: %s (%d)\n", src, - target, strerror(errno), errno); + mutt_debug(1, + "mutt_file_safe_rename: rename (%s, %s) failed: %s (%d)\n", + src, target, strerror(errno), errno); return -1; } - mutt_debug(1, "safe_rename: rename succeeded.\n"); + mutt_debug(1, "mutt_file_safe_rename: rename succeeded.\n"); return 0; } @@ -417,13 +418,15 @@ int safe_rename(const char *src, const char *target) if (lstat(src, &ssb) == -1) { - mutt_debug(1, "safe_rename: can't stat %s: %s (%d)\n", src, strerror(errno), errno); + mutt_debug(1, "mutt_file_safe_rename: can't stat %s: %s (%d)\n", src, + strerror(errno), errno); return -1; } if (lstat(target, &tsb) == -1) { - mutt_debug(1, "safe_rename: can't stat %s: %s (%d)\n", src, strerror(errno), errno); + mutt_debug(1, "mutt_file_safe_rename: can't stat %s: %s (%d)\n", src, + strerror(errno), errno); return -1; } @@ -431,7 +434,7 @@ int safe_rename(const char *src, const char *target) if (!compare_stat(&ssb, &tsb)) { - mutt_debug(1, "safe_rename: stat blocks for %s and %s diverge; " + mutt_debug(1, "mutt_file_safe_rename: stat blocks for %s and %s diverge; " "pretending EEXIST.\n", src, target); errno = EEXIST; @@ -442,19 +445,20 @@ int safe_rename(const char *src, const char *target) * Should we really ignore the return value here? XXX */ if (unlink(src) == -1) { - mutt_debug(1, "safe_rename: unlink (%s) failed: %s (%d)\n", src, strerror(errno), errno); + mutt_debug(1, "mutt_file_safe_rename: unlink (%s) failed: %s (%d)\n", src, + strerror(errno), errno); } return 0; } /** - * mutt_rmtree - Recursively remove a directory + * mutt_file_rmtree - Recursively remove a directory * @param path Directory to delete * @retval 0 Success * @retval -1 Error, see errno */ -int mutt_rmtree(const char *path) +int mutt_file_rmtree(const char *path) { DIR *dirp = NULL; struct dirent *de = NULL; @@ -465,7 +469,7 @@ int mutt_rmtree(const char *path) dirp = opendir(path); if (!dirp) { - mutt_debug(1, "mutt_rmtree: error opening directory %s\n", path); + mutt_debug(1, "mutt_file_rmtree: error opening directory %s\n", path); return -1; } while ((de = readdir(dirp))) @@ -483,7 +487,7 @@ int mutt_rmtree(const char *path) } if (S_ISDIR(statbuf.st_mode)) - rc |= mutt_rmtree(cur); + rc |= mutt_file_rmtree(cur); else rc |= unlink(cur); } @@ -495,13 +499,13 @@ int mutt_rmtree(const char *path) } /** - * safe_open - Open a file + * mutt_file_open - Open a file * @param path Pathname to open * @param flags Flags, e.g. O_EXCL * @retval >0 Success, file handle * @retval -1 Error */ -int safe_open(const char *path, int flags) +int mutt_file_open(const char *path, int flags) { struct stat osb, nsb; int fd; @@ -542,7 +546,7 @@ int safe_open(const char *path, int flags) } /** - * safe_fopen - Call fopen() safely + * mutt_file_fopen - Call fopen() safely * @param path Filename * @param mode Mode e.g. "r" readonly; "w" read-write * @retval ptr FILE handle @@ -551,7 +555,7 @@ int safe_open(const char *path, int flags) * When opening files for writing, make sure the file doesn't already exist to * avoid race conditions. */ -FILE *safe_fopen(const char *path, const char *mode) +FILE *mutt_file_fopen(const char *path, const char *mode) { if (mode[0] == 'w') { @@ -563,7 +567,7 @@ FILE *safe_fopen(const char *path, const char *mode) else flags |= O_WRONLY; - fd = safe_open(path, flags); + fd = mutt_file_open(path, flags); if (fd < 0) return NULL; @@ -574,11 +578,11 @@ FILE *safe_fopen(const char *path, const char *mode) } /** - * mutt_sanitize_filename - Replace unsafe characters in a filename + * mutt_file_sanitize_filename - Replace unsafe characters in a filename * @param f Filename to make safe * @param slash Replace '/' characters too */ -void mutt_sanitize_filename(char *f, short slash) +void mutt_file_sanitize_filename(char *f, short slash) { if (!f) return; @@ -591,14 +595,14 @@ void mutt_sanitize_filename(char *f, short slash) } /** - * mutt_regex_sanitize_string - Escape any regex-magic characters in a string + * mutt_file_sanitize_regex - Escape any regex-magic characters in a string * @param dest Buffer for result * @param destlen Length of buffer * @param src String to transform * @retval 0 Success * @retval -1 Error */ -int mutt_regex_sanitize_string(char *dest, size_t destlen, const char *src) +int mutt_file_sanitize_regex(char *dest, size_t destlen, const char *src) { while (*src && (--destlen > 2)) { @@ -619,7 +623,7 @@ int mutt_regex_sanitize_string(char *dest, size_t destlen, const char *src) } /** - * mutt_read_line - Read a line from a file + * mutt_file_read_line - Read a line from a file * @param[out] s Buffer allocated on the head (optional) * @param[in] size Length of buffer (optional) * @param[in] fp File to read @@ -632,7 +636,7 @@ int mutt_regex_sanitize_string(char *dest, size_t destlen, const char *src) * with "\", this char and the linefeed is removed, and the next line is read * too. */ -char *mutt_read_line(char *s, size_t *size, FILE *fp, int *line, int flags) +char *mutt_file_read_line(char *s, size_t *size, FILE *fp, int *line, int flags) { size_t offset = 0; char *ch = NULL; @@ -692,7 +696,7 @@ char *mutt_read_line(char *s, size_t *size, FILE *fp, int *line, int flags) } /** - * mutt_quote_filename - Quote a filename to survive the shell's quoting rules + * mutt_file_quote_filename - Quote a filename to survive the shell's quoting rules * @param d Buffer for the result * @param l Length of buffer * @param f String to convert @@ -700,7 +704,7 @@ char *mutt_read_line(char *s, size_t *size, FILE *fp, int *line, int flags) * * From the Unix programming FAQ by way of Liviu. */ -size_t mutt_quote_filename(char *d, size_t l, const char *f) +size_t mutt_file_quote_filename(char *d, size_t l, const char *f) { size_t j = 0; @@ -735,7 +739,7 @@ size_t mutt_quote_filename(char *d, size_t l, const char *f) } /** - * mutt_concatn_path - Concatenate directory and filename + * mutt_file_concatn_path - Concatenate directory and filename * @param dst Buffer for result * @param dstlen Buffer length * @param dir Directory @@ -748,8 +752,8 @@ size_t mutt_quote_filename(char *d, size_t l, const char *f) * Write the concatenated pathname (dir + "/" + fname) into dst. * The slash is omitted when dir or fname is of 0 length. */ -char *mutt_concatn_path(char *dst, size_t dstlen, const char *dir, - size_t dirlen, const char *fname, size_t fnamelen) +char *mutt_file_concatn_path(char *dst, size_t dstlen, const char *dir, + size_t dirlen, const char *fname, size_t fnamelen) { size_t req; size_t offset = 0; @@ -766,7 +770,7 @@ char *mutt_concatn_path(char *dst, size_t dstlen, const char *dir, /* Two options here: * 1) assert(0) or return NULL to signal error * 2) copy as much of the path as will fit - * It doesn't appear that the return value is actually checked anywhere mutt_concat_path() + * It doesn't appear that the return value is actually checked anywhere mutt_file_concat_path() * is called, so we should just copy set dst to nul and let the calling function fail later. */ dst[0] = '\0'; /* safe since we bail out early if dstlen == 0 */ @@ -790,7 +794,7 @@ char *mutt_concatn_path(char *dst, size_t dstlen, const char *dir, } /** - * mutt_concat_path - Join a directory name and a filename + * mutt_file_concat_path - Join a directory name and a filename * @param d Buffer for the result * @param dir Directory name * @param fname File name @@ -800,7 +804,7 @@ char *mutt_concatn_path(char *dst, size_t dstlen, const char *dir, * If both dir and fname are supplied, they are separated with '/'. * If either is missing, then the other will be copied exactly. */ -char *mutt_concat_path(char *d, const char *dir, const char *fname, size_t l) +char *mutt_file_concat_path(char *d, const char *dir, const char *fname, size_t l) { const char *fmt = "%s/%s"; @@ -812,11 +816,11 @@ char *mutt_concat_path(char *d, const char *dir, const char *fname, size_t l) } /** - * mutt_basename - Find the last component for a pathname + * mutt_file_basename - Find the last component for a pathname * @param f String to be examined * @retval ptr Part of pathname after last '/' character */ -const char *mutt_basename(const char *f) +const char *mutt_file_basename(const char *f) { const char *p = strrchr(f, '/'); if (p) @@ -826,7 +830,7 @@ const char *mutt_basename(const char *f) } /** - * mutt_mkdir - Recursively create directories + * mutt_file_mkdir - Recursively create directories * @param path Directories to create * @param mode Permissions for final directory * @retval 0 Success @@ -838,7 +842,7 @@ const char *mutt_basename(const char *f) * The permissions of any parent directories are determined by the umask. * (This is how "mkdir -p" behaves) */ -int mutt_mkdir(const char *path, mode_t mode) +int mutt_file_mkdir(const char *path, mode_t mode) { if (!path || !*path) { @@ -884,7 +888,7 @@ int mutt_mkdir(const char *path, mode_t mode) } /** - * mutt_decrease_mtime - Decrease a file's modification time by 1 second + * mutt_file_decrease_mtime - Decrease a file's modification time by 1 second * @param f Filename * @param st struct stat for the file (optional) * @retval num Updated Unix mtime @@ -892,7 +896,7 @@ int mutt_mkdir(const char *path, mode_t mode) * * If a file's mtime is NOW, then set it to 1 second in the past. */ -time_t mutt_decrease_mtime(const char *f, struct stat *st) +time_t mutt_file_decrease_mtime(const char *f, struct stat *st) { struct utimbuf utim; struct stat _st; @@ -918,7 +922,7 @@ time_t mutt_decrease_mtime(const char *f, struct stat *st) } /** - * mutt_dirname - Return a path up to, but not including, the final '/' + * mutt_file_dirname - Return a path up to, but not including, the final '/' * @param p Path * @retval ptr The directory containing p * @@ -926,9 +930,9 @@ time_t mutt_decrease_mtime(const char *f, struct stat *st) * implementation does not modify its parameter, so callers need not manually * copy their paths into a modifiable buffer prior to calling this function. * - * mutt_dirname() returns a static string which must not be free()'d. + * mutt_file_dirname() returns a static string which must not be free()'d. */ -const char *mutt_dirname(const char *p) +const char *mutt_file_dirname(const char *p) { static char buf[_POSIX_PATH_MAX]; strfcpy(buf, p, sizeof(buf)); @@ -936,11 +940,11 @@ const char *mutt_dirname(const char *p) } /** - * mutt_set_mtime - Set the modification time of one file from another + * mutt_file_set_mtime - Set the modification time of one file from another * @param from Filename whose mtime should be copied * @param to Filename to update */ -void mutt_set_mtime(const char *from, const char *to) +void mutt_file_set_mtime(const char *from, const char *to) { struct utimbuf utim; struct stat st; @@ -954,13 +958,13 @@ void mutt_set_mtime(const char *from, const char *to) } /** - * mutt_touch_atime - Set the access time to current time + * mutt_file_touch_atime - Set the access time to current time * @param f File descriptor of the file to alter * * This is just as read() would do on !noatime. * Silently ignored if futimens() isn't supported. */ -void mutt_touch_atime(int f) +void mutt_file_touch_atime(int f) { #ifdef HAVE_FUTIMENS struct timespec times[2] = { { 0, UTIME_NOW }, { 0, UTIME_OMIT } }; @@ -969,7 +973,7 @@ void mutt_touch_atime(int f) } /** - * mutt_lock_file - (try to) lock a file + * mutt_file_lock - (try to) lock a file * @param path Path to file * @param fd File descriptor to file * @param excl If set, try to lock exclusively @@ -980,9 +984,9 @@ void mutt_touch_atime(int f) * The type of file locking depends on how NeoMutt was compiled. * It could use fcntl() or flock() to perform the locking. * - * Use mutt_unlock_file() to unlock the file. + * Use mutt_file_unlock() to unlock the file. */ -int mutt_lock_file(const char *path, int fd, int excl, int timeout) +int mutt_file_lock(const char *path, int fd, int excl, int timeout) { #if defined(USE_FCNTL) || defined(USE_FLOCK) int count; @@ -1002,7 +1006,7 @@ int mutt_lock_file(const char *path, int fd, int excl, int timeout) attempt = 0; while (fcntl(fd, F_SETLK, &lck) == -1) { - mutt_debug(1, "mutt_lock_file(): fcntl errno %d.\n", errno); + mutt_debug(1, "mutt_file_lock(): fcntl errno %d.\n", errno); if ((errno != EAGAIN) && (errno != EACCES)) { mutt_perror("fcntl"); @@ -1081,12 +1085,12 @@ int mutt_lock_file(const char *path, int fd, int excl, int timeout) } /** - * mutt_unlock_file - Unlock a file previously locked by mutt_lock_file() + * mutt_file_unlock - Unlock a file previously locked by mutt_file_lock() * @param path Path to file * @param fd File descriptor to file * @retval 0 Always */ -int mutt_unlock_file(const char *path, int fd) +int mutt_file_unlock(const char *path, int fd) { #ifdef USE_FCNTL struct flock unlockit = { F_UNLCK, 0, 0, 0, 0 }; @@ -1105,10 +1109,10 @@ int mutt_unlock_file(const char *path, int fd) } /** - * mutt_unlink_empty - Delete a file if it's empty + * mutt_file_unlink_empty - Delete a file if it's empty * @param path File to delete */ -void mutt_unlink_empty(const char *path) +void mutt_file_unlink_empty(const char *path) { int fd; struct stat sb; @@ -1117,7 +1121,7 @@ void mutt_unlink_empty(const char *path) if (fd == -1) return; - if (mutt_lock_file(path, fd, 1, 1) == -1) + if (mutt_file_lock(path, fd, 1, 1) == -1) { close(fd); return; @@ -1126,12 +1130,12 @@ void mutt_unlink_empty(const char *path) if (fstat(fd, &sb) == 0 && sb.st_size == 0) unlink(path); - mutt_unlock_file(path, fd); + mutt_file_unlock(path, fd); close(fd); } /** - * mutt_rename_file - Rename a file + * mutt_file_rename - Rename a file * @param oldfile Old filename * @param newfile New filename * @retval 0 Success @@ -1140,10 +1144,10 @@ void mutt_unlink_empty(const char *path) * @retval 3 Some other error * * note on access(2) use: No dangling symlink problems here due to - * safe_fopen(). + * mutt_file_fopen(). */ -int mutt_rename_file(char *oldfile, char *newfile) +int mutt_file_rename(char *oldfile, char *newfile) { FILE *ofp = NULL, *nfp = NULL; @@ -1154,21 +1158,21 @@ int mutt_rename_file(char *oldfile, char *newfile) ofp = fopen(oldfile, "r"); if (!ofp) return 3; - nfp = safe_fopen(newfile, "w"); + nfp = mutt_file_fopen(newfile, "w"); if (!nfp) { - safe_fclose(&ofp); + mutt_file_fclose(&ofp); return 3; } - mutt_copy_stream(ofp, nfp); - safe_fclose(&nfp); - safe_fclose(&ofp); - mutt_unlink(oldfile); + mutt_file_copy_stream(ofp, nfp); + mutt_file_fclose(&nfp); + mutt_file_fclose(&ofp); + mutt_file_unlink(oldfile); return 0; } /** - * to_absolute_path - Convert relative filepath to an absolute path + * mutt_file_to_absolute_path - Convert relative filepath to an absolute path * @param path Relative path * @param reference Absolute path that \a path is relative to * @retval true on success @@ -1177,7 +1181,7 @@ int mutt_rename_file(char *oldfile, char *newfile) * Use POSIX functions to convert a path to absolute, relatively to another path * @note \a path should be at least of PATH_MAX length */ -int to_absolute_path(char *path, const char *reference) +int mutt_file_to_absolute_path(char *path, const char *reference) { const char *dirpath = NULL; char abs_path[PATH_MAX]; @@ -1189,7 +1193,7 @@ int to_absolute_path(char *path, const char *reference) return true; } - dirpath = mutt_dirname(reference); + dirpath = mutt_file_dirname(reference); strfcpy(abs_path, dirpath, PATH_MAX); safe_strncat(abs_path, sizeof(abs_path), "/", 1); /* append a / at the end of the path */ @@ -1209,7 +1213,7 @@ int to_absolute_path(char *path, const char *reference) } /** - * file_read_keyword - Read a keyword from a file + * mutt_file_read_keyword - Read a keyword from a file * @param file File to read * @param buffer Buffer to store the keyword * @param buflen Length of the buffer @@ -1218,17 +1222,17 @@ int to_absolute_path(char *path, const char *reference) * Read one line from the start of a file. * Skip any leading whitespace and extract the first token. */ -char *file_read_keyword(const char *file, char *buffer, size_t buflen) +char *mutt_file_read_keyword(const char *file, char *buffer, size_t buflen) { FILE *fp = NULL; char *start = NULL; - fp = safe_fopen(file, "r"); + fp = mutt_file_fopen(file, "r"); if (!fp) return NULL; buffer = fgets(buffer, buflen, fp); - safe_fclose(&fp); + mutt_file_fclose(&fp); if (!buffer) return NULL; @@ -1245,13 +1249,13 @@ char *file_read_keyword(const char *file, char *buffer, size_t buflen) } /** - * mbox_check_empty - Is the mailbox empty + * mutt_file_check_empty - Is the mailbox empty * @param path Path to mailbox * @retval 1 mailbox is not empty * @retval 0 mailbox is empty * @retval -1 on error */ -int mbox_check_empty(const char *path) +int mutt_file_check_empty(const char *path) { struct stat st; diff --git a/mutt/file.h b/mutt/file.h index 55eb9be521b..a79b39420d6 100644 --- a/mutt/file.h +++ b/mutt/file.h @@ -29,38 +29,38 @@ struct stat; -/* Flags for mutt_read_line() */ +/* Flags for mutt_file_read_line() */ #define MUTT_CONT (1 << 0) /**< \-continuation */ #define MUTT_EOL (1 << 1) /**< don't strip `\n` / `\r\n` */ -char * file_read_keyword(const char *file, char *buffer, size_t buflen); -int mbox_check_empty(const char *path); -const char *mutt_basename(const char *f); -char * mutt_concatn_path(char *dst, size_t dstlen, const char *dir, size_t dirlen, const char *fname, size_t fnamelen); -char * mutt_concat_path(char *d, const char *dir, const char *fname, size_t l); -int mutt_copy_bytes(FILE *in, FILE *out, size_t size); -int mutt_copy_stream(FILE *fin, FILE *fout); -time_t mutt_decrease_mtime(const char *f, struct stat *st); -const char *mutt_dirname(const char *p); -int mutt_lock_file(const char *path, int fd, int excl, int timeout); -int mutt_mkdir(const char *path, mode_t mode); -size_t mutt_quote_filename(char *d, size_t l, const char *f); -char * mutt_read_line(char *s, size_t *size, FILE *fp, int *line, int flags); -int mutt_regex_sanitize_string(char *dest, size_t destlen, const char *src); -int mutt_rename_file(char *oldfile, char *newfile); -int mutt_rmtree(const char *path); -void mutt_sanitize_filename(char *f, short slash); -void mutt_set_mtime(const char *from, const char *to); -void mutt_touch_atime(int f); -void mutt_unlink(const char *s); -void mutt_unlink_empty(const char *path); -int mutt_unlock_file(const char *path, int fd); -int safe_fclose(FILE **f); -FILE * safe_fopen(const char *path, const char *mode); -int safe_fsync_close(FILE **f); -int safe_open(const char *path, int flags); -int safe_rename(const char *src, const char *target); -int safe_symlink(const char *oldpath, const char *newpath); -int to_absolute_path(char *path, const char *reference); +const char *mutt_file_basename(const char *f); +int mutt_file_check_empty(const char *path); +char * mutt_file_concatn_path(char *dst, size_t dstlen, const char *dir, size_t dirlen, const char *fname, size_t fnamelen); +char * mutt_file_concat_path(char *d, const char *dir, const char *fname, size_t l); +int mutt_file_copy_bytes(FILE *in, FILE *out, size_t size); +int mutt_file_copy_stream(FILE *fin, FILE *fout); +time_t mutt_file_decrease_mtime(const char *f, struct stat *st); +const char *mutt_file_dirname(const char *p); +int mutt_file_fclose(FILE **f); +FILE * mutt_file_fopen(const char *path, const char *mode); +int mutt_file_fsync_close(FILE **f); +int mutt_file_lock(const char *path, int fd, int excl, int timeout); +int mutt_file_mkdir(const char *path, mode_t mode); +int mutt_file_open(const char *path, int flags); +size_t mutt_file_quote_filename(char *d, size_t l, const char *f); +char * mutt_file_read_keyword(const char *file, char *buffer, size_t buflen); +char * mutt_file_read_line(char *s, size_t *size, FILE *fp, int *line, int flags); +int mutt_file_rename(char *oldfile, char *newfile); +int mutt_file_rmtree(const char *path); +int mutt_file_safe_rename(const char *src, const char *target); +void mutt_file_sanitize_filename(char *f, short slash); +int mutt_file_sanitize_regex(char *dest, size_t destlen, const char *src); +void mutt_file_set_mtime(const char *from, const char *to); +int mutt_file_symlink(const char *oldpath, const char *newpath); +int mutt_file_to_absolute_path(char *path, const char *reference); +void mutt_file_touch_atime(int f); +void mutt_file_unlink(const char *s); +void mutt_file_unlink_empty(const char *path); +int mutt_file_unlock(const char *path, int fd); #endif /* _MUTT_FILE_H */ diff --git a/mutt_notmuch.c b/mutt_notmuch.c index 63471c8859f..069c6bb905a 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -2439,7 +2439,7 @@ static int nm_close_message(struct Context *ctx, struct Message *msg) { if (!msg) return 1; - safe_fclose(&(msg->fp)); + mutt_file_fclose(&(msg->fp)); return 0; } diff --git a/muttlib.c b/muttlib.c index c7c33a8f020..7096822b3ab 100644 --- a/muttlib.c +++ b/muttlib.c @@ -103,7 +103,7 @@ void mutt_adv_mktemp(char *s, size_t l) else { strfcpy(prefix, s, sizeof(prefix)); - mutt_sanitize_filename(prefix, 1); + mutt_file_sanitize_filename(prefix, 1); snprintf(s, l, "%s/%s", NONULL(Tmpdir), prefix); if (lstat(s, &sb) == -1 && errno == ENOENT) return; @@ -322,7 +322,7 @@ char *mutt_expand_path_regex(char *s, size_t slen, int regex) if (regex && *p && !recurse) { - mutt_regex_sanitize_string(q, sizeof(q), p); + mutt_file_sanitize_regex(q, sizeof(q), p); snprintf(tmp, sizeof(tmp), "%s%s", q, tail); } else @@ -623,7 +623,7 @@ void mutt_expand_file_fmt(char *dest, size_t destlen, const char *fmt, const cha { char tmp[LONG_STRING]; - mutt_quote_filename(tmp, sizeof(tmp), src); + mutt_file_quote_filename(tmp, sizeof(tmp), src); mutt_expand_fmt(dest, destlen, fmt, tmp); } @@ -724,12 +724,12 @@ int mutt_check_overwrite(const char *attname, const char *path, char *fname, else if ((rc = mutt_yesorno(_("File is a directory, save under it?"), MUTT_YES)) != MUTT_YES) return (rc == MUTT_NO) ? 1 : -1; - strfcpy(tmp, mutt_basename(NONULL(attname)), sizeof(tmp)); + strfcpy(tmp, mutt_file_basename(NONULL(attname)), sizeof(tmp)); if (mutt_get_field(_("File under directory: "), tmp, sizeof(tmp), MUTT_FILE | MUTT_CLEAR) != 0 || !tmp[0]) return -1; - mutt_concat_path(fname, path, tmp, flen); + mutt_file_concat_path(fname, path, tmp, flen); } if (*append == 0 && access(fname, F_OK) == 0) @@ -981,7 +981,7 @@ void mutt_expando_format(char *dest, size_t destlen, size_t col, int cols, int rc; n = fread(dest, 1, destlen /* already decremented */, filter); - safe_fclose(&filter); + mutt_file_fclose(&filter); rc = mutt_wait_filter(pid); if (rc != 0) mutt_debug(1, "format pipe command exited code %d\n", rc); @@ -1508,7 +1508,7 @@ int mutt_save_confirm(const char *s, struct stat *st) if (ret == 0) { /* create dir recursively */ - if (mutt_mkdir(mutt_dirname(s), S_IRWXU) == -1) + if (mutt_file_mkdir(mutt_file_dirname(s), S_IRWXU) == -1) { /* report failure & abort */ mutt_perror(s); diff --git a/mx.c b/mx.c index 5f66bde32c1..7b6e82a3157 100644 --- a/mx.c +++ b/mx.c @@ -286,7 +286,7 @@ int mx_get_magic(const char *path) else if (mutt_strcmp(MMDF_SEP, tmp) == 0) magic = MUTT_MMDF; } - safe_fclose(&f); + mutt_file_fclose(&f); if (!option(OPT_CHECK_MBOX_SIZE)) { @@ -550,7 +550,7 @@ void mx_fastclose_mailbox(struct Context *ctx) FREE(&ctx->pattern); if (ctx->limit_pattern) mutt_pattern_free(&ctx->limit_pattern); - safe_fclose(&ctx->fp); + mutt_file_fclose(&ctx->fp); memset(ctx, 0, sizeof(struct Context)); } @@ -873,7 +873,7 @@ int mx_close_mailbox(struct Context *ctx, int *index_hint) if (ctx->msgcount == ctx->deleted && (ctx->magic == MUTT_MMDF || ctx->magic == MUTT_MBOX) && !mutt_is_spool(ctx->path) && !option(OPT_SAVE_EMPTY)) - mutt_unlink_empty(ctx->path); + mutt_file_unlink_empty(ctx->path); #ifdef USE_SIDEBAR if (purge && ctx->deleted) @@ -1364,7 +1364,7 @@ int mx_check_empty(const char *path) { case MUTT_MBOX: case MUTT_MMDF: - return mbox_check_empty(path); + return mutt_file_check_empty(path); case MUTT_MH: return mh_check_empty(path); case MUTT_MAILDIR: diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 87b8580e114..5f115ac7dcb 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -617,7 +617,7 @@ int crypt_write_signed(struct Body *a, struct State *s, const char *tempfile) if (!WithCrypto) return -1; - fp = safe_fopen(tempfile, "w"); + fp = mutt_file_fopen(tempfile, "w"); if (!fp) { mutt_perror(tempfile); @@ -647,7 +647,7 @@ int crypt_write_signed(struct Body *a, struct State *s, const char *tempfile) fputc(c, fp); } - safe_fclose(&fp); + mutt_file_fclose(&fp); return 0; } @@ -696,7 +696,7 @@ void crypt_extract_keys_from_messages(struct Header *h) return; mutt_mktemp(tempfname, sizeof(tempfname)); - fpout = safe_fopen(tempfname, "w"); + fpout = mutt_file_fopen(tempfname, "w"); if (!fpout) { mutt_perror(tempfname); @@ -718,7 +718,7 @@ void crypt_extract_keys_from_messages(struct Header *h) mutt_parse_mime_message(Context, hi); if (hi->security & ENCRYPT && !crypt_valid_passphrase(hi->security)) { - safe_fclose(&fpout); + mutt_file_fclose(&fpout); break; } @@ -794,11 +794,11 @@ void crypt_extract_keys_from_messages(struct Header *h) } } - safe_fclose(&fpout); + mutt_file_fclose(&fpout); if (isendwin()) mutt_any_key_to_continue(NULL); - mutt_unlink(tempfname); + mutt_file_unlink(tempfname); if ((WithCrypto & APPLICATION_PGP)) unset_option(OPT_DONT_HANDLE_PGP_KEYS); @@ -1025,7 +1025,7 @@ int mutt_signed_handler(struct Body *a, struct State *s) } } - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); b->goodsig = goodsig; b->badsig = !goodsig; diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index 3a4c875d76e..b864190832e 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -525,7 +525,7 @@ static gpgme_data_t body_to_data_object(struct Body *a, int convert) gpgme_data_t data; mutt_mktemp(tempfile, sizeof(tempfile)); - fptmp = safe_fopen(tempfile, "w+"); + fptmp = mutt_file_fopen(tempfile, "w+"); if (!fptmp) { mutt_perror(tempfile); @@ -561,12 +561,12 @@ static gpgme_data_t body_to_data_object(struct Body *a, int convert) buf[0] = c; gpgme_data_write(data, buf, 1); } - safe_fclose(&fptmp); + mutt_file_fclose(&fptmp); gpgme_data_seek(data, 0, SEEK_SET); } else { - safe_fclose(&fptmp); + mutt_file_fclose(&fptmp); err = gpgme_data_new_from_file(&data, tempfile, 1); } unlink(tempfile); @@ -660,7 +660,7 @@ static char *data_object_to_tempfile(gpgme_data_t data, char *tempf, FILE **ret_ mutt_mktemp(tempfb, sizeof(tempfb)); tempf = tempfb; } - fp = safe_fopen(tempf, tempf == tempfb ? "w+" : "a+"); + fp = mutt_file_fopen(tempf, tempf == tempfb ? "w+" : "a+"); if (!fp) { mutt_perror(_("Can't create temporary file")); @@ -677,7 +677,7 @@ static char *data_object_to_tempfile(gpgme_data_t data, char *tempf, FILE **ret_ if (fwrite(buf, nread, 1, fp) != 1) { mutt_perror(tempf); - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(tempf); return NULL; } @@ -686,12 +686,12 @@ static char *data_object_to_tempfile(gpgme_data_t data, char *tempf, FILE **ret_ if (ret_fp) rewind(fp); else - safe_fclose(&fp); + mutt_file_fclose(&fp); if (nread == -1) { mutt_error(_("error reading data object: %s\n"), gpgme_strerror(err)); unlink(tempf); - safe_fclose(&fp); + mutt_file_fclose(&fp); return NULL; } if (ret_fp) @@ -1974,7 +1974,7 @@ int pgp_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body saved_length = b->length; mutt_mktemp(tempfile, sizeof(tempfile)); - decoded_fp = safe_fopen(tempfile, "w+"); + decoded_fp = mutt_file_fopen(tempfile, "w+"); if (!decoded_fp) { mutt_perror(tempfile); @@ -1996,7 +1996,7 @@ int pgp_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body } mutt_mktemp(tempfile, sizeof(tempfile)); - *fpout = safe_fopen(tempfile, "w+"); + *fpout = mutt_file_fopen(tempfile, "w+"); if (!*fpout) { mutt_perror(tempfile); @@ -2018,7 +2018,7 @@ int pgp_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body b->type = saved_type; b->length = saved_length; b->offset = saved_offset; - safe_fclose(&decoded_fp); + mutt_file_fclose(&decoded_fp); } return rv; @@ -2058,13 +2058,13 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo s.fpin = fpin; fseeko(s.fpin, b->offset, SEEK_SET); mutt_mktemp(tempfile, sizeof(tempfile)); - tmpfp = safe_fopen(tempfile, "w+"); + tmpfp = mutt_file_fopen(tempfile, "w+"); if (!tmpfp) { mutt_perror(tempfile); return -1; } - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); s.fpout = tmpfp; mutt_decode_attachment(b, &s); @@ -2077,13 +2077,13 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo s.fpin = tmpfp; s.fpout = 0; mutt_mktemp(tempfile, sizeof(tempfile)); - *fpout = safe_fopen(tempfile, "w+"); + *fpout = mutt_file_fopen(tempfile, "w+"); if (!*fpout) { mutt_perror(tempfile); return -1; } - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); *cur = decrypt_part(b, &s, *fpout, 1, &is_signed); if (*cur) @@ -2091,7 +2091,7 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo b->type = saved_b_type; b->length = saved_b_length; b->offset = saved_b_offset; - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); rewind(*fpout); if (*cur && !is_signed && !(*cur)->parts && mutt_is_application_smime(*cur)) { @@ -2114,13 +2114,13 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo s.fpin = *fpout; fseeko(s.fpin, bb->offset, SEEK_SET); mutt_mktemp(tempfile, sizeof(tempfile)); - tmpfp = safe_fopen(tempfile, "w+"); + tmpfp = mutt_file_fopen(tempfile, "w+"); if (!tmpfp) { mutt_perror(tempfile); return -1; } - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); s.fpout = tmpfp; mutt_decode_attachment(bb, &s); @@ -2128,19 +2128,19 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo bb->length = ftello(s.fpout); bb->offset = 0; rewind(tmpfp); - safe_fclose(fpout); + mutt_file_fclose(fpout); memset(&s, 0, sizeof(s)); s.fpin = tmpfp; s.fpout = 0; mutt_mktemp(tempfile, sizeof(tempfile)); - *fpout = safe_fopen(tempfile, "w+"); + *fpout = mutt_file_fopen(tempfile, "w+"); if (!*fpout) { mutt_perror(tempfile); return -1; } - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); tmp_b = decrypt_part(bb, &s, *fpout, 1, &is_signed); if (tmp_b) @@ -2148,7 +2148,7 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo bb->type = saved_b_type; bb->length = saved_b_length; bb->offset = saved_b_offset; - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); rewind(*fpout); mutt_free_body(cur); *cur = tmp_b; @@ -2217,7 +2217,7 @@ static int pgp_gpgme_extract_keys(gpgme_data_t keydata, FILE **fp, int dryrun) } mutt_mktemp(tmpfile, sizeof(tmpfile)); - *fp = safe_fopen(tmpfile, "w+"); + *fp = mutt_file_fopen(tmpfile, "w+"); if (!*fp) { mutt_perror(tmpfile); @@ -2263,10 +2263,10 @@ static int pgp_gpgme_extract_keys(gpgme_data_t keydata, FILE **fp, int dryrun) err_fp: if (rc) - safe_fclose(fp); + mutt_file_fclose(fp); err_tmpdir: if (dryrun) - mutt_rmtree(tmpdir); + mutt_file_rmtree(tmpdir); err_ctx: gpgme_release(tmpctx); @@ -2347,7 +2347,7 @@ static int pgp_check_traditional_one_body(FILE *fp, struct Body *b) } } } - safe_fclose(&tfp); + mutt_file_fclose(&tfp); unlink(tempfile); if (!enc && !sgn) @@ -2390,7 +2390,7 @@ void pgp_gpgme_invoke_import(const char *fname) FILE *in = NULL; FILE *out = NULL; - in = safe_fopen(fname, "r"); + in = mutt_file_fopen(fname, "r"); if (!in) return; /* Note that the stream, "in", needs to be kept open while the keydata @@ -2399,7 +2399,7 @@ void pgp_gpgme_invoke_import(const char *fname) err = gpgme_data_new_from_stream(&keydata, in); if (err != GPG_ERR_NO_ERROR) { - safe_fclose(&in); + mutt_file_fclose(&in); mutt_error(_("error allocating data object: %s\n"), gpgme_strerror(err)); mutt_sleep(1); return; @@ -2411,8 +2411,8 @@ void pgp_gpgme_invoke_import(const char *fname) mutt_sleep(1); } gpgme_data_release(keydata); - safe_fclose(&in); - safe_fclose(&out); + mutt_file_fclose(&in); + mutt_file_fclose(&out); } /* @@ -2442,7 +2442,7 @@ static void copy_clearsigned(gpgme_data_t data, struct State *s, char *charset) fname = data_object_to_tempfile(data, NULL, &fp); if (!fname) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return; } unlink(fname); @@ -2484,7 +2484,7 @@ static void copy_clearsigned(gpgme_data_t data, struct State *s, char *charset) } fgetconv_close(&fc); - safe_fclose(&fp); + mutt_file_fclose(&fp); } /** @@ -2639,7 +2639,7 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) tmpfname = data_object_to_tempfile(plaintext, NULL, &pgpout); if (!tmpfname) { - safe_fclose(&pgpout); + mutt_file_fclose(&pgpout); state_puts(_("Error: copy data failed\n"), s); } else @@ -2701,7 +2701,7 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) gpgme_data_release(armored_data); if (pgpout) { - safe_fclose(&pgpout); + mutt_file_fclose(&pgpout); } } else @@ -2749,7 +2749,7 @@ int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s) mutt_debug(2, "Entering pgp_encrypted handler\n"); mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = safe_fopen(tempfile, "w+"); + fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { if (s->flags & MUTT_DISPLAY) @@ -2805,8 +2805,8 @@ int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s) rc = -1; } - safe_fclose(&fpout); - mutt_unlink(tempfile); + mutt_file_fclose(&fpout); + mutt_file_unlink(tempfile); mutt_debug(2, "Leaving pgp_encrypted handler\n"); return rc; @@ -2827,7 +2827,7 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) a->warnsig = false; mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = safe_fopen(tempfile, "w+"); + fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { if (s->flags & MUTT_DISPLAY) @@ -2883,8 +2883,8 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) mutt_free_body(&tattach); } - safe_fclose(&fpout); - mutt_unlink(tempfile); + mutt_file_fclose(&fpout); + mutt_file_unlink(tempfile); mutt_debug(2, "Leaving smime_encrypted handler\n"); return rc; @@ -3831,7 +3831,7 @@ static void verify_key(struct CryptKeyInfo *key) int maxdepth = 100; mutt_mktemp(tempfile, sizeof(tempfile)); - fp = safe_fopen(tempfile, "w"); + fp = mutt_file_fopen(tempfile, "w"); if (!fp) { mutt_perror(_("Can't create temporary file")); @@ -3879,7 +3879,7 @@ static void verify_key(struct CryptKeyInfo *key) leave: gpgme_key_unref(k); gpgme_release(listctx); - safe_fclose(&fp); + mutt_file_fclose(&fp); mutt_clear_error(); snprintf(cmd, sizeof(cmd), _("Key ID: 0x%s"), crypt_keyid(key)); mutt_do_pager(cmd, tempfile, 0, NULL); diff --git a/ncrypt/gnupgparse.c b/ncrypt/gnupgparse.c index 3a286b31f42..14e00c8d306 100644 --- a/ncrypt/gnupgparse.c +++ b/ncrypt/gnupgparse.c @@ -436,7 +436,7 @@ struct PgpKeyInfo *pgp_get_candidates(enum PgpRing keyring, struct ListHead *hin if (ferror(fp)) mutt_perror("fgets"); - safe_fclose(&fp); + mutt_file_fclose(&fp); mutt_wait_filter(thepid); close(devnull); diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 55e3d4eab46..3592b0b17b1 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -198,7 +198,7 @@ static int pgp_copy_checksig(FILE *fpin, FILE *fpout) int lineno = 0; size_t linelen; - while ((line = mutt_read_line(line, &linelen, fpin, &lineno, 0)) != NULL) + while ((line = mutt_file_read_line(line, &linelen, fpin, &lineno, 0)) != NULL) { if (regexec(PgpGoodSign.regex, line, 0, NULL, 0) == 0) { @@ -218,7 +218,7 @@ static int pgp_copy_checksig(FILE *fpin, FILE *fpout) else { mutt_debug(2, "pgp_copy_checksig: No pattern.\n"); - mutt_copy_stream(fpin, fpout); + mutt_file_copy_stream(fpin, fpout); rv = 1; } @@ -242,7 +242,7 @@ static int pgp_check_decryption_okay(FILE *fpin) int lineno = 0; size_t linelen; - while ((line = mutt_read_line(line, &linelen, fpin, &lineno, 0)) != NULL) + while ((line = mutt_file_read_line(line, &linelen, fpin, &lineno, 0)) != NULL) { if (regexec(PgpDecryptionOkay.regex, line, 0, NULL, 0) == 0) { @@ -393,7 +393,7 @@ int pgp_application_pgp_handler(struct Body *m, struct State *s) /* Copy PGP material to temporary file */ mutt_mktemp(tmpfname, sizeof(tmpfname)); - tmpfp = safe_fopen(tmpfname, "w+"); + tmpfp = mutt_file_fopen(tmpfname, "w+"); if (!tmpfp) { mutt_perror(tmpfname); @@ -434,11 +434,11 @@ int pgp_application_pgp_handler(struct Body *m, struct State *s) if (!clearsign || (s->flags & MUTT_VERIFY)) { mutt_mktemp(outfile, sizeof(outfile)); - pgpout = safe_fopen(outfile, "w+"); + pgpout = mutt_file_fopen(outfile, "w+"); if (!pgpout) { mutt_perror(outfile); - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); FREE(&gpgcharset); return -1; } @@ -446,7 +446,7 @@ int pgp_application_pgp_handler(struct Body *m, struct State *s) if ((thepid = pgp_invoke_decode(&pgpin, NULL, &pgperr, -1, fileno(pgpout), -1, tmpfname, needpass)) == -1) { - safe_fclose(&pgpout); + mutt_file_fclose(&pgpout); maybe_goodsig = false; pgpin = NULL; pgperr = NULL; @@ -464,7 +464,7 @@ int pgp_application_pgp_handler(struct Body *m, struct State *s) fprintf(pgpin, "%s\n", PgpPass); } - safe_fclose(&pgpin); + mutt_file_fclose(&pgpin); if (s->flags & MUTT_DISPLAY) { @@ -472,7 +472,7 @@ int pgp_application_pgp_handler(struct Body *m, struct State *s) rc = pgp_copy_checksig(pgperr, s->fpout); } - safe_fclose(&pgperr); + mutt_file_fclose(&pgperr); rv = mutt_wait_filter(thepid); if (s->flags & MUTT_DISPLAY) @@ -558,12 +558,12 @@ int pgp_application_pgp_handler(struct Body *m, struct State *s) * Multiple PGP blocks can exist, so these need to be closed and * unlinked inside the loop. */ - safe_fclose(&tmpfp); - mutt_unlink(tmpfname); + mutt_file_fclose(&tmpfp); + mutt_file_unlink(tmpfname); if (pgpout) { - safe_fclose(&pgpout); - mutt_unlink(outfile); + mutt_file_fclose(&pgpout); + mutt_file_unlink(outfile); } if (s->flags & MUTT_DISPLAY) @@ -600,13 +600,13 @@ int pgp_application_pgp_handler(struct Body *m, struct State *s) if (tmpfp) { - safe_fclose(&tmpfp); - mutt_unlink(tmpfname); + mutt_file_fclose(&tmpfp); + mutt_file_unlink(tmpfname); } if (pgpout) { - safe_fclose(&pgpout); - mutt_unlink(outfile); + mutt_file_fclose(&pgpout); + mutt_file_unlink(outfile); } FREE(&gpgcharset); @@ -660,7 +660,7 @@ static int pgp_check_traditional_one_body(FILE *fp, struct Body *b) key = 1; } } - safe_fclose(&tfp); + mutt_file_fclose(&tfp); unlink(tempfile); if (!enc && !sgn && !key) @@ -712,7 +712,7 @@ int pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) snprintf(sigfile, sizeof(sigfile), "%s.asc", tempfile); - fp = safe_fopen(sigfile, "w"); + fp = mutt_file_fopen(sigfile, "w"); if (!fp) { mutt_perror(sigfile); @@ -720,11 +720,11 @@ int pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) } fseeko(s->fpin, sigbdy->offset, SEEK_SET); - mutt_copy_bytes(s->fpin, fp, sigbdy->length); - safe_fclose(&fp); + mutt_file_copy_bytes(s->fpin, fp, sigbdy->length); + mutt_file_fclose(&fp); mutt_mktemp(pgperrfile, sizeof(pgperrfile)); - pgperr = safe_fopen(pgperrfile, "w+"); + pgperr = mutt_file_fopen(pgperrfile, "w+"); if (!pgperr) { mutt_perror(pgperrfile); @@ -740,7 +740,7 @@ int pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) if (pgp_copy_checksig(pgpout, s->fpout) >= 0) badsig = 0; - safe_fclose(&pgpout); + mutt_file_fclose(&pgpout); fflush(pgperr); rewind(pgperr); @@ -753,12 +753,12 @@ int pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) mutt_debug(1, "pgp_verify_one: mutt_wait_filter returned %d.\n", rv); } - safe_fclose(&pgperr); + mutt_file_fclose(&pgperr); state_attach_puts(_("[-- End of PGP output --]\n\n"), s); - mutt_unlink(sigfile); - mutt_unlink(pgperrfile); + mutt_file_unlink(sigfile); + mutt_file_unlink(pgperrfile); mutt_debug(1, "pgp_verify_one: returning %d.\n", badsig); @@ -775,7 +775,7 @@ static void pgp_extract_keys_from_attachment(FILE *fp, struct Body *top) char tempfname[_POSIX_PATH_MAX]; mutt_mktemp(tempfname, sizeof(tempfname)); - tempfp = safe_fopen(tempfname, "w"); + tempfp = mutt_file_fopen(tempfname, "w"); if (!tempfp) { mutt_perror(tempfname); @@ -789,12 +789,12 @@ static void pgp_extract_keys_from_attachment(FILE *fp, struct Body *top) mutt_body_handler(top, &s); - safe_fclose(&tempfp); + mutt_file_fclose(&tempfp); pgp_invoke_import(tempfname); mutt_any_key_to_continue(NULL); - mutt_unlink(tempfname); + mutt_file_unlink(tempfname); } void pgp_extract_keys_from_attachment_list(FILE *fp, int tag, struct Body *top) @@ -837,7 +837,7 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, int rv; mutt_mktemp(pgperrfile, sizeof(pgperrfile)); - pgperr = safe_fopen(pgperrfile, "w+"); + pgperr = mutt_file_fopen(pgperrfile, "w+"); if (!pgperr) { mutt_perror(pgperrfile); @@ -846,11 +846,11 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, unlink(pgperrfile); mutt_mktemp(pgptmpfile, sizeof(pgptmpfile)); - pgptmp = safe_fopen(pgptmpfile, "w"); + pgptmp = mutt_file_fopen(pgptmpfile, "w"); if (!pgptmp) { mutt_perror(pgptmpfile); - safe_fclose(&pgperr); + mutt_file_fclose(&pgperr); return NULL; } @@ -859,13 +859,13 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, */ fseeko(s->fpin, a->offset, SEEK_SET); - mutt_copy_bytes(s->fpin, pgptmp, a->length); - safe_fclose(&pgptmp); + mutt_file_copy_bytes(s->fpin, pgptmp, a->length); + mutt_file_fclose(&pgptmp); if ((thepid = pgp_invoke_decrypt(&pgpin, &pgpout, NULL, -1, -1, fileno(pgperr), pgptmpfile)) == -1) { - safe_fclose(&pgperr); + mutt_file_fclose(&pgperr); unlink(pgptmpfile); if (s->flags & MUTT_DISPLAY) state_attach_puts( @@ -879,7 +879,7 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, if (!pgp_use_gpg_agent()) fputs(PgpPass, pgpin); fputc('\n', pgpin); - safe_fclose(&pgpin); + mutt_file_fclose(&pgpin); /* Read the output from PGP, and make sure to change CRLF to LF, otherwise * read_mime_header has a hard time parsing the message. @@ -892,9 +892,9 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, fputs(buf, fpout); } - safe_fclose(&pgpout); + mutt_file_fclose(&pgpout); rv = mutt_wait_filter(thepid); - mutt_unlink(pgptmpfile); + mutt_file_unlink(pgptmpfile); fflush(pgperr); rewind(pgperr); @@ -902,7 +902,7 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, { mutt_error(_("Decryption failed")); pgp_void_passphrase(); - safe_fclose(&pgperr); + mutt_file_fclose(&pgperr); return NULL; } @@ -915,7 +915,7 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, p->goodsig = false; state_attach_puts(_("[-- End of PGP output --]\n\n"), s); } - safe_fclose(&pgperr); + mutt_file_fclose(&pgperr); fflush(fpout); rewind(fpout); @@ -981,7 +981,7 @@ int pgp_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body **cur saved_length = b->length; mutt_mktemp(tempfile, sizeof(tempfile)); - decoded_fp = safe_fopen(tempfile, "w+"); + decoded_fp = mutt_file_fopen(tempfile, "w+"); if (!decoded_fp) { mutt_perror(tempfile); @@ -1003,7 +1003,7 @@ int pgp_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body **cur } mutt_mktemp(tempfile, sizeof(tempfile)); - *fpout = safe_fopen(tempfile, "w+"); + *fpout = mutt_file_fopen(tempfile, "w+"); if (!*fpout) { mutt_perror(tempfile); @@ -1023,7 +1023,7 @@ int pgp_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body **cur b->type = saved_type; b->length = saved_length; b->offset = saved_offset; - safe_fclose(&decoded_fp); + mutt_file_fclose(&decoded_fp); } return rv; @@ -1043,7 +1043,7 @@ int pgp_encrypted_handler(struct Body *a, struct State *s) int rc = 0; mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = safe_fopen(tempfile, "w+"); + fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { if (s->flags & MUTT_DISPLAY) @@ -1095,8 +1095,8 @@ int pgp_encrypted_handler(struct Body *a, struct State *s) rc = -1; } - safe_fclose(&fpout); - mutt_unlink(tempfile); + mutt_file_fclose(&fpout); + mutt_file_unlink(tempfile); return rc; } @@ -1118,18 +1118,18 @@ struct Body *pgp_sign_message(struct Body *a) convert_to_7bit(a); /* Signed data _must_ be in 7-bit format. */ mutt_mktemp(sigfile, sizeof(sigfile)); - fp = safe_fopen(sigfile, "w"); + fp = mutt_file_fopen(sigfile, "w"); if (!fp) { return NULL; } mutt_mktemp(signedfile, sizeof(signedfile)); - sfp = safe_fopen(signedfile, "w"); + sfp = mutt_file_fopen(signedfile, "w"); if (!sfp) { mutt_perror(signedfile); - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(sigfile); return NULL; } @@ -1137,13 +1137,13 @@ struct Body *pgp_sign_message(struct Body *a) mutt_write_mime_header(a, sfp); fputc('\n', sfp); mutt_write_mime_body(a, sfp); - safe_fclose(&sfp); + mutt_file_fclose(&sfp); thepid = pgp_invoke_sign(&pgpin, &pgpout, &pgperr, -1, -1, -1, signedfile); if (thepid == -1) { mutt_perror(_("Can't open PGP subprocess!")); - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(sigfile); unlink(signedfile); return NULL; @@ -1152,7 +1152,7 @@ struct Body *pgp_sign_message(struct Body *a) if (!pgp_use_gpg_agent()) fputs(PgpPass, pgpin); fputc('\n', pgpin); - safe_fclose(&pgpin); + mutt_file_fclose(&pgpin); /* * Read back the PGP signature. Also, change MESSAGE=>SIGNATURE as @@ -1180,8 +1180,8 @@ struct Body *pgp_sign_message(struct Body *a) if (mutt_wait_filter(thepid) && option(OPT_PGP_CHECK_EXIT)) empty = true; - safe_fclose(&pgperr); - safe_fclose(&pgpout); + mutt_file_fclose(&pgperr); + mutt_file_fclose(&pgpout); unlink(signedfile); if (fclose(fp) != 0) @@ -1369,7 +1369,7 @@ struct Body *pgp_encrypt_message(struct Body *a, char *keylist, int sign) pid_t thepid; mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = safe_fopen(tempfile, "w+"); + fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { mutt_perror(tempfile); @@ -1377,24 +1377,24 @@ struct Body *pgp_encrypt_message(struct Body *a, char *keylist, int sign) } mutt_mktemp(pgperrfile, sizeof(pgperrfile)); - pgperr = safe_fopen(pgperrfile, "w+"); + pgperr = mutt_file_fopen(pgperrfile, "w+"); if (!pgperr) { mutt_perror(pgperrfile); unlink(tempfile); - safe_fclose(&fpout); + mutt_file_fclose(&fpout); return NULL; } unlink(pgperrfile); mutt_mktemp(pgpinfile, sizeof(pgpinfile)); - fptmp = safe_fopen(pgpinfile, "w"); + fptmp = mutt_file_fopen(pgpinfile, "w"); if (!fptmp) { mutt_perror(pgpinfile); unlink(tempfile); - safe_fclose(&fpout); - safe_fclose(&pgperr); + mutt_file_fclose(&fpout); + mutt_file_fclose(&pgperr); return NULL; } @@ -1404,13 +1404,13 @@ struct Body *pgp_encrypt_message(struct Body *a, char *keylist, int sign) mutt_write_mime_header(a, fptmp); fputc('\n', fptmp); mutt_write_mime_body(a, fptmp); - safe_fclose(&fptmp); + mutt_file_fclose(&fptmp); if ((thepid = pgp_invoke_encrypt(&pgpin, NULL, NULL, -1, fileno(fpout), fileno(pgperr), pgpinfile, keylist, sign)) == -1) { - safe_fclose(&fpout); - safe_fclose(&pgperr); + mutt_file_fclose(&fpout); + mutt_file_fclose(&pgperr); unlink(pgpinfile); return NULL; } @@ -1421,7 +1421,7 @@ struct Body *pgp_encrypt_message(struct Body *a, char *keylist, int sign) fputs(PgpPass, pgpin); fputc('\n', pgpin); } - safe_fclose(&pgpin); + mutt_file_fclose(&pgpin); if (mutt_wait_filter(thepid) && option(OPT_PGP_CHECK_EXIT)) empty = 1; @@ -1432,7 +1432,7 @@ struct Body *pgp_encrypt_message(struct Body *a, char *keylist, int sign) rewind(fpout); if (!empty) empty = (fgetc(fpout) == EOF); - safe_fclose(&fpout); + mutt_file_fclose(&fpout); fflush(pgperr); rewind(pgperr); @@ -1441,7 +1441,7 @@ struct Body *pgp_encrypt_message(struct Body *a, char *keylist, int sign) err = 1; fputs(buf, stdout); } - safe_fclose(&pgperr); + mutt_file_fclose(&pgperr); /* pause if there is any error output from PGP */ if (err) @@ -1519,11 +1519,11 @@ struct Body *pgp_traditional_encryptsign(struct Body *a, int flags, char *keylis } mutt_mktemp(pgpinfile, sizeof(pgpinfile)); - pgpin = safe_fopen(pgpinfile, "w"); + pgpin = mutt_file_fopen(pgpinfile, "w"); if (!pgpin) { mutt_perror(pgpinfile); - safe_fclose(&fp); + mutt_file_fclose(&fp); return NULL; } @@ -1559,21 +1559,21 @@ struct Body *pgp_traditional_encryptsign(struct Body *a, int flags, char *keylis else { send_charset = "us-ascii"; - mutt_copy_stream(fp, pgpin); + mutt_file_copy_stream(fp, pgpin); } - safe_fclose(&fp); - safe_fclose(&pgpin); + mutt_file_fclose(&fp); + mutt_file_fclose(&pgpin); mutt_mktemp(pgpoutfile, sizeof(pgpoutfile)); mutt_mktemp(pgperrfile, sizeof(pgperrfile)); - if ((pgpout = safe_fopen(pgpoutfile, "w+")) == NULL || - (pgperr = safe_fopen(pgperrfile, "w+")) == NULL) + if ((pgpout = mutt_file_fopen(pgpoutfile, "w+")) == NULL || + (pgperr = mutt_file_fopen(pgperrfile, "w+")) == NULL) { mutt_perror(pgpout ? pgperrfile : pgpoutfile); unlink(pgpinfile); if (pgpout) { - safe_fclose(&pgpout); + mutt_file_fclose(&pgpout); unlink(pgpoutfile); } return NULL; @@ -1585,9 +1585,9 @@ struct Body *pgp_traditional_encryptsign(struct Body *a, int flags, char *keylis fileno(pgperr), pgpinfile, keylist, flags)) == -1) { mutt_perror(_("Can't invoke PGP")); - safe_fclose(&pgpout); - safe_fclose(&pgperr); - mutt_unlink(pgpinfile); + mutt_file_fclose(&pgpout); + mutt_file_fclose(&pgperr); + mutt_file_unlink(pgpinfile); unlink(pgpoutfile); return NULL; } @@ -1596,12 +1596,12 @@ struct Body *pgp_traditional_encryptsign(struct Body *a, int flags, char *keylis *PgpPass = 0; if (flags & SIGN) fprintf(pgpin, "%s\n", PgpPass); - safe_fclose(&pgpin); + mutt_file_fclose(&pgpin); if (mutt_wait_filter(thepid) && option(OPT_PGP_CHECK_EXIT)) empty = true; - mutt_unlink(pgpinfile); + mutt_file_unlink(pgpinfile); fflush(pgpout); fflush(pgperr); @@ -1611,7 +1611,7 @@ struct Body *pgp_traditional_encryptsign(struct Body *a, int flags, char *keylis if (!empty) empty = (fgetc(pgpout) == EOF); - safe_fclose(&pgpout); + mutt_file_fclose(&pgpout); err = false; @@ -1621,7 +1621,7 @@ struct Body *pgp_traditional_encryptsign(struct Body *a, int flags, char *keylis fputs(buff, stdout); } - safe_fclose(&pgperr); + mutt_file_fclose(&pgperr); if (err) mutt_any_key_to_continue(NULL); diff --git a/ncrypt/pgpinvoke.c b/ncrypt/pgpinvoke.c index 45c39cff043..c864bb1f005 100644 --- a/ncrypt/pgpinvoke.c +++ b/ncrypt/pgpinvoke.c @@ -245,7 +245,7 @@ void pgp_invoke_import(const char *fname) memset(&cctx, 0, sizeof(cctx)); - mutt_quote_filename(_fname, sizeof(_fname), fname); + mutt_file_quote_filename(_fname, sizeof(_fname), fname); cctx.fname = _fname; cctx.signas = PgpSignAs; @@ -276,7 +276,7 @@ void pgp_invoke_getkeys(struct Address *addr) *tmp = '\0'; mutt_addrlist_to_local(addr); rfc822_write_address_single(tmp, sizeof(tmp), addr, 0); - mutt_quote_filename(buff, sizeof(buff), tmp); + mutt_file_quote_filename(buff, sizeof(buff), tmp); addr->personal = personal; @@ -326,7 +326,7 @@ pid_t pgp_invoke_list_keys(FILE **pgpin, FILE **pgpout, FILE **pgperr, struct ListNode *np; STAILQ_FOREACH(np, hints, entries) { - mutt_quote_filename(quoted, sizeof(quoted), (char *) np->data); + mutt_file_quote_filename(quoted, sizeof(quoted), (char *) np->data); snprintf(tmpuids, sizeof(tmpuids), "%s %s", uids, quoted); strcpy(uids, tmpuids); } diff --git a/ncrypt/pgpkey.c b/ncrypt/pgpkey.c index ff4a7782685..144b54ee88a 100644 --- a/ncrypt/pgpkey.c +++ b/ncrypt/pgpkey.c @@ -559,10 +559,10 @@ static struct PgpKeyInfo *pgp_select_key(struct PgpKeyInfo *keys, mutt_perror(_("Can't open /dev/null")); break; } - fp = safe_fopen(tempfile, "w"); + fp = mutt_file_fopen(tempfile, "w"); if (!fp) { - safe_fclose(&devnull); + mutt_file_fclose(&devnull); mutt_perror(_("Can't create temporary file")); break; } @@ -577,13 +577,13 @@ static struct PgpKeyInfo *pgp_select_key(struct PgpKeyInfo *keys, { mutt_perror(_("Can't create filter")); unlink(tempfile); - safe_fclose(&fp); - safe_fclose(&devnull); + mutt_file_fclose(&fp); + mutt_file_fclose(&devnull); } mutt_wait_filter(thepid); - safe_fclose(&fp); - safe_fclose(&devnull); + mutt_file_fclose(&fp); + mutt_file_fclose(&devnull); mutt_clear_error(); snprintf(cmd, sizeof(cmd), _("Key ID: 0x%s"), pgp_keyid(pgp_principal_key(KeyTable[menu->current]->parent))); @@ -736,7 +736,7 @@ struct Body *pgp_make_key_attachment(char *tempf) tempf = tempfb; } - tempfp = safe_fopen(tempf, tempf == tempfb ? "w" : "a"); + tempfp = mutt_file_fopen(tempf, tempf == tempfb ? "w" : "a"); if (!tempfp) { mutt_perror(_("Can't create temporary file")); @@ -747,7 +747,7 @@ struct Body *pgp_make_key_attachment(char *tempf) if (!devnull) { mutt_perror(_("Can't open /dev/null")); - safe_fclose(&tempfp); + mutt_file_fclose(&tempfp); if (tempf == tempfb) unlink(tempf); return NULL; @@ -760,15 +760,15 @@ struct Body *pgp_make_key_attachment(char *tempf) { mutt_perror(_("Can't create filter")); unlink(tempf); - safe_fclose(&tempfp); - safe_fclose(&devnull); + mutt_file_fclose(&tempfp); + mutt_file_fclose(&devnull); return NULL; } mutt_wait_filter(thepid); - safe_fclose(&tempfp); - safe_fclose(&devnull); + mutt_file_fclose(&tempfp); + mutt_file_fclose(&devnull); att = mutt_new_body(); att->filename = safe_strdup(tempf); diff --git a/ncrypt/pgpmicalg.c b/ncrypt/pgpmicalg.c index 6aa01a464ab..c7f31d860a7 100644 --- a/ncrypt/pgpmicalg.c +++ b/ncrypt/pgpmicalg.c @@ -165,7 +165,7 @@ static short pgp_find_hash(const char *fname) short rv = -1; mutt_mktemp(tempfile, sizeof(tempfile)); - out = safe_fopen(tempfile, "w+"); + out = mutt_file_fopen(tempfile, "w+"); if (!out) { mutt_perror(tempfile); @@ -195,8 +195,8 @@ static short pgp_find_hash(const char *fname) bye: - safe_fclose(&in); - safe_fclose(&out); + mutt_file_fclose(&in); + mutt_file_fclose(&out); pgp_release_packet(); return rv; } diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 42457f88b13..e7c749bee6d 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -180,7 +180,7 @@ static const char *fmt_smime_command(char *dest, size_t destlen, size_t col, int strfcpy(path, NONULL(SmimeCALocation), sizeof(path)); mutt_expand_path(path, sizeof(path)); - mutt_quote_filename(buf1, sizeof(buf1), path); + mutt_file_quote_filename(buf1, sizeof(buf1), path); if (stat(path, &sb) != 0 || !S_ISDIR(sb.st_mode)) snprintf(buf2, sizeof(buf2), "-CAfile %s", buf1); @@ -572,7 +572,7 @@ static struct SmimeKey *smime_get_candidates(char *search, short public) snprintf(index_file, sizeof(index_file), "%s/.index", public ? NONULL(SmimeCertificates) : NONULL(SmimeKeys)); - fp = safe_fopen(index_file, "r"); + fp = mutt_file_fopen(index_file, "r"); if (!fp) { mutt_perror(index_file); @@ -592,7 +592,7 @@ static struct SmimeKey *smime_get_candidates(char *search, short public) } } - safe_fclose(&fp); + mutt_file_fclose(&fp); return results; } @@ -909,31 +909,31 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, size_t len = 0; mutt_mktemp(tmpfname, sizeof(tmpfname)); - fperr = safe_fopen(tmpfname, "w+"); + fperr = mutt_file_fopen(tmpfname, "w+"); if (!fperr) { mutt_perror(tmpfname); return 1; } - mutt_unlink(tmpfname); + mutt_file_unlink(tmpfname); mutt_mktemp(tmpfname, sizeof(tmpfname)); - fpout = safe_fopen(tmpfname, "w+"); + fpout = mutt_file_fopen(tmpfname, "w+"); if (!fpout) { - safe_fclose(&fperr); + mutt_file_fclose(&fperr); mutt_perror(tmpfname); return 1; } - mutt_unlink(tmpfname); + mutt_file_unlink(tmpfname); if ((thepid = smime_invoke(NULL, NULL, NULL, -1, fileno(fpout), fileno(fperr), certificate, NULL, NULL, NULL, NULL, NULL, NULL, SmimeGetCertEmailCommand)) == -1) { mutt_message(_("Error: unable to create OpenSSL subprocess!")); - safe_fclose(&fperr); - safe_fclose(&fpout); + mutt_file_fclose(&fperr); + mutt_file_fclose(&fpout); return 1; } @@ -959,7 +959,7 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, if (ret == -1) { mutt_endwin(NULL); - mutt_copy_stream(fperr, stdout); + mutt_file_copy_stream(fperr, stdout); mutt_any_key_to_continue(_("Error: unable to create OpenSSL subprocess!")); ret = 1; } @@ -988,8 +988,8 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, else if (copy) ret = 2; - safe_fclose(&fpout); - safe_fclose(&fperr); + mutt_file_fclose(&fpout); + mutt_file_fclose(&fperr); return ret; } @@ -1003,19 +1003,19 @@ static char *smime_extract_certificate(char *infile) int empty; mutt_mktemp(tmpfname, sizeof(tmpfname)); - fperr = safe_fopen(tmpfname, "w+"); + fperr = mutt_file_fopen(tmpfname, "w+"); if (!fperr) { mutt_perror(tmpfname); return NULL; } - mutt_unlink(tmpfname); + mutt_file_unlink(tmpfname); mutt_mktemp(pk7out, sizeof(pk7out)); - fpout = safe_fopen(pk7out, "w+"); + fpout = mutt_file_fopen(pk7out, "w+"); if (!fpout) { - safe_fclose(&fperr); + mutt_file_fclose(&fperr); mutt_perror(pk7out); return NULL; } @@ -1027,9 +1027,9 @@ static char *smime_extract_certificate(char *infile) NULL, NULL, NULL, NULL, NULL, SmimePk7outCommand)) == -1) { mutt_any_key_to_continue(_("Error: unable to create OpenSSL subprocess!")); - safe_fclose(&fperr); - safe_fclose(&fpout); - mutt_unlink(pk7out); + mutt_file_fclose(&fperr); + mutt_file_fclose(&fpout); + mutt_file_unlink(pk7out); return NULL; } @@ -1043,20 +1043,20 @@ static char *smime_extract_certificate(char *infile) if (empty) { mutt_perror(pk7out); - mutt_copy_stream(fperr, stdout); - safe_fclose(&fpout); - safe_fclose(&fperr); - mutt_unlink(pk7out); + mutt_file_copy_stream(fperr, stdout); + mutt_file_fclose(&fpout); + mutt_file_fclose(&fperr); + mutt_file_unlink(pk7out); return NULL; } - safe_fclose(&fpout); + mutt_file_fclose(&fpout); mutt_mktemp(certfile, sizeof(certfile)); - fpout = safe_fopen(certfile, "w+"); + fpout = mutt_file_fopen(certfile, "w+"); if (!fpout) { - safe_fclose(&fperr); - mutt_unlink(pk7out); + mutt_file_fclose(&fperr); + mutt_file_unlink(pk7out); mutt_perror(certfile); return NULL; } @@ -1067,16 +1067,16 @@ static char *smime_extract_certificate(char *infile) NULL, NULL, NULL, NULL, NULL, SmimeGetCertCommand)) == -1) { mutt_any_key_to_continue(_("Error: unable to create OpenSSL subprocess!")); - safe_fclose(&fperr); - safe_fclose(&fpout); - mutt_unlink(pk7out); - mutt_unlink(certfile); + mutt_file_fclose(&fperr); + mutt_file_fclose(&fpout); + mutt_file_unlink(pk7out); + mutt_file_unlink(certfile); return NULL; } mutt_wait_filter(thepid); - mutt_unlink(pk7out); + mutt_file_unlink(pk7out); fflush(fpout); rewind(fpout); @@ -1085,15 +1085,15 @@ static char *smime_extract_certificate(char *infile) empty = (fgetc(fpout) == EOF); if (empty) { - mutt_copy_stream(fperr, stdout); - safe_fclose(&fpout); - safe_fclose(&fperr); - mutt_unlink(certfile); + mutt_file_copy_stream(fperr, stdout); + mutt_file_fclose(&fpout); + mutt_file_fclose(&fperr); + mutt_file_unlink(certfile); return NULL; } - safe_fclose(&fpout); - safe_fclose(&fperr); + mutt_file_fclose(&fpout); + mutt_file_fclose(&fperr); return safe_strdup(certfile); } @@ -1107,19 +1107,19 @@ static char *smime_extract_signer_certificate(char *infile) int empty; mutt_mktemp(tmpfname, sizeof(tmpfname)); - fperr = safe_fopen(tmpfname, "w+"); + fperr = mutt_file_fopen(tmpfname, "w+"); if (!fperr) { mutt_perror(tmpfname); return NULL; } - mutt_unlink(tmpfname); + mutt_file_unlink(tmpfname); mutt_mktemp(certfile, sizeof(certfile)); - fpout = safe_fopen(certfile, "w+"); + fpout = mutt_file_fopen(certfile, "w+"); if (!fpout) { - safe_fclose(&fperr); + mutt_file_fclose(&fperr); mutt_perror(certfile); return NULL; } @@ -1130,10 +1130,10 @@ static char *smime_extract_signer_certificate(char *infile) NULL, certfile, NULL, SmimeGetSignerCertCommand)) == -1) { mutt_any_key_to_continue(_("Error: unable to create OpenSSL subprocess!")); - safe_fclose(&fperr); - safe_fclose(&fpout); - mutt_unlink(pk7out); - mutt_unlink(certfile); + mutt_file_fclose(&fperr); + mutt_file_fclose(&fpout); + mutt_file_unlink(pk7out); + mutt_file_unlink(certfile); return NULL; } @@ -1147,16 +1147,16 @@ static char *smime_extract_signer_certificate(char *infile) if (empty) { mutt_endwin(NULL); - mutt_copy_stream(fperr, stdout); + mutt_file_copy_stream(fperr, stdout); mutt_any_key_to_continue(NULL); - safe_fclose(&fpout); - safe_fclose(&fperr); - mutt_unlink(certfile); + mutt_file_fclose(&fpout); + mutt_file_fclose(&fperr); + mutt_file_unlink(certfile); return NULL; } - safe_fclose(&fpout); - safe_fclose(&fperr); + mutt_file_fclose(&fpout); + mutt_file_fclose(&fperr); return safe_strdup(certfile); } @@ -1171,23 +1171,23 @@ void smime_invoke_import(char *infile, char *mailbox) pid_t thepid = -1; mutt_mktemp(tmpfname, sizeof(tmpfname)); - fperr = safe_fopen(tmpfname, "w+"); + fperr = mutt_file_fopen(tmpfname, "w+"); if (!fperr) { mutt_perror(tmpfname); return; } - mutt_unlink(tmpfname); + mutt_file_unlink(tmpfname); mutt_mktemp(tmpfname, sizeof(tmpfname)); - fpout = safe_fopen(tmpfname, "w+"); + fpout = mutt_file_fopen(tmpfname, "w+"); if (!fpout) { - safe_fclose(&fperr); + mutt_file_fclose(&fperr); mutt_perror(tmpfname); return; } - mutt_unlink(tmpfname); + mutt_file_unlink(tmpfname); buf[0] = '\0'; if (option(OPT_SMIME_ASK_CERT_LABEL)) @@ -1195,8 +1195,8 @@ void smime_invoke_import(char *infile, char *mailbox) if ((mutt_get_field(_("Label for certificate: "), buf, sizeof(buf), 0) != 0) || (buf[0] == 0)) { - safe_fclose(&fpout); - safe_fclose(&fperr); + mutt_file_fclose(&fpout); + mutt_file_fclose(&fperr); return; } } @@ -1215,11 +1215,11 @@ void smime_invoke_import(char *infile, char *mailbox) } fputs(buf, smimein); fputc('\n', smimein); - safe_fclose(&smimein); + mutt_file_fclose(&smimein); mutt_wait_filter(thepid); - mutt_unlink(certfile); + mutt_file_unlink(certfile); FREE(&certfile); } @@ -1228,11 +1228,11 @@ void smime_invoke_import(char *infile, char *mailbox) fflush(fperr); rewind(fperr); - mutt_copy_stream(fpout, stdout); - mutt_copy_stream(fperr, stdout); + mutt_file_copy_stream(fpout, stdout); + mutt_file_copy_stream(fperr, stdout); - safe_fclose(&fpout); - safe_fclose(&fperr); + mutt_file_fclose(&fpout); + mutt_file_fclose(&fperr); } int smime_verify_sender(struct Header *h) @@ -1242,7 +1242,7 @@ int smime_verify_sender(struct Header *h) int retval = 1; mutt_mktemp(tempfname, sizeof(tempfname)); - fpout = safe_fopen(tempfname, "w"); + fpout = mutt_file_fopen(tempfname, "w"); if (!fpout) { mutt_perror(tempfname); @@ -1256,7 +1256,7 @@ int smime_verify_sender(struct Header *h) mutt_copy_message_ctx(fpout, Context, h, 0, 0); fflush(fpout); - safe_fclose(&fpout); + mutt_file_fclose(&fpout); if (h->env->from) { @@ -1273,7 +1273,7 @@ int smime_verify_sender(struct Header *h) { if ((certfile = smime_extract_signer_certificate(tempfname))) { - mutt_unlink(tempfname); + mutt_file_unlink(tempfname); if (smime_handle_cert_email(certfile, mbox, 0, NULL, NULL)) { if (isendwin()) @@ -1281,7 +1281,7 @@ int smime_verify_sender(struct Header *h) } else retval = 0; - mutt_unlink(certfile); + mutt_file_unlink(certfile); FREE(&certfile); } else @@ -1290,7 +1290,7 @@ int smime_verify_sender(struct Header *h) else mutt_any_key_to_continue(_("no mbox")); - mutt_unlink(tempfname); + mutt_file_unlink(tempfname); return retval; } @@ -1327,7 +1327,7 @@ struct Body *smime_build_smime_entity(struct Body *a, char *certlist) pid_t thepid; mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = safe_fopen(tempfile, "w+"); + fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { mutt_perror(tempfile); @@ -1335,24 +1335,24 @@ struct Body *smime_build_smime_entity(struct Body *a, char *certlist) } mutt_mktemp(smimeerrfile, sizeof(smimeerrfile)); - smimeerr = safe_fopen(smimeerrfile, "w+"); + smimeerr = mutt_file_fopen(smimeerrfile, "w+"); if (!smimeerr) { mutt_perror(smimeerrfile); - safe_fclose(&fpout); - mutt_unlink(tempfile); + mutt_file_fclose(&fpout); + mutt_file_unlink(tempfile); return NULL; } - mutt_unlink(smimeerrfile); + mutt_file_unlink(smimeerrfile); mutt_mktemp(smimeinfile, sizeof(smimeinfile)); - fptmp = safe_fopen(smimeinfile, "w+"); + fptmp = mutt_file_fopen(smimeinfile, "w+"); if (!fptmp) { mutt_perror(smimeinfile); - mutt_unlink(tempfile); - safe_fclose(&fpout); - safe_fclose(&smimeerr); + mutt_file_unlink(tempfile); + mutt_file_fclose(&fpout); + mutt_file_fclose(&smimeerr); return NULL; } @@ -1375,28 +1375,28 @@ struct Body *smime_build_smime_entity(struct Body *a, char *certlist) mutt_write_mime_header(a, fptmp); fputc('\n', fptmp); mutt_write_mime_body(a, fptmp); - safe_fclose(&fptmp); + mutt_file_fclose(&fptmp); if ((thepid = smime_invoke_encrypt(&smimein, NULL, NULL, -1, fileno(fpout), fileno(smimeerr), smimeinfile, certfile)) == -1) { - safe_fclose(&smimeerr); - mutt_unlink(smimeinfile); - mutt_unlink(certfile); - safe_fclose(&fpout); + mutt_file_fclose(&smimeerr); + mutt_file_unlink(smimeinfile); + mutt_file_unlink(certfile); + mutt_file_fclose(&fpout); return NULL; } - safe_fclose(&smimein); + mutt_file_fclose(&smimein); mutt_wait_filter(thepid); - mutt_unlink(smimeinfile); - mutt_unlink(certfile); + mutt_file_unlink(smimeinfile); + mutt_file_unlink(certfile); fflush(fpout); rewind(fpout); empty = (fgetc(fpout) == EOF); - safe_fclose(&fpout); + mutt_file_fclose(&fpout); fflush(smimeerr); rewind(smimeerr); @@ -1405,7 +1405,7 @@ struct Body *smime_build_smime_entity(struct Body *a, char *certlist) err = 1; fputs(buf, stdout); } - safe_fclose(&smimeerr); + mutt_file_fclose(&smimeerr); /* pause if there is any error output from SMIME */ if (err) @@ -1416,7 +1416,7 @@ struct Body *smime_build_smime_entity(struct Body *a, char *certlist) /* fatal error while trying to encrypt message */ if (!err) mutt_any_key_to_continue(_("No output from OpenSSL...")); - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); return NULL; } @@ -1489,7 +1489,7 @@ struct Body *smime_sign_message(struct Body *a) convert_to_7bit(a); /* Signed data _must_ be in 7-bit format. */ mutt_mktemp(filetosign, sizeof(filetosign)); - sfp = safe_fopen(filetosign, "w+"); + sfp = mutt_file_fopen(filetosign, "w+"); if (!sfp) { mutt_perror(filetosign); @@ -1497,19 +1497,19 @@ struct Body *smime_sign_message(struct Body *a) } mutt_mktemp(signedfile, sizeof(signedfile)); - smimeout = safe_fopen(signedfile, "w+"); + smimeout = mutt_file_fopen(signedfile, "w+"); if (!smimeout) { mutt_perror(signedfile); - safe_fclose(&sfp); - mutt_unlink(filetosign); + mutt_file_fclose(&sfp); + mutt_file_unlink(filetosign); return NULL; } mutt_write_mime_header(a, sfp); fputc('\n', sfp); mutt_write_mime_body(a, sfp); - safe_fclose(&sfp); + mutt_file_fclose(&sfp); snprintf(SmimeKeyToUse, sizeof(SmimeKeyToUse), "%s/%s", NONULL(SmimeKeys), SmimeDefaultKey); @@ -1531,14 +1531,14 @@ struct Body *smime_sign_message(struct Body *a) fileno(smimeout), -1, filetosign)) == -1) { mutt_perror(_("Can't open OpenSSL subprocess!")); - safe_fclose(&smimeout); - mutt_unlink(signedfile); - mutt_unlink(filetosign); + mutt_file_fclose(&smimeout); + mutt_file_unlink(signedfile); + mutt_file_unlink(filetosign); return NULL; } fputs(SmimePass, smimein); fputc('\n', smimein); - safe_fclose(&smimein); + mutt_file_fclose(&smimein); mutt_wait_filter(thepid); @@ -1551,14 +1551,14 @@ struct Body *smime_sign_message(struct Body *a) err = 1; fputs(buffer, stdout); } - safe_fclose(&smimeerr); + mutt_file_fclose(&smimeerr); fflush(smimeout); rewind(smimeout); empty = (fgetc(smimeout) == EOF); - safe_fclose(&smimeout); + mutt_file_fclose(&smimeout); - mutt_unlink(filetosign); + mutt_file_unlink(filetosign); if (err) mutt_any_key_to_continue(NULL); @@ -1566,7 +1566,7 @@ struct Body *smime_sign_message(struct Body *a) if (empty) { mutt_any_key_to_continue(_("No output from OpenSSL...")); - mutt_unlink(signedfile); + mutt_file_unlink(signedfile); return NULL; /* fatal error while signing */ } @@ -1640,7 +1640,7 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) /* decode to a tempfile, saving the original destination */ fp = s->fpout; - s->fpout = safe_fopen(signedfile, "w"); + s->fpout = mutt_file_fopen(signedfile, "w"); if (!s->fpout) { mutt_perror(signedfile); @@ -1662,7 +1662,7 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) sigbdy->length = ftello(s->fpout); sigbdy->offset = 0; - safe_fclose(&s->fpout); + mutt_file_fclose(&s->fpout); /* restore final destination and substitute the tempfile for input */ s->fpout = fp; @@ -1675,11 +1675,11 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) sigbdy->type = origType; mutt_mktemp(smimeerrfile, sizeof(smimeerrfile)); - smimeerr = safe_fopen(smimeerrfile, "w+"); + smimeerr = mutt_file_fopen(smimeerrfile, "w+"); if (!smimeerr) { mutt_perror(smimeerrfile); - mutt_unlink(signedfile); + mutt_file_unlink(signedfile); return -1; } @@ -1689,7 +1689,7 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) tempfile, signedfile, 0)) != -1) { fflush(smimeout); - safe_fclose(&smimeout); + mutt_file_fclose(&smimeout); if (mutt_wait_filter(thepid)) badsig = -1; @@ -1702,7 +1702,7 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) fflush(smimeerr); rewind(smimeerr); - line = mutt_read_line(line, &linelen, smimeerr, &lineno, 0); + line = mutt_file_read_line(line, &linelen, smimeerr, &lineno, 0); if (linelen && (mutt_strcasecmp(line, "verification successful") == 0)) badsig = 0; @@ -1712,19 +1712,19 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) fflush(smimeerr); rewind(smimeerr); - mutt_copy_stream(smimeerr, s->fpout); - safe_fclose(&smimeerr); + mutt_file_copy_stream(smimeerr, s->fpout); + mutt_file_fclose(&smimeerr); state_attach_puts(_("[-- End of OpenSSL output --]\n\n"), s); - mutt_unlink(signedfile); - mutt_unlink(smimeerrfile); + mutt_file_unlink(signedfile); + mutt_file_unlink(smimeerrfile); sigbdy->length = tmplength; sigbdy->offset = tmpoffset; /* restore the original source stream */ - safe_fclose(&s->fpin); + mutt_file_fclose(&s->fpin); s->fpin = fp; return badsig; @@ -1754,7 +1754,7 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *o return NULL; mutt_mktemp(outfile, sizeof(outfile)); - smimeout = safe_fopen(outfile, "w+"); + smimeout = mutt_file_fopen(outfile, "w+"); if (!smimeout) { mutt_perror(outfile); @@ -1762,54 +1762,54 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *o } mutt_mktemp(errfile, sizeof(errfile)); - smimeerr = safe_fopen(errfile, "w+"); + smimeerr = mutt_file_fopen(errfile, "w+"); if (!smimeerr) { mutt_perror(errfile); - safe_fclose(&smimeout); + mutt_file_fclose(&smimeout); return NULL; } - mutt_unlink(errfile); + mutt_file_unlink(errfile); mutt_mktemp(tmpfname, sizeof(tmpfname)); - tmpfp = safe_fopen(tmpfname, "w+"); + tmpfp = mutt_file_fopen(tmpfname, "w+"); if (!tmpfp) { mutt_perror(tmpfname); - safe_fclose(&smimeout); - safe_fclose(&smimeerr); + mutt_file_fclose(&smimeout); + mutt_file_fclose(&smimeerr); return NULL; } fseeko(s->fpin, m->offset, SEEK_SET); - mutt_copy_bytes(s->fpin, tmpfp, m->length); + mutt_file_copy_bytes(s->fpin, tmpfp, m->length); fflush(tmpfp); - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); if ((type & ENCRYPT) && (thepid = smime_invoke_decrypt(&smimein, NULL, NULL, -1, fileno(smimeout), fileno(smimeerr), tmpfname)) == -1) { - safe_fclose(&smimeout); - mutt_unlink(tmpfname); + mutt_file_fclose(&smimeout); + mutt_file_unlink(tmpfname); if (s->flags & MUTT_DISPLAY) state_attach_puts( _("[-- Error: unable to create OpenSSL subprocess! --]\n"), s); - safe_fclose(&smimeerr); + mutt_file_fclose(&smimeerr); return NULL; } else if ((type & SIGNOPAQUE) && (thepid = smime_invoke_verify(&smimein, NULL, NULL, -1, fileno(smimeout), fileno(smimeerr), NULL, tmpfname, SIGNOPAQUE)) == -1) { - safe_fclose(&smimeout); - mutt_unlink(tmpfname); + mutt_file_fclose(&smimeout); + mutt_file_unlink(tmpfname); if (s->flags & MUTT_DISPLAY) state_attach_puts( _("[-- Error: unable to create OpenSSL subprocess! --]\n"), s); - safe_fclose(&smimeerr); + mutt_file_fclose(&smimeerr); return NULL; } @@ -1821,10 +1821,10 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *o fputc('\n', smimein); } - safe_fclose(&smimein); + mutt_file_fclose(&smimein); mutt_wait_filter(thepid); - mutt_unlink(tmpfname); + mutt_file_unlink(tmpfname); if (s->flags & MUTT_DISPLAY) { @@ -1837,7 +1837,7 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *o ungetc(c, smimeerr); crypt_current_time(s, "OpenSSL"); - mutt_copy_stream(smimeerr, s->fpout); + mutt_file_copy_stream(smimeerr, s->fpout); state_attach_puts(_("[-- End of OpenSSL output --]\n\n"), s); } @@ -1859,12 +1859,12 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *o else { mutt_mktemp(tmptmpfname, sizeof(tmptmpfname)); - fpout = safe_fopen(tmptmpfname, "w+"); + fpout = mutt_file_fopen(tmptmpfname, "w+"); if (!fpout) { mutt_perror(tmptmpfname); - safe_fclose(&smimeout); - safe_fclose(&smimeerr); + mutt_file_fclose(&smimeout); + mutt_file_fclose(&smimeerr); return NULL; } } @@ -1897,14 +1897,14 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *o s->fpin = tmpfp_buffer; } } - safe_fclose(&smimeout); + mutt_file_fclose(&smimeout); smimeout = NULL; - mutt_unlink(outfile); + mutt_file_unlink(outfile); if (!outFile) { - safe_fclose(&fpout); - mutt_unlink(tmptmpfname); + mutt_file_fclose(&fpout); + mutt_file_unlink(tmptmpfname); } fpout = NULL; } @@ -1925,7 +1925,7 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *o rewind(smimeerr); - line = mutt_read_line(line, &linelen, smimeerr, &lineno, 0); + line = mutt_file_read_line(line, &linelen, smimeerr, &lineno, 0); if (linelen && (mutt_strcasecmp(line, "verification successful") == 0)) m->goodsig = true; FREE(&line); @@ -1935,7 +1935,7 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *o m->goodsig = p->goodsig; m->badsig = p->badsig; } - safe_fclose(&smimeerr); + mutt_file_fclose(&smimeerr); return p; } @@ -1961,14 +1961,14 @@ int smime_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body **c fseeko(s.fpin, b->offset, SEEK_SET); mutt_mktemp(tempfile, sizeof(tempfile)); - tmpfp = safe_fopen(tempfile, "w+"); + tmpfp = mutt_file_fopen(tempfile, "w+"); if (!tmpfp) { mutt_perror(tempfile); return -1; } - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); s.fpout = tmpfp; mutt_decode_attachment(b, &s); fflush(tmpfp); @@ -1979,14 +1979,14 @@ int smime_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body **c s.fpout = 0; mutt_mktemp(tempfile, sizeof(tempfile)); - *fpout = safe_fopen(tempfile, "w+"); + *fpout = mutt_file_fopen(tempfile, "w+"); if (!*fpout) { mutt_perror(tempfile); rv = -1; goto bail; } - mutt_unlink(tempfile); + mutt_file_unlink(tempfile); *cur = smime_handle_entity(b, &s, *fpout); if (!*cur) @@ -2002,7 +2002,7 @@ int smime_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body **c b->type = origType; b->length = tmplength; b->offset = tmpoffset; - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); if (*fpout) rewind(*fpout); diff --git a/newsrc.c b/newsrc.c index ee1c16ccea3..1a731389250 100644 --- a/newsrc.c +++ b/newsrc.c @@ -124,8 +124,8 @@ void nntp_newsrc_close(struct NntpServer *nserv) return; mutt_debug(1, "Unlocking %s\n", nserv->newsrc_file); - mutt_unlock_file(nserv->newsrc_file, fileno(nserv->newsrc_fp)); - safe_fclose(&nserv->newsrc_fp); + mutt_file_unlock(nserv->newsrc_file, fileno(nserv->newsrc_fp)); + mutt_file_fclose(&nserv->newsrc_fp); } /** @@ -168,17 +168,17 @@ int nntp_newsrc_parse(struct NntpServer *nserv) if (nserv->newsrc_fp) { /* if we already have a handle, close it and reopen */ - safe_fclose(&nserv->newsrc_fp); + mutt_file_fclose(&nserv->newsrc_fp); } else { /* if file doesn't exist, create it */ - nserv->newsrc_fp = safe_fopen(nserv->newsrc_file, "a"); - safe_fclose(&nserv->newsrc_fp); + nserv->newsrc_fp = mutt_file_fopen(nserv->newsrc_file, "a"); + mutt_file_fclose(&nserv->newsrc_fp); } /* open .newsrc */ - nserv->newsrc_fp = safe_fopen(nserv->newsrc_file, "r"); + nserv->newsrc_fp = mutt_file_fopen(nserv->newsrc_file, "r"); if (!nserv->newsrc_fp) { mutt_perror(nserv->newsrc_file); @@ -188,9 +188,9 @@ int nntp_newsrc_parse(struct NntpServer *nserv) /* lock it */ mutt_debug(1, "Locking %s\n", nserv->newsrc_file); - if (mutt_lock_file(nserv->newsrc_file, fileno(nserv->newsrc_fp), 0, 1)) + if (mutt_file_lock(nserv->newsrc_file, fileno(nserv->newsrc_fp), 0, 1)) { - safe_fclose(&nserv->newsrc_fp); + mutt_file_fclose(&nserv->newsrc_fp); return -1; } @@ -388,7 +388,7 @@ static int update_file(char *filename, char *buf) while (true) { snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename); - fp = safe_fopen(tmpfile, "w"); + fp = mutt_file_fopen(tmpfile, "w"); if (!fp) { mutt_perror(tmpfile); @@ -400,7 +400,7 @@ static int update_file(char *filename, char *buf) mutt_perror(tmpfile); break; } - if (safe_fclose(&fp) == EOF) + if (mutt_file_fclose(&fp) == EOF) { mutt_perror(tmpfile); fp = NULL; @@ -417,7 +417,7 @@ static int update_file(char *filename, char *buf) break; } if (fp) - safe_fclose(&fp); + mutt_file_fclose(&fp); if (*tmpfile) unlink(tmpfile); if (rc) @@ -589,13 +589,13 @@ static int active_get_cache(struct NntpServer *nserv) cache_expand(file, sizeof(file), &nserv->conn->account, ".active"); mutt_debug(1, "Parsing %s\n", file); - fp = safe_fopen(file, "r"); + fp = mutt_file_fopen(file, "r"); if (!fp) return -1; if (fgets(buf, sizeof(buf), fp) == NULL || sscanf(buf, "%ld%s", &t, file) != 1 || t == 0) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return -1; } nserv->newgroups_time = t; @@ -604,7 +604,7 @@ static int active_get_cache(struct NntpServer *nserv) while (fgets(buf, sizeof(buf), fp)) nntp_add_group(buf, nserv); nntp_add_group(NULL, NULL); - safe_fclose(&fp); + mutt_file_fclose(&fp); mutt_clear_error(); return 0; } @@ -1019,7 +1019,7 @@ struct NntpServer *nntp_select_server(char *server, bool leave_lock) if (rc >= 0 && NewsCacheDir && *NewsCacheDir) { cache_expand(file, sizeof(file), &conn->account, NULL); - if (mutt_mkdir(file, S_IRWXU) < 0) + if (mutt_file_mkdir(file, S_IRWXU) < 0) { mutt_error(_("Can't create %s: %s."), file, strerror(errno)); mutt_sleep(2); diff --git a/nntp.c b/nntp.c index 9c5cd5c21eb..da0afeba0b2 100644 --- a/nntp.c +++ b/nntp.c @@ -1088,7 +1088,7 @@ static int parse_overview_line(char *line, void *data) /* convert overview line to header */ mutt_mktemp(tempfile, sizeof(tempfile)); - fp = safe_fopen(tempfile, "w+"); + fp = mutt_file_fopen(tempfile, "w+"); if (!fp) return -1; @@ -1101,7 +1101,7 @@ static int parse_overview_line(char *line, void *data) { if (strstr(header, ":full") == NULL && fputs(header, fp) == EOF) { - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(tempfile); return -1; } @@ -1113,7 +1113,7 @@ static int parse_overview_line(char *line, void *data) *field++ = '\0'; if (fputs(b, fp) == EOF || fputc('\n', fp) == EOF) { - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(tempfile); return -1; } @@ -1129,7 +1129,7 @@ static int parse_overview_line(char *line, void *data) hdr->env = mutt_read_rfc822_header(fp, hdr, 0, 0); hdr->env->newsgroups = safe_strdup(nntp_data->group); hdr->received = hdr->date_sent; - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(tempfile); #ifdef USE_HCACHE @@ -1342,7 +1342,7 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, char tempfile[_POSIX_PATH_MAX]; mutt_mktemp(tempfile, sizeof(tempfile)); - fp = safe_fopen(tempfile, "w+"); + fp = mutt_file_fopen(tempfile, "w+"); if (!fp) { mutt_perror(tempfile); @@ -1356,7 +1356,7 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, rc = nntp_fetch_lines(nntp_data, buf, sizeof(buf), NULL, fetch_tempfile, fp); if (rc) { - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(tempfile); if (rc < 0) break; @@ -1384,7 +1384,7 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, hdr = ctx->hdrs[ctx->msgcount] = mutt_new_header(); hdr->env = mutt_read_rfc822_header(fp, hdr, 0, 0); hdr->received = hdr->date_sent; - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(tempfile); } @@ -1592,7 +1592,7 @@ static int nntp_open_message(struct Context *ctx, struct Message *msg, int msgno { if (acache->index == hdr->index) { - msg->fp = safe_fopen(acache->path, "r"); + msg->fp = mutt_file_fopen(acache->path, "r"); if (msg->fp) return 0; } @@ -1624,7 +1624,7 @@ static int nntp_open_message(struct Context *ctx, struct Message *msg, int msgno mutt_mktemp(buf, sizeof(buf)); acache->path = safe_strdup(buf); acache->index = hdr->index; - msg->fp = safe_fopen(acache->path, "w+"); + msg->fp = mutt_file_fopen(acache->path, "w+"); if (!msg->fp) { mutt_perror(acache->path); @@ -1640,7 +1640,7 @@ static int nntp_open_message(struct Context *ctx, struct Message *msg, int msgno rc = nntp_fetch_lines(nntp_data, buf, sizeof(buf), fetch_msg, fetch_tempfile, msg->fp); if (rc) { - safe_fclose(&msg->fp); + mutt_file_fclose(&msg->fp); if (acache->path) { unlink(acache->path); @@ -1702,7 +1702,7 @@ static int nntp_open_message(struct Context *ctx, struct Message *msg, int msgno */ static int nntp_close_message(struct Context *ctx, struct Message *msg) { - return safe_fclose(&msg->fp); + return mutt_file_fclose(&msg->fp); } /** @@ -1728,7 +1728,7 @@ int nntp_post(const char *msg) nntp_data->group = NULL; } - fp = safe_fopen(msg, "r"); + fp = mutt_file_fopen(msg, "r"); if (!fp) { mutt_perror(msg); @@ -1738,13 +1738,13 @@ int nntp_post(const char *msg) strfcpy(buf, "POST\r\n", sizeof(buf)); if (nntp_query(nntp_data, buf, sizeof(buf)) < 0) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return -1; } if (buf[0] != '3') { mutt_error(_("Can't post article: %s"), buf); - safe_fclose(&fp); + mutt_file_fclose(&fp); return -1; } @@ -1764,7 +1764,7 @@ int nntp_post(const char *msg) -1, MUTT_SOCK_LOG_HDR) < 0) return nntp_connect_error(nntp_data->nserv); } - safe_fclose(&fp); + mutt_file_fclose(&fp); if ((buf[strlen(buf) - 1] != '\n' && mutt_socket_write_d(nntp_data->nserv->conn, "\r\n", -1, MUTT_SOCK_LOG_HDR) < 0) || @@ -2367,7 +2367,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid) int rc; mutt_mktemp(tempfile, sizeof(tempfile)); - fp = safe_fopen(tempfile, "w+"); + fp = mutt_file_fopen(tempfile, "w+"); if (!fp) { mutt_perror(tempfile); @@ -2379,7 +2379,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid) rc = nntp_fetch_lines(nntp_data, buf, sizeof(buf), NULL, fetch_tempfile, fp); if (rc) { - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(tempfile); if (rc < 0) return -1; @@ -2395,7 +2395,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid) hdr = ctx->hdrs[ctx->msgcount] = mutt_new_header(); hdr->data = safe_calloc(1, sizeof(struct NntpHeaderData)); hdr->env = mutt_read_rfc822_header(fp, hdr, 0, 0); - safe_fclose(&fp); + mutt_file_fclose(&fp); unlink(tempfile); /* get article number */ diff --git a/pager.c b/pager.c index 8fc7474eca8..c3f098bab68 100644 --- a/pager.c +++ b/pager.c @@ -1154,7 +1154,7 @@ static int fill_buffer(FILE *f, LOFF_T *last_pos, LOFF_T offset, unsigned char * { if (offset != *last_pos) fseeko(f, offset, SEEK_SET); - *buf = (unsigned char *) mutt_read_line((char *) *buf, blen, f, &l, MUTT_EOL); + *buf = (unsigned char *) mutt_file_read_line((char *) *buf, blen, f, &l, MUTT_EOL); if (!*buf) { fmt[0] = 0; @@ -2072,7 +2072,7 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e if (stat(fname, &rd.sb) != 0) { mutt_perror(fname); - safe_fclose(&rd.fp); + mutt_file_fclose(&rd.fp); return -1; } unlink(fname); @@ -3204,7 +3204,7 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e } } - safe_fclose(&rd.fp); + mutt_file_fclose(&rd.fp); if (IsHeader(extra)) { if (Context) diff --git a/pattern.c b/pattern.c index ba8d86ac336..dad2f08c447 100644 --- a/pattern.c +++ b/pattern.c @@ -958,7 +958,7 @@ static int msg_search(struct Context *ctx, struct Pattern *pat, int msgno) } #else mutt_mktemp(tempfile, sizeof(tempfile)); - s.fpout = safe_fopen(tempfile, "w+"); + s.fpout = mutt_file_fopen(tempfile, "w+"); if (!s.fpout) { mutt_perror(tempfile); @@ -978,7 +978,7 @@ static int msg_search(struct Context *ctx, struct Pattern *pat, int msgno) mx_close_message(ctx, &msg); if (s.fpout) { - safe_fclose(&s.fpout); + mutt_file_fclose(&s.fpout); #ifdef USE_FMEMOPEN FREE(&temp); #else @@ -1007,7 +1007,7 @@ static int msg_search(struct Context *ctx, struct Pattern *pat, int msgno) } else { /* fmemopen cannot handle empty buffers */ - fp = safe_fopen("/dev/null", "r"); + fp = mutt_file_fopen("/dev/null", "r"); if (!fp) { mutt_perror(_("Error opening /dev/null")); @@ -1066,7 +1066,7 @@ static int msg_search(struct Context *ctx, struct Pattern *pat, int msgno) if (option(OPT_THOROUGH_SEARCH)) { - safe_fclose(&fp); + mutt_file_fclose(&fp); #ifdef USE_FMEMOPEN if (tempsize) FREE(&temp); diff --git a/pgppubring.c b/pgppubring.c index 2b34c111527..b3cc8e1e52e 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -826,7 +826,7 @@ static void pgpring_find_candidates(char *ringfile, const char *hints[], int nhi fgetpos(rfp, &pos); } - safe_fclose(&rfp); + mutt_file_fclose(&rfp); } int main(int argc, char *const argv[]) diff --git a/pop.c b/pop.c index 620b46ab3eb..5d88b4a8aa9 100644 --- a/pop.c +++ b/pop.c @@ -88,7 +88,7 @@ static int pop_read_header(struct PopData *pop_data, struct Header *h) char tempfile[_POSIX_PATH_MAX]; mutt_mktemp(tempfile, sizeof(tempfile)); - f = safe_fopen(tempfile, "w+"); + f = mutt_file_fopen(tempfile, "w+"); if (!f) { mutt_perror(tempfile); @@ -151,7 +151,7 @@ static int pop_read_header(struct PopData *pop_data, struct Header *h) } } - safe_fclose(&f); + mutt_file_fclose(&f); unlink(tempfile); return ret; } @@ -609,7 +609,7 @@ static int pop_fetch_message(struct Context *ctx, struct Message *msg, int msgno /* no */ bcache = 0; mutt_mktemp(path, sizeof(path)); - msg->fp = safe_fopen(path, "w+"); + msg->fp = mutt_file_fopen(path, "w+"); if (!msg->fp) { mutt_perror(path); @@ -624,7 +624,7 @@ static int pop_fetch_message(struct Context *ctx, struct Message *msg, int msgno if (ret == 0) break; - safe_fclose(&msg->fp); + mutt_file_fclose(&msg->fp); /* if RETR failed (e.g. connection closed), be sure to remove either * the file in bcache or from POP's own cache since the next iteration @@ -693,7 +693,7 @@ static int pop_fetch_message(struct Context *ctx, struct Message *msg, int msgno static int pop_close_message(struct Context *ctx, struct Message *msg) { - return safe_fclose(&msg->fp); + return mutt_file_fclose(&msg->fp); } /** diff --git a/postpone.c b/postpone.c index 7c1ee8baf5d..16b9c9756e1 100644 --- a/postpone.c +++ b/postpone.c @@ -660,7 +660,7 @@ int mutt_prepare_template(FILE *fp, struct Context *ctx, struct Header *newhdr, } mutt_adv_mktemp(file, sizeof(file)); - s.fpout = safe_fopen(file, "w"); + s.fpout = mutt_file_fopen(file, "w"); if (!s.fpout) goto bail; @@ -687,7 +687,7 @@ int mutt_prepare_template(FILE *fp, struct Context *ctx, struct Header *newhdr, else mutt_decode_attachment(b, &s); - if (safe_fclose(&s.fpout) != 0) + if (mutt_file_fclose(&s.fpout) != 0) goto bail; mutt_str_replace(&b->filename, file); @@ -724,7 +724,7 @@ int mutt_prepare_template(FILE *fp, struct Context *ctx, struct Header *newhdr, /* that's it. */ if (bfp != fp) - safe_fclose(&bfp); + mutt_file_fclose(&bfp); if (msg) mx_close_message(ctx, &msg); diff --git a/query.c b/query.c index 59e2cc81cb8..c4357170078 100644 --- a/query.c +++ b/query.c @@ -138,7 +138,7 @@ static struct Query *run_query(char *s, int quiet) fgets(msg, sizeof(msg), fp); if ((p = strrchr(msg, '\n'))) *p = '\0'; - while ((buf = mutt_read_line(buf, &buflen, fp, &dummy, 0)) != NULL) + while ((buf = mutt_file_read_line(buf, &buflen, fp, &dummy, 0)) != NULL) { if ((p = strtok(buf, "\t\n"))) { @@ -165,7 +165,7 @@ static struct Query *run_query(char *s, int quiet) } } FREE(&buf); - safe_fclose(&fp); + mutt_file_fclose(&fp); if (mutt_wait_filter(thepid)) { mutt_debug(1, "Error: %s\n", msg); diff --git a/recvattach.c b/recvattach.c index 2b3d7a45485..3bbbab30295 100644 --- a/recvattach.c +++ b/recvattach.c @@ -438,7 +438,8 @@ static int query_save_attachment(FILE *fp, struct Body *body, if (body->filename) { if (directory && *directory) - mutt_concat_path(buf, *directory, mutt_basename(body->filename), sizeof(buf)); + mutt_file_concat_path(buf, *directory, mutt_file_basename(body->filename), + sizeof(buf)); else strfcpy(buf, body->filename, sizeof(buf)); } @@ -535,7 +536,7 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, { int append = 0; - strfcpy(buf, mutt_basename(NONULL(top->filename)), sizeof(buf)); + strfcpy(buf, mutt_file_basename(NONULL(top->filename)), sizeof(buf)); prepend_curdir(buf, sizeof(buf)); if (mutt_get_field(_("Save to file: "), buf, sizeof(buf), MUTT_FILE | MUTT_CLEAR) != 0 || @@ -548,7 +549,7 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, if (rc == 0 && AttachSep && (fpout = fopen(tfile, "a")) != NULL) { fprintf(fpout, "%s", AttachSep); - safe_fclose(&fpout); + mutt_file_fclose(&fpout); } } else @@ -557,7 +558,7 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, if (rc == 0 && AttachSep && (fpout = fopen(tfile, "a")) != NULL) { fprintf(fpout, "%s", AttachSep); - safe_fclose(&fpout); + mutt_file_fclose(&fpout); } } } @@ -617,8 +618,8 @@ static void query_pipe_attachment(char *command, FILE *fp, struct Body *body, bo { if (filter) { - mutt_unlink(body->filename); - mutt_rename_file(tfile, body->filename); + mutt_file_unlink(body->filename); + mutt_file_rename(tfile, body->filename); mutt_update_encoding(body); mutt_message(_("Attachment filtered.")); } @@ -626,7 +627,7 @@ static void query_pipe_attachment(char *command, FILE *fp, struct Body *body, bo else { if (filter && tfile[0]) - mutt_unlink(tfile); + mutt_file_unlink(tfile); } } @@ -649,8 +650,8 @@ static void pipe_attachment(FILE *fp, struct Body *b, struct State *state) mutt_perror("fopen"); return; } - mutt_copy_stream(ifp, state->fpout); - safe_fclose(&ifp); + mutt_file_copy_stream(ifp, state->fpout); + mutt_file_fclose(&ifp); if (AttachSep) state_puts(AttachSep, state); } @@ -705,7 +706,7 @@ void mutt_pipe_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, mutt_endwin(NULL); thepid = mutt_create_filter(buf, &state.fpout, NULL, NULL); pipe_attachment_list(buf, actx, fp, tag, top, filter, &state); - safe_fclose(&state.fpout); + mutt_file_fclose(&state.fpout); if (mutt_wait_filter(thepid) != 0 || option(OPT_WAIT_KEY)) mutt_any_key_to_continue(NULL); } @@ -776,13 +777,13 @@ static void print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, ifp = fopen(newfile, "r"); if (ifp) { - mutt_copy_stream(ifp, state->fpout); - safe_fclose(&ifp); + mutt_file_copy_stream(ifp, state->fpout); + mutt_file_fclose(&ifp); if (AttachSep) state_puts(AttachSep, state); } } - mutt_unlink(newfile); + mutt_file_unlink(newfile); } } else @@ -811,7 +812,7 @@ void mutt_print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, stru memset(&state, 0, sizeof(struct State)); thepid = mutt_create_filter(NONULL(PrintCommand), &state.fpout, NULL, NULL); print_attachment_list(actx, fp, tag, top, &state); - safe_fclose(&state.fpout); + mutt_file_fclose(&state.fpout); if (mutt_wait_filter(thepid) != 0 || option(OPT_WAIT_KEY)) mutt_any_key_to_continue(NULL); } @@ -973,7 +974,7 @@ static void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Header secured = !crypt_smime_decrypt_mime(outer_fp, &new_fp, outer_new_body, &new_body); mutt_free_body(&outer_new_body); - safe_fclose(&outer_fp); + mutt_file_fclose(&outer_fp); } if (secured) diff --git a/recvcmd.c b/recvcmd.c index babafcf563c..cdac9c9ff71 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -418,7 +418,7 @@ static void attach_forward_bodies(FILE *fp, struct Header *hdr, struct AttachCtx mutt_make_forward_subject(tmphdr->env, Context, parent_hdr); mutt_mktemp(tmpbody, sizeof(tmpbody)); - tmpfp = safe_fopen(tmpbody, "w"); + tmpfp = mutt_file_fopen(tmpbody, "w"); if (!tmpfp) { mutt_error(_("Can't open temporary file %s."), tmpbody); @@ -524,7 +524,7 @@ static void attach_forward_bodies(FILE *fp, struct Header *hdr, struct AttachCtx mutt_forward_trailer(Context, parent_hdr, tmpfp); - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); tmpfp = NULL; /* now that we have the template, send it. */ @@ -535,8 +535,8 @@ static void attach_forward_bodies(FILE *fp, struct Header *hdr, struct AttachCtx if (tmpfp) { - safe_fclose(&tmpfp); - mutt_unlink(tmpbody); + mutt_file_fclose(&tmpfp); + mutt_file_unlink(tmpbody); } mutt_free_header(&tmphdr); @@ -590,7 +590,7 @@ static void attach_forward_msgs(FILE *fp, struct Header *hdr, /* no MIME encapsulation */ mutt_mktemp(tmpbody, sizeof(tmpbody)); - tmpfp = safe_fopen(tmpbody, "w"); + tmpfp = mutt_file_fopen(tmpbody, "w"); if (!tmpfp) { mutt_error(_("Can't create %s."), tmpbody); @@ -633,7 +633,7 @@ static void attach_forward_msgs(FILE *fp, struct Header *hdr, } } } - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); } else if (rc == MUTT_YES) /* do MIME encapsulation - we don't need to do much here */ { @@ -853,7 +853,7 @@ void mutt_attach_reply(FILE *fp, struct Header *hdr, struct AttachCtx *actx, } mutt_mktemp(tmpbody, sizeof(tmpbody)); - tmpfp = safe_fopen(tmpbody, "w"); + tmpfp = mutt_file_fopen(tmpbody, "w"); if (!tmpfp) { mutt_error(_("Can't create %s."), tmpbody); @@ -926,12 +926,12 @@ void mutt_attach_reply(FILE *fp, struct Header *hdr, struct AttachCtx *actx, copy_problematic_attachments(&tmphdr->content, actx, 0) == NULL) { mutt_free_header(&tmphdr); - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); return; } } - safe_fclose(&tmpfp); + mutt_file_fclose(&tmpfp); if (ci_send_message(flags, tmphdr, tmpbody, NULL, parent_hdr ? parent_hdr : (cur ? cur->hdr : NULL)) == 0) diff --git a/remailer.c b/remailer.c index a7b3ae5a9aa..4830c22b2e7 100644 --- a/remailer.c +++ b/remailer.c @@ -727,7 +727,7 @@ int mix_send_message(struct ListHead *chain, const char *tempfile) STAILQ_FOREACH(np, chain, entries) { strfcpy(tmp, cmd, sizeof(tmp)); - mutt_quote_filename(cd_quoted, sizeof(cd_quoted), np->data); + mutt_file_quote_filename(cd_quoted, sizeof(cd_quoted), np->data); snprintf(cmd, sizeof(cmd), "%s%s%s", tmp, (np == STAILQ_FIRST(chain)) ? " -l " : ",", cd_quoted); } diff --git a/rfc1524.c b/rfc1524.c index ab2b3fe0f30..1b070109966 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -70,7 +70,7 @@ int rfc1524_expand_command(struct Body *a, char *filename, char *_type, char *co strfcpy(type, _type, sizeof(type)); if (option(OPT_MAILCAP_SANITIZE)) - mutt_sanitize_filename(type, 0); + mutt_file_sanitize_filename(type, 0); while (x < clen - 1 && command[x] && y < sizeof(buf) - 1) { @@ -97,18 +97,18 @@ int rfc1524_expand_command(struct Body *a, char *filename, char *_type, char *co _pvalue = mutt_get_parameter(param, a->parameter); strfcpy(pvalue, NONULL(_pvalue), sizeof(pvalue)); if (option(OPT_MAILCAP_SANITIZE)) - mutt_sanitize_filename(pvalue, 0); + mutt_file_sanitize_filename(pvalue, 0); - y += mutt_quote_filename(buf + y, sizeof(buf) - y, pvalue); + y += mutt_file_quote_filename(buf + y, sizeof(buf) - y, pvalue); } else if (command[x] == 's' && filename != NULL) { - y += mutt_quote_filename(buf + y, sizeof(buf) - y, filename); + y += mutt_file_quote_filename(buf + y, sizeof(buf) - y, filename); needspipe = false; } else if (command[x] == 't') { - y += mutt_quote_filename(buf + y, sizeof(buf) - y, type); + y += mutt_file_quote_filename(buf + y, sizeof(buf) - y, type); } x++; } @@ -210,7 +210,7 @@ static int rfc1524_mailcap_parse(struct Body *a, char *filename, char *type, fp = fopen(filename, "r"); if (fp) { - while (!found && (buf = mutt_read_line(buf, &buflen, fp, &line, MUTT_CONT)) != NULL) + while (!found && (buf = mutt_file_read_line(buf, &buflen, fp, &line, MUTT_CONT)) != NULL) { /* ignore comments */ if (*buf == '#') @@ -349,8 +349,8 @@ static int rfc1524_mailcap_parse(struct Body *a, char *filename, char *type, entry->copiousoutput = false; } } - } /* while (!found && (buf = mutt_read_line ())) */ - safe_fclose(&fp); + } /* while (!found && (buf = mutt_file_read_line ())) */ + mutt_file_fclose(&fp); } /* if ((fp = fopen ())) */ FREE(&buf); return found; diff --git a/rfc3676.c b/rfc3676.c index 8c42f15456b..16b268a8538 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -286,7 +286,7 @@ int rfc3676_handler(struct Body *a, struct State *s) mutt_debug(4, "f=f: DelSp: %s\n", delsp ? "yes" : "no"); - while ((buf = mutt_read_line(buf, &sz, s->fpin, NULL, 0))) + while ((buf = mutt_file_read_line(buf, &sz, s->fpin, NULL, 0))) { buf_len = mutt_strlen(buf); newql = get_quote_level(buf); @@ -365,15 +365,15 @@ void rfc3676_space_stuff(struct Header *hdr) mutt_debug(2, "f=f: postprocess %s\n", hdr->content->filename); - in = safe_fopen(hdr->content->filename, "r"); + in = mutt_file_fopen(hdr->content->filename, "r"); if (!in) return; mutt_mktemp(tmpfile, sizeof(tmpfile)); - out = safe_fopen(tmpfile, "w+"); + out = mutt_file_fopen(tmpfile, "w+"); if (!out) { - safe_fclose(&in); + mutt_file_fclose(&in); return; } @@ -397,9 +397,9 @@ void rfc3676_space_stuff(struct Header *hdr) } fputs(buf, out); } - safe_fclose(&in); - safe_fclose(&out); - mutt_set_mtime(hdr->content->filename, tmpfile); + mutt_file_fclose(&in); + mutt_file_fclose(&out); + mutt_file_set_mtime(hdr->content->filename, tmpfile); unlink(hdr->content->filename); mutt_str_replace(&hdr->content->filename, tmpfile); } diff --git a/send.c b/send.c index c18b4ad8bd6..0859e2e1324 100644 --- a/send.c +++ b/send.c @@ -78,8 +78,8 @@ static void append_signature(FILE *f) { if (option(OPT_SIG_DASHES)) fputs("\n-- \n", f); - mutt_copy_stream(tmpfp, f); - safe_fclose(&tmpfp); + mutt_file_copy_stream(tmpfp, f); + mutt_file_fclose(&tmpfp); if (thepid != -1) mutt_wait_filter(thepid); } @@ -1096,7 +1096,7 @@ static int send_message(struct Header *msg) /* Write out the message in MIME form. */ mutt_mktemp(tempfile, sizeof(tempfile)); - tempfp = safe_fopen(tempfile, "w"); + tempfp = mutt_file_fopen(tempfile, "w"); if (!tempfp) return -1; @@ -1120,7 +1120,7 @@ static int send_message(struct Header *msg) if ((mutt_write_mime_body(msg->content, tempfp) == -1)) { - safe_fclose(&tempfp); + mutt_file_fclose(&tempfp); unlink(tempfile); return -1; } @@ -1187,7 +1187,7 @@ static void fix_end_of_file(const char *data) { FILE *fp = NULL; - fp = safe_fopen(data, "a+"); + fp = mutt_file_fopen(data, "a+"); if (!fp) return; if (fseek(fp, -1, SEEK_END) >= 0) @@ -1196,7 +1196,7 @@ static void fix_end_of_file(const char *data) if (c != '\n') fputc('\n', fp); } - safe_fclose(&fp); + mutt_file_fclose(&fp); } int mutt_compose_to_sender(struct Header *hdr) @@ -1286,7 +1286,7 @@ static int search_attach_keyword(char *filename) if (!AttachKeyword.regex) return 0; - FILE *attf = safe_fopen(filename, "r"); + FILE *attf = mutt_file_fopen(filename, "r"); if (!attf) return 0; @@ -1303,7 +1303,7 @@ static int search_attach_keyword(char *filename) } } FREE(&inputline); - safe_fclose(&attf); + mutt_file_fclose(&attf); return found; } @@ -1404,7 +1404,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, if (flags & (SENDPOSTPONED | SENDRESEND)) { - tempfp = safe_fopen(msg->content->filename, "a+"); + tempfp = mutt_file_fopen(msg->content->filename, "a+"); if (!tempfp) { mutt_perror(msg->content->filename); @@ -1448,17 +1448,17 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, if (!tempfile) { mutt_mktemp(buffer, sizeof(buffer)); - tempfp = safe_fopen(buffer, "w+"); + tempfp = mutt_file_fopen(buffer, "w+"); msg->content->filename = safe_strdup(buffer); } else { - tempfp = safe_fopen(tempfile, "a+"); + tempfp = mutt_file_fopen(tempfile, "a+"); msg->content->filename = safe_strdup(tempfile); } } else - tempfp = safe_fopen(msg->content->filename, "a+"); + tempfp = mutt_file_fopen(msg->content->filename, "a+"); if (!tempfp) { @@ -1598,7 +1598,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, process_user_header(msg->env); if (flags & SENDBATCH) - mutt_copy_stream(stdin, tempfp); + mutt_file_copy_stream(stdin, tempfp); if (option(OPT_SIG_ON_TOP) && !(flags & (SENDMAILX | SENDKEY | SENDBATCH)) && Editor && (mutt_strcmp(Editor, "builtin") != 0)) @@ -1627,7 +1627,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, msg->env->from->personal = safe_strdup(RealName); if (!((WithCrypto & APPLICATION_PGP) && (flags & SENDKEY))) - safe_fclose(&tempfp); + mutt_file_fclose(&tempfp); if (flags & SENDMAILX) { @@ -1637,7 +1637,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, else if (!(flags & SENDBATCH)) { struct stat st; - time_t mtime = mutt_decrease_mtime(msg->content->filename, NULL); + time_t mtime = mutt_file_decrease_mtime(msg->content->filename, NULL); mutt_update_encoding(msg->content); @@ -2231,7 +2231,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, } } - safe_fclose(&tempfp); + mutt_file_fclose(&tempfp); if (!(flags & SENDNOFREEHEADER)) mutt_free_header(&msg); diff --git a/sendlib.c b/sendlib.c index 564a929f0cb..eec383cdf87 100644 --- a/sendlib.c +++ b/sendlib.c @@ -489,11 +489,11 @@ int mutt_write_mime_body(struct Body *a, FILE *f) else if (a->type == TYPETEXT && (!a->noconv)) encode_8bit(fc, f, write_as_text_part(a)); else - mutt_copy_stream(fpin, f); + mutt_file_copy_stream(fpin, f); mutt_allow_interrupt(0); fgetconv_close(&fc); - safe_fclose(&fpin); + mutt_file_fclose(&fpin); if (SigInt == 1) { @@ -958,7 +958,7 @@ struct Content *mutt_get_content_info(const char *fname, struct Body *b) FREE(&b->charset); b->charset = fromcode; FREE(&tocode); - safe_fclose(&fp); + mutt_file_fclose(&fp); return info; } } @@ -968,7 +968,7 @@ struct Content *mutt_get_content_info(const char *fname, struct Body *b) update_content_info(info, &state, buffer, r); update_content_info(info, &state, 0, 0); - safe_fclose(&fp); + mutt_file_fclose(&fp); if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset)) mutt_set_parameter( @@ -1092,7 +1092,7 @@ int mutt_lookup_mime_type(struct Body *att, const char *path) p = NULL; } } - safe_fclose(&f); + mutt_file_fclose(&f); } } @@ -1140,7 +1140,7 @@ static void transform_to_7bit(struct Body *a, FILE *fpin) a->force_charset = true; mutt_mktemp(buff, sizeof(buff)); - s.fpout = safe_fopen(buff, "w"); + s.fpout = mutt_file_fopen(buff, "w"); if (!s.fpout) { mutt_perror("fopen"); @@ -1148,7 +1148,7 @@ static void transform_to_7bit(struct Body *a, FILE *fpin) } s.fpin = fpin; mutt_decode_attachment(a, &s); - safe_fclose(&s.fpout); + mutt_file_fclose(&s.fpout); FREE(&a->d_filename); a->d_filename = a->filename; a->filename = safe_strdup(buff); @@ -1190,13 +1190,13 @@ void mutt_message_to_7bit(struct Body *a, FILE *fp) if (stat(a->filename, &sb) == -1) { mutt_perror("stat"); - safe_fclose(&fpin); + mutt_file_fclose(&fpin); } a->length = sb.st_size; } mutt_mktemp(temp, sizeof(temp)); - fpout = safe_fopen(temp, "w+"); + fpout = mutt_file_fopen(temp, "w+"); if (!fpout) { mutt_perror("fopen"); @@ -1223,9 +1223,9 @@ void mutt_message_to_7bit(struct Body *a, FILE *fp) FREE(&line); if (fpin && fpin != fp) - safe_fclose(&fpin); + mutt_file_fclose(&fpin); if (fpout) - safe_fclose(&fpout); + mutt_file_fclose(&fpout); else return; @@ -1363,7 +1363,7 @@ struct Body *mutt_make_message_attach(struct Context *ctx, struct Header *hdr, i } mutt_mktemp(buffer, sizeof(buffer)); - fp = safe_fopen(buffer, "w+"); + fp = mutt_file_fopen(buffer, "w+"); if (!fp) return NULL; @@ -1429,7 +1429,7 @@ struct Body *mutt_make_message_attach(struct Context *ctx, struct Header *hdr, i mutt_update_encoding(body); body->parts = body->hdr->content; - safe_fclose(&fp); + mutt_file_fclose(&fp); return body; } @@ -1452,7 +1452,7 @@ static void run_mime_type_query(struct Body *att) return; } - buf = mutt_read_line(buf, &buflen, fp, &dummy, 0); + buf = mutt_file_read_line(buf, &buflen, fp, &dummy, 0); if (buf) { if (strchr(buf, '/')) @@ -1460,8 +1460,8 @@ static void run_mime_type_query(struct Body *att) FREE(&buf); } - safe_fclose(&fp); - safe_fclose(&fperr); + mutt_file_fclose(&fp); + mutt_file_fclose(&fperr); mutt_wait_filter(thepid); } @@ -2727,7 +2727,7 @@ static int bounce_message(FILE *fp, struct Header *h, struct Address *to, fp = msg->fp; mutt_mktemp(tempfile, sizeof(tempfile)); - f = safe_fopen(tempfile, "w"); + f = mutt_file_fopen(tempfile, "w"); if (f) { int ch_flags = CH_XMIT | CH_NONEWLINE | CH_NOQFROM; @@ -2745,9 +2745,9 @@ static int bounce_message(FILE *fp, struct Header *h, struct Address *to, mutt_write_address_list(to, f, 11, 0); mutt_copy_header(fp, h, f, ch_flags, NULL); fputc('\n', f); - mutt_copy_bytes(fp, f, h->content->length); + mutt_file_copy_bytes(fp, f, h->content->length); FREE(&msgid_str); - if (safe_fclose(&f) != 0) + if (mutt_file_fclose(&f) != 0) { mutt_perror(tempfile); unlink(tempfile); @@ -2954,7 +2954,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, if (f.magic == MUTT_MMDF || f.magic == MUTT_MBOX) { mutt_mktemp(tempfile, sizeof(tempfile)); - tempfp = safe_fopen(tempfile, "w+"); + tempfp = mutt_file_fopen(tempfile, "w+"); if (!tempfp) { mutt_perror(tempfile); @@ -2973,7 +2973,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, msg = mx_open_new_message(&f, hdr, onm_flags); if (!msg) { - safe_fclose(&tempfp); + mutt_file_fclose(&tempfp); mx_close_mailbox(&f, NULL); return -1; } @@ -3088,7 +3088,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, if (ferror(tempfp)) { mutt_debug(1, "mutt_write_fcc(): %s: write failed.\n", tempfile); - safe_fclose(&tempfp); + mutt_file_fclose(&tempfp); unlink(tempfile); mx_commit_message(msg, &f); /* XXX - really? */ mx_close_message(&f, &msg); @@ -3105,7 +3105,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, /* copy the body and clean up */ rewind(tempfp); - r = mutt_copy_stream(tempfp, msg->fp); + r = mutt_file_copy_stream(tempfp, msg->fp); if (fclose(tempfp) != 0) r = -1; /* if there was an error, leave the temp version */ diff --git a/smtp.c b/smtp.c index e4aa274608e..9e34099812f 100644 --- a/smtp.c +++ b/smtp.c @@ -192,12 +192,12 @@ static int smtp_data(struct Connection *conn, const char *msgfile) snprintf(buf, sizeof(buf), "DATA\r\n"); if (mutt_socket_write(conn, buf) == -1) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return SMTP_ERR_WRITE; } if ((r = smtp_get_resp(conn))) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return r; } @@ -211,23 +211,23 @@ static int smtp_data(struct Connection *conn, const char *msgfile) { if (mutt_socket_write_d(conn, ".", -1, MUTT_SOCK_LOG_FULL) == -1) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return SMTP_ERR_WRITE; } } if (mutt_socket_write_d(conn, buf, -1, MUTT_SOCK_LOG_FULL) == -1) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return SMTP_ERR_WRITE; } mutt_progress_update(&progress, ftell(fp), -1); } if (!term && buflen && mutt_socket_write_d(conn, "\r\n", -1, MUTT_SOCK_LOG_FULL) == -1) { - safe_fclose(&fp); + mutt_file_fclose(&fp); return SMTP_ERR_WRITE; } - safe_fclose(&fp); + mutt_file_fclose(&fp); /* terminate the message body */ if (mutt_socket_write(conn, ".\r\n") == -1)