talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 414b08d658d56f25052aab18ab75d7e321d97e3b
parent 2735b0e9fb64550c31c862cf5ead129042109ffa
Author: Colin Leroy <colin@colino.net>
Date:   Wed, 10 Oct 2018 14:34:34 +0200

Revert all memory-based tmpfile I/O, it comes with too much drawbacks
(like having to know the filesize before writing to it)

Diffstat:
Msrc/common/file-utils.c | 30+-----------------------------
Msrc/common/file-utils.h | 1-
Msrc/procmime.c | 13+++++--------
3 files changed, 6 insertions(+), 38 deletions(-)

diff --git a/src/common/file-utils.c b/src/common/file-utils.c @@ -827,34 +827,6 @@ FILE *my_tmpfile(void) return tmpfile(); } -/* Returns a memory-backed FILE pointer to avoid file I/O - * where unnecessary. The "file" size is passed in the len - * parameter and is fixed: it's up to the caller to pass a - * large enough length to write to the FILE pointer. If the - * precise length isn't known, it is possible to ask for more. - * - * In this case, once writing to the pointer is done, the - * caller is responsible for calling ftruncate(fileno(fp), ftell(fp)) - * to make sure re-reading the stream will return EOF at the - * end of what we wrote. - * Otherwise, re-reading the stream will return uninitialized - * memory at the end of the stream. - */ -FILE *my_tmpfile_with_len(size_t len) -{ -#if HAVE_FMEMOPEN - FILE *tmpfp = fmemopen(NULL, len, "w+b"); - - if (tmpfp == NULL) { - return my_tmpfile(); - } - - return tmpfp; -#else - return my_tmpfile(); -#endif -} - FILE *get_tmpfile_in_dir(const gchar *dir, gchar **filename) { int fd; @@ -874,7 +846,7 @@ FILE *str_open_as_stream(const gchar *str) len = strlen(str); - fp = my_tmpfile_with_len(len); + fp = my_tmpfile(); if (!fp) { FILE_OP_ERROR("str_open_as_stream", "my_tmpfile"); diff --git a/src/common/file-utils.h b/src/common/file-utils.h @@ -94,7 +94,6 @@ gint copy_dir (const gchar *src, gint change_file_mode_rw (FILE *fp, const gchar *file); FILE *my_tmpfile (void); -FILE *my_tmpfile_with_len (size_t len); FILE *get_tmpfile_in_dir (const gchar *dir, gchar **filename); FILE *str_open_as_stream (const gchar *str); diff --git a/src/procmime.c b/src/procmime.c @@ -377,7 +377,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo) if (mimeinfo->type == MIMETYPE_TEXT || mimeinfo->type == MIMETYPE_MESSAGE) { uncanonicalize = TRUE; - tmpfp = my_tmpfile_with_len(mimeinfo->length * 2); + tmpfp = my_tmpfile(); if (!tmpfp) { perror("my_tmpfile"); if (tmp_file) @@ -429,7 +429,6 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo) } } if (tmpfp != outfp) { - ftruncate(fileno(tmpfp), ftell(tmpfp)); claws_fclose(tmpfp); } } else if (encoding == ENC_X_UUENCODE) { @@ -467,7 +466,6 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo) g_warning("write error"); } - ftruncate(fileno(outfp), ftell(outfp)); claws_fclose(outfp); claws_fclose(infp); @@ -744,7 +742,7 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo, if (!procmime_decode_content(mimeinfo)) return TRUE; - tmpfp = my_tmpfile_with_len(mimeinfo->length * 2); + tmpfp = my_tmpfile(); if (tmpfp == NULL) { FILE_OP_ERROR("tmpfile", "open"); @@ -834,14 +832,13 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo) FILE *outfp; gboolean err; - if ((outfp = my_tmpfile_with_len(mimeinfo->length * 2)) == NULL) { + if ((outfp = my_tmpfile()) == NULL) { perror("my_tmpfile"); return NULL; } err = procmime_scan_text_content(mimeinfo, scan_fputs_cb, outfp); - ftruncate(fileno(outfp), ftell(outfp)); rewind(outfp); if (err == TRUE) { claws_fclose(outfp); @@ -860,12 +857,12 @@ FILE *procmime_get_binary_content(MimeInfo *mimeinfo) if (!procmime_decode_content(mimeinfo)) return NULL; - outfp = my_tmpfile_with_len(mimeinfo->length * 2); + outfp = my_tmpfile(); if (procmime_get_part_to_stream(outfp, mimeinfo) < 0) { return NULL; } - ftruncate(fileno(outfp), ftell(outfp)); + return outfp; }