[Commits] [SCM] claws branch, master, updated. 3.17.0-113-g414b08d

Colin colin at claws-mail.org
Wed Oct 10 14:35:15 CEST 2018


The branch, master has been updated
       via  414b08d658d56f25052aab18ab75d7e321d97e3b (commit)
      from  2735b0e9fb64550c31c862cf5ead129042109ffa (commit)

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


- Log -----------------------------------------------------------------
commit 414b08d658d56f25052aab18ab75d7e321d97e3b
Author: Colin Leroy <colin at colino.net>
Date:   Wed Oct 10 14:34:34 2018 +0200

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

diff --git a/src/common/file-utils.c b/src/common/file-utils.c
index 97f1f50..f7e2da7 100644
--- 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
index 398bfde..d89b069 100644
--- 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
index 8b42d20..bd3239e 100644
--- 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;
 }
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list