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)
}
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));
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."));
fseek_err:
mutt_perror(_("Error seeking in alias file"));
- safe_fclose(&rc);
+ mutt_file_fclose(&rc);
return;
}
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;
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;
}
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;
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."));
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;
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;
if (fp)
{
fname = safe_strdup(a->filename);
- mutt_sanitize_filename(fname, 1);
+ mutt_file_sanitize_filename(fname, 1);
}
else
fname = a->filename;
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));
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;
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;
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;
}
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");
s.fpin = fp;
mutt_decode_attachment(b, &s);
- safe_fclose(&s.fpout);
+ mutt_file_fclose(&s.fpout);
}
else
{
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;
if (flags == MUTT_SAVE_OVERWRITE)
return fopen(path, "w");
- return safe_fopen(path, "w");
+ return mutt_file_fopen(path, "w");
}
/**
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);
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;
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)
{
if (stat(m->filename, &st) == -1)
{
mutt_perror("stat");
- safe_fclose(&s.fpout);
+ mutt_file_fclose(&s.fpout);
return -1;
}
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;
m->parts = saved_parts;
m->hdr = saved_hdr;
}
- safe_fclose(&s.fpin);
+ mutt_file_fclose(&s.fpin);
}
return ret;
{
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)
{
{
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);
}
}
if (fp)
- mutt_unlink(newfile);
+ mutt_file_unlink(newfile);
else if (unlink_newfile)
unlink(newfile);
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
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++)
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");
}
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;
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)
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));
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;
}
#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
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));
}
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 */
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);
}
/* 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)
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)
{
if ((f = fopen(path, "rb")))
{
rc = test_last_status_new(f);
- safe_fclose(&f);
+ mutt_file_fclose(&f);
}
return rc;
}
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!"));
if (filterpid < 0)
{
mutt_error(_("Cannot create display filter"));
- safe_fclose(&fpfilterout);
+ mutt_file_fclose(&fpfilterout);
unlink(tempfile);
return 0;
}
#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)
{
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);
}
/* 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);
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);
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));
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;
}
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)
{
}
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);
}
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)
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;
}
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);
}
/**
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;
}
ERR_clear_error();
X509_free(cert);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return rv;
}
if (!X509_digest(peercert, EVP_sha256(), peermd, &peermdlen))
{
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return 0;
}
if (!pass)
ERR_clear_error();
X509_free(cert);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return pass;
}
{
if (PEM_write_X509(fp, cert))
done = 1;
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
}
if (!done)
{
"^#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')
{
{
regfree(&preg);
FREE(&linestr);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return 1;
}
}
}
regfree(&preg);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
}
/* not found a matching name */
}
b64_data.size = fread(b64_data.data, 1, b64_data.size, fd1);
- safe_fclose(&fd1);
+ mutt_file_fclose(&fd1);
do
{
gnutls_free(pemdata.data);
}
}
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
}
if (!done)
{
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
{
}
}
}
- else if (mutt_copy_bytes(fpin, fpout, body->length) == -1)
+ else if (mutt_file_copy_bytes(fpin, fpout, body->length) == -1)
return -1;
}
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)
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 */
}
/* 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;
}
else
rc = 0;
- mutt_unlink(tempfile);
+ mutt_file_unlink(tempfile);
}
return rc;
snprintf(tmp, sizeof(tmp), "\"%s\" %lu bytes\n", path, (unsigned long) sb.st_size);
addstr(tmp);
}
- safe_fclose(&f);
+ mutt_file_fclose(&f);
}
else
{
}
/* 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);
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);
bail:
if (fp)
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
if (rc >= 0)
unlink(tmp);
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)
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)
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);
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);
mutt_message(_("Invoking autoview command: %s"), command);
}
- fpin = safe_fopen(tempfile, "w+");
+ fpin = mutt_file_fopen(tempfile, "w+");
if (!fpin)
{
mutt_perror("fopen");
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
}
else
{
- mutt_copy_stream(fpout, s->fpout);
+ mutt_file_copy_stream(fpout, s->fpout);
/* Check for stderr messages */
if (fgets(buffer, sizeof(buffer), fperr))
{
}
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();
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))
{
}
#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!"));
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;
}
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)
{
b->offset = tmpoffset;
/* restore the original source stream */
- safe_fclose(&s->fpin);
+ mutt_file_fclose(&s->fpin);
#ifdef USE_FMEMOPEN
FREE(&temp);
#endif
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);
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);
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);
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));
struct stat st;
mutt_mktemp(path, sizeof(path));
- ofp = safe_fopen(path, "w");
+ ofp = mutt_file_fopen(path, "w");
if (!ofp)
{
mutt_perror(path);
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)
{
return;
}
- mtime = mutt_decrease_mtime(path, &st);
+ mtime = mutt_file_decrease_mtime(path, &st);
mutt_edit_file(editor, path);
stat(path, &st);
{
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 */
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;
}
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;
do
{
- f = safe_fopen(t, "w");
+ f = mutt_file_fopen(t, "w");
if (!f)
{
mutt_perror(t);
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,
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 ||
}
}
- safe_fclose(&f);
+ mutt_file_fclose(&f);
FREE(&linebuf);
}
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)
if (regen_file)
{
mutt_mktemp(tmpfname, sizeof(tmpfname));
- tmp = safe_fopen(tmpfname, "w+");
+ tmp = mutt_file_fopen(tmpfname, "w+");
if (!tmp)
{
mutt_perror(tmpfname);
}
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)
}
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))
}
fputs("|\n", f);
- safe_fclose(&f);
+ mutt_file_fclose(&f);
FREE(&tmp);
if (--n < 0)
{
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);
}
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);
/* 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);
retval = msn_end;
error_out_1:
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
error_out_0:
FREE(&hdrreq);
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);
return 0;
bail:
- safe_fclose(&msg->fp);
+ mutt_file_fclose(&msg->fp);
imap_cache_del(idata, h);
if (cache->path)
{
*/
int imap_close_message(struct Context *ctx, struct Message *msg)
{
- return safe_fclose(&msg->fp);
+ return mutt_file_fclose(&msg->fp);
}
/**
*/
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;
pc = imap_next_word(pc);
mutt_error("%s", pc);
mutt_sleep(1);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
goto fail;
}
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);
/* 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
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! */
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)
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;
}
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)
}
FREE(&token.data);
FREE(&linebuf);
- safe_fclose(&f);
+ mutt_file_fclose(&f);
if (pid != -1)
mutt_wait_filter(pid);
if (rc)
}
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
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);
}
mutt_exit(1);
}
- mutt_mkdir(Tmpdir, S_IRWXU);
+ mutt_file_mkdir(Tmpdir, S_IRWXU);
mutt_read_histfile();
#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
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)
bodyfile = tempfile;
if (fin)
- safe_fclose(&fin);
+ mutt_file_fclose(&fin);
}
FREE(&bodytext);
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))
{
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);
{
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)
{
fflush(ctx->fp);
- mutt_unlock_file(ctx->path, fileno(ctx->fp));
+ mutt_file_unlock(ctx->path, fileno(ctx->fp));
ctx->locked = false;
}
}
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();
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);
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;
}
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;
}
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
return -1;
}
- mutt_touch_atime(fileno(ctx->fp));
+ mutt_file_touch_atime(fileno(ctx->fp));
/* now try to recover the old flags */
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);
*/
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;
}
}
- 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
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)
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)
out:
FREE(&buff);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return rc;
}
/* 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;
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++)
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);
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))
{
fprintf(nfp, "%s\n", buff);
}
}
- safe_fclose(&ofp);
+ mutt_file_fclose(&ofp);
FREE(&buff);
if (!unseen_done && 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);
if (f)
{
h = maildir_parse_stream(magic, f, fname, is_old, h);
- safe_fclose(&f);
+ mutt_file_fclose(&f);
return h;
}
return NULL;
static int mh_close_message(struct Context *ctx, struct Message *msg)
{
- return safe_fclose(&msg->fp);
+ return mutt_file_fclose(&msg->fp);
}
/**
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;
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
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;
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);
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);
}
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);
}
*
* 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"
{
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;
}
/**
- * 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;
{
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;
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;
}
/**
- * 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];
}
/**
- * 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;
}
/**
- * 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
*
* 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;
* 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. */
#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;
}
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;
}
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;
* 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;
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)))
}
if (S_ISDIR(statbuf.st_mode))
- rc |= mutt_rmtree(cur);
+ rc |= mutt_file_rmtree(cur);
else
rc |= unlink(cur);
}
}
/**
- * 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;
}
/**
- * 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
* 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')
{
else
flags |= O_WRONLY;
- fd = safe_open(path, flags);
+ fd = mutt_file_open(path, flags);
if (fd < 0)
return NULL;
}
/**
- * 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;
}
/**
- * 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))
{
}
/**
- * 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
* 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;
}
/**
- * 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
*
* 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;
}
/**
- * 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
* 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;
/* 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 */
}
/**
- * 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
* 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";
}
/**
- * 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)
}
/**
- * 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
* 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)
{
}
/**
- * 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
*
* 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;
}
/**
- * 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
*
* 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));
}
/**
- * 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;
}
/**
- * 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 } };
}
/**
- * 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
* 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;
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");
}
/**
- * 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 };
}
/**
- * 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;
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;
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
* @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;
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
* 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];
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 */
}
/**
- * 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
* 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;
}
/**
- * 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;
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 */
{
if (!msg)
return 1;
- safe_fclose(&(msg->fp));
+ mutt_file_fclose(&(msg->fp));
return 0;
}
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;
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
{
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);
}
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)
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);
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);
else if (mutt_strcmp(MMDF_SEP, tmp) == 0)
magic = MUTT_MMDF;
}
- safe_fclose(&f);
+ mutt_file_fclose(&f);
if (!option(OPT_CHECK_MBOX_SIZE))
{
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));
}
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)
{
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:
if (!WithCrypto)
return -1;
- fp = safe_fopen(tempfile, "w");
+ fp = mutt_file_fopen(tempfile, "w");
if (!fp)
{
mutt_perror(tempfile);
fputc(c, fp);
}
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return 0;
}
return;
mutt_mktemp(tempfname, sizeof(tempfname));
- fpout = safe_fopen(tempfname, "w");
+ fpout = mutt_file_fopen(tempfname, "w");
if (!fpout)
{
mutt_perror(tempfname);
mutt_parse_mime_message(Context, hi);
if (hi->security & ENCRYPT && !crypt_valid_passphrase(hi->security))
{
- safe_fclose(&fpout);
+ mutt_file_fclose(&fpout);
break;
}
}
}
- 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);
}
}
- mutt_unlink(tempfile);
+ mutt_file_unlink(tempfile);
b->goodsig = goodsig;
b->badsig = !goodsig;
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);
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);
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"));
if (fwrite(buf, nread, 1, fp) != 1)
{
mutt_perror(tempf);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
unlink(tempf);
return NULL;
}
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)
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);
}
mutt_mktemp(tempfile, sizeof(tempfile));
- *fpout = safe_fopen(tempfile, "w+");
+ *fpout = mutt_file_fopen(tempfile, "w+");
if (!*fpout)
{
mutt_perror(tempfile);
b->type = saved_type;
b->length = saved_length;
b->offset = saved_offset;
- safe_fclose(&decoded_fp);
+ mutt_file_fclose(&decoded_fp);
}
return rv;
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);
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)
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))
{
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);
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)
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;
}
mutt_mktemp(tmpfile, sizeof(tmpfile));
- *fp = safe_fopen(tmpfile, "w+");
+ *fp = mutt_file_fopen(tmpfile, "w+");
if (!*fp)
{
mutt_perror(tmpfile);
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);
}
}
}
- safe_fclose(&tfp);
+ mutt_file_fclose(&tfp);
unlink(tempfile);
if (!enc && !sgn)
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
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;
mutt_sleep(1);
}
gpgme_data_release(keydata);
- safe_fclose(&in);
- safe_fclose(&out);
+ mutt_file_fclose(&in);
+ mutt_file_fclose(&out);
}
/*
fname = data_object_to_tempfile(data, NULL, &fp);
if (!fname)
{
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return;
}
unlink(fname);
}
fgetconv_close(&fc);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
}
/**
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
gpgme_data_release(armored_data);
if (pgpout)
{
- safe_fclose(&pgpout);
+ mutt_file_fclose(&pgpout);
}
}
else
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)
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;
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)
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;
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"));
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);
if (ferror(fp))
mutt_perror("fgets");
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
mutt_wait_filter(thepid);
close(devnull);
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)
{
else
{
mutt_debug(2, "pgp_copy_checksig: No pattern.\n");
- mutt_copy_stream(fpin, fpout);
+ mutt_file_copy_stream(fpin, fpout);
rv = 1;
}
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)
{
/* 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);
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;
}
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;
fprintf(pgpin, "%s\n", PgpPass);
}
- safe_fclose(&pgpin);
+ mutt_file_fclose(&pgpin);
if (s->flags & MUTT_DISPLAY)
{
rc = pgp_copy_checksig(pgperr, s->fpout);
}
- safe_fclose(&pgperr);
+ mutt_file_fclose(&pgperr);
rv = mutt_wait_filter(thepid);
if (s->flags & MUTT_DISPLAY)
* 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)
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);
key = 1;
}
}
- safe_fclose(&tfp);
+ mutt_file_fclose(&tfp);
unlink(tempfile);
if (!enc && !sgn && !key)
snprintf(sigfile, sizeof(sigfile), "%s.asc", tempfile);
- fp = safe_fopen(sigfile, "w");
+ fp = mutt_file_fopen(sigfile, "w");
if (!fp)
{
mutt_perror(sigfile);
}
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);
if (pgp_copy_checksig(pgpout, s->fpout) >= 0)
badsig = 0;
- safe_fclose(&pgpout);
+ mutt_file_fclose(&pgpout);
fflush(pgperr);
rewind(pgperr);
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);
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);
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)
int rv;
mutt_mktemp(pgperrfile, sizeof(pgperrfile));
- pgperr = safe_fopen(pgperrfile, "w+");
+ pgperr = mutt_file_fopen(pgperrfile, "w+");
if (!pgperr)
{
mutt_perror(pgperrfile);
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;
}
*/
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(
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.
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);
{
mutt_error(_("Decryption failed"));
pgp_void_passphrase();
- safe_fclose(&pgperr);
+ mutt_file_fclose(&pgperr);
return NULL;
}
p->goodsig = false;
state_attach_puts(_("[-- End of PGP output --]\n\n"), s);
}
- safe_fclose(&pgperr);
+ mutt_file_fclose(&pgperr);
fflush(fpout);
rewind(fpout);
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);
}
mutt_mktemp(tempfile, sizeof(tempfile));
- *fpout = safe_fopen(tempfile, "w+");
+ *fpout = mutt_file_fopen(tempfile, "w+");
if (!*fpout)
{
mutt_perror(tempfile);
b->type = saved_type;
b->length = saved_length;
b->offset = saved_offset;
- safe_fclose(&decoded_fp);
+ mutt_file_fclose(&decoded_fp);
}
return rv;
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)
rc = -1;
}
- safe_fclose(&fpout);
- mutt_unlink(tempfile);
+ mutt_file_fclose(&fpout);
+ mutt_file_unlink(tempfile);
return rc;
}
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;
}
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;
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
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)
pid_t thepid;
mutt_mktemp(tempfile, sizeof(tempfile));
- fpout = safe_fopen(tempfile, "w+");
+ fpout = mutt_file_fopen(tempfile, "w+");
if (!fpout)
{
mutt_perror(tempfile);
}
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;
}
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;
}
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;
rewind(fpout);
if (!empty)
empty = (fgetc(fpout) == EOF);
- safe_fclose(&fpout);
+ mutt_file_fclose(&fpout);
fflush(pgperr);
rewind(pgperr);
err = 1;
fputs(buf, stdout);
}
- safe_fclose(&pgperr);
+ mutt_file_fclose(&pgperr);
/* pause if there is any error output from PGP */
if (err)
}
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;
}
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;
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;
}
*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);
if (!empty)
empty = (fgetc(pgpout) == EOF);
- safe_fclose(&pgpout);
+ mutt_file_fclose(&pgpout);
err = false;
fputs(buff, stdout);
}
- safe_fclose(&pgperr);
+ mutt_file_fclose(&pgperr);
if (err)
mutt_any_key_to_continue(NULL);
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;
*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;
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);
}
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;
}
{
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)));
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"));
if (!devnull)
{
mutt_perror(_("Can't open /dev/null"));
- safe_fclose(&tempfp);
+ mutt_file_fclose(&tempfp);
if (tempf == tempfb)
unlink(tempf);
return NULL;
{
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);
short rv = -1;
mutt_mktemp(tempfile, sizeof(tempfile));
- out = safe_fopen(tempfile, "w+");
+ out = mutt_file_fopen(tempfile, "w+");
if (!out)
{
mutt_perror(tempfile);
bye:
- safe_fclose(&in);
- safe_fclose(&out);
+ mutt_file_fclose(&in);
+ mutt_file_fclose(&out);
pgp_release_packet();
return rv;
}
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);
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);
}
}
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return results;
}
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;
}
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;
}
else if (copy)
ret = 2;
- safe_fclose(&fpout);
- safe_fclose(&fperr);
+ mutt_file_fclose(&fpout);
+ mutt_file_fclose(&fperr);
return ret;
}
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;
}
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;
}
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;
}
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);
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);
}
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;
}
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;
}
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);
}
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))
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;
}
}
}
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);
}
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)
int retval = 1;
mutt_mktemp(tempfname, sizeof(tempfname));
- fpout = safe_fopen(tempfname, "w");
+ fpout = mutt_file_fopen(tempfname, "w");
if (!fpout)
{
mutt_perror(tempfname);
mutt_copy_message_ctx(fpout, Context, h, 0, 0);
fflush(fpout);
- safe_fclose(&fpout);
+ mutt_file_fclose(&fpout);
if (h->env->from)
{
{
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())
}
else
retval = 0;
- mutt_unlink(certfile);
+ mutt_file_unlink(certfile);
FREE(&certfile);
}
else
else
mutt_any_key_to_continue(_("no mbox"));
- mutt_unlink(tempfname);
+ mutt_file_unlink(tempfname);
return retval;
}
pid_t thepid;
mutt_mktemp(tempfile, sizeof(tempfile));
- fpout = safe_fopen(tempfile, "w+");
+ fpout = mutt_file_fopen(tempfile, "w+");
if (!fpout)
{
mutt_perror(tempfile);
}
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;
}
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);
err = 1;
fputs(buf, stdout);
}
- safe_fclose(&smimeerr);
+ mutt_file_fclose(&smimeerr);
/* pause if there is any error output from SMIME */
if (err)
/* 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;
}
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);
}
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);
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);
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);
if (empty)
{
mutt_any_key_to_continue(_("No output from OpenSSL..."));
- mutt_unlink(signedfile);
+ mutt_file_unlink(signedfile);
return NULL; /* fatal error while signing */
}
/* 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);
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;
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;
}
tempfile, signedfile, 0)) != -1)
{
fflush(smimeout);
- safe_fclose(&smimeout);
+ mutt_file_fclose(&smimeout);
if (mutt_wait_filter(thepid))
badsig = -1;
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;
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;
return NULL;
mutt_mktemp(outfile, sizeof(outfile));
- smimeout = safe_fopen(outfile, "w+");
+ smimeout = mutt_file_fopen(outfile, "w+");
if (!smimeout)
{
mutt_perror(outfile);
}
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;
}
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)
{
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);
}
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;
}
}
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;
}
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);
m->goodsig = p->goodsig;
m->badsig = p->badsig;
}
- safe_fclose(&smimeerr);
+ mutt_file_fclose(&smimeerr);
return p;
}
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);
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)
b->type = origType;
b->length = tmplength;
b->offset = tmpoffset;
- safe_fclose(&tmpfp);
+ mutt_file_fclose(&tmpfp);
if (*fpout)
rewind(*fpout);
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);
}
/**
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);
/* 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;
}
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);
mutt_perror(tmpfile);
break;
}
- if (safe_fclose(&fp) == EOF)
+ if (mutt_file_fclose(&fp) == EOF)
{
mutt_perror(tmpfile);
fp = NULL;
break;
}
if (fp)
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
if (*tmpfile)
unlink(tmpfile);
if (rc)
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;
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;
}
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);
/* 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;
{
if (strstr(header, ":full") == NULL && fputs(header, fp) == EOF)
{
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
unlink(tempfile);
return -1;
}
*field++ = '\0';
if (fputs(b, fp) == EOF || fputc('\n', fp) == EOF)
{
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
unlink(tempfile);
return -1;
}
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
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);
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;
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);
}
{
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;
}
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);
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);
*/
static int nntp_close_message(struct Context *ctx, struct Message *msg)
{
- return safe_fclose(&msg->fp);
+ return mutt_file_fclose(&msg->fp);
}
/**
nntp_data->group = NULL;
}
- fp = safe_fopen(msg, "r");
+ fp = mutt_file_fopen(msg, "r");
if (!fp)
{
mutt_perror(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;
}
-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) ||
int rc;
mutt_mktemp(tempfile, sizeof(tempfile));
- fp = safe_fopen(tempfile, "w+");
+ fp = mutt_file_fopen(tempfile, "w+");
if (!fp)
{
mutt_perror(tempfile);
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;
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 */
{
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;
if (stat(fname, &rd.sb) != 0)
{
mutt_perror(fname);
- safe_fclose(&rd.fp);
+ mutt_file_fclose(&rd.fp);
return -1;
}
unlink(fname);
}
}
- safe_fclose(&rd.fp);
+ mutt_file_fclose(&rd.fp);
if (IsHeader(extra))
{
if (Context)
}
#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);
mx_close_message(ctx, &msg);
if (s.fpout)
{
- safe_fclose(&s.fpout);
+ mutt_file_fclose(&s.fpout);
#ifdef USE_FMEMOPEN
FREE(&temp);
#else
}
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"));
if (option(OPT_THOROUGH_SEARCH))
{
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
#ifdef USE_FMEMOPEN
if (tempsize)
FREE(&temp);
fgetpos(rfp, &pos);
}
- safe_fclose(&rfp);
+ mutt_file_fclose(&rfp);
}
int main(int argc, char *const argv[])
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);
}
}
- safe_fclose(&f);
+ mutt_file_fclose(&f);
unlink(tempfile);
return ret;
}
/* 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);
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
static int pop_close_message(struct Context *ctx, struct Message *msg)
{
- return safe_fclose(&msg->fp);
+ return mutt_file_fclose(&msg->fp);
}
/**
}
mutt_adv_mktemp(file, sizeof(file));
- s.fpout = safe_fopen(file, "w");
+ s.fpout = mutt_file_fopen(file, "w");
if (!s.fpout)
goto bail;
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);
/* that's it. */
if (bfp != fp)
- safe_fclose(&bfp);
+ mutt_file_fclose(&bfp);
if (msg)
mx_close_message(ctx, &msg);
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")))
{
}
}
FREE(&buf);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
if (mutt_wait_filter(thepid))
{
mutt_debug(1, "Error: %s\n", msg);
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));
}
{
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 ||
if (rc == 0 && AttachSep && (fpout = fopen(tfile, "a")) != NULL)
{
fprintf(fpout, "%s", AttachSep);
- safe_fclose(&fpout);
+ mutt_file_fclose(&fpout);
}
}
else
if (rc == 0 && AttachSep && (fpout = fopen(tfile, "a")) != NULL)
{
fprintf(fpout, "%s", AttachSep);
- safe_fclose(&fpout);
+ mutt_file_fclose(&fpout);
}
}
}
{
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."));
}
else
{
if (filter && tfile[0])
- mutt_unlink(tfile);
+ mutt_file_unlink(tfile);
}
}
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);
}
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);
}
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
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);
}
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)
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);
mutt_forward_trailer(Context, parent_hdr, tmpfp);
- safe_fclose(&tmpfp);
+ mutt_file_fclose(&tmpfp);
tmpfp = NULL;
/* now that we have the template, send it. */
if (tmpfp)
{
- safe_fclose(&tmpfp);
- mutt_unlink(tmpbody);
+ mutt_file_fclose(&tmpfp);
+ mutt_file_unlink(tmpbody);
}
mutt_free_header(&tmphdr);
/* 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);
}
}
}
- safe_fclose(&tmpfp);
+ mutt_file_fclose(&tmpfp);
}
else if (rc == MUTT_YES) /* do MIME encapsulation - we don't need to do much here */
{
}
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);
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)
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);
}
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)
{
_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++;
}
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 == '#')
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;
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);
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;
}
}
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);
}
{
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);
}
/* 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;
if ((mutt_write_mime_body(msg->content, tempfp) == -1))
{
- safe_fclose(&tempfp);
+ mutt_file_fclose(&tempfp);
unlink(tempfile);
return -1;
}
{
FILE *fp = NULL;
- fp = safe_fopen(data, "a+");
+ fp = mutt_file_fopen(data, "a+");
if (!fp)
return;
if (fseek(fp, -1, SEEK_END) >= 0)
if (c != '\n')
fputc('\n', fp);
}
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
}
int mutt_compose_to_sender(struct Header *hdr)
if (!AttachKeyword.regex)
return 0;
- FILE *attf = safe_fopen(filename, "r");
+ FILE *attf = mutt_file_fopen(filename, "r");
if (!attf)
return 0;
}
}
FREE(&inputline);
- safe_fclose(&attf);
+ mutt_file_fclose(&attf);
return found;
}
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);
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)
{
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))
msg->env->from->personal = safe_strdup(RealName);
if (!((WithCrypto & APPLICATION_PGP) && (flags & SENDKEY)))
- safe_fclose(&tempfp);
+ mutt_file_fclose(&tempfp);
if (flags & SENDMAILX)
{
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);
}
}
- safe_fclose(&tempfp);
+ mutt_file_fclose(&tempfp);
if (!(flags & SENDNOFREEHEADER))
mutt_free_header(&msg);
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)
{
FREE(&b->charset);
b->charset = fromcode;
FREE(&tocode);
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return info;
}
}
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(
p = NULL;
}
}
- safe_fclose(&f);
+ mutt_file_fclose(&f);
}
}
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");
}
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);
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");
FREE(&line);
if (fpin && fpin != fp)
- safe_fclose(&fpin);
+ mutt_file_fclose(&fpin);
if (fpout)
- safe_fclose(&fpout);
+ mutt_file_fclose(&fpout);
else
return;
}
mutt_mktemp(buffer, sizeof(buffer));
- fp = safe_fopen(buffer, "w+");
+ fp = mutt_file_fopen(buffer, "w+");
if (!fp)
return NULL;
mutt_update_encoding(body);
body->parts = body->hdr->content;
- safe_fclose(&fp);
+ mutt_file_fclose(&fp);
return body;
}
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, '/'))
FREE(&buf);
}
- safe_fclose(&fp);
- safe_fclose(&fperr);
+ mutt_file_fclose(&fp);
+ mutt_file_fclose(&fperr);
mutt_wait_filter(thepid);
}
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;
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);
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);
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;
}
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);
/* 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 */
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;
}
{
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)