sync with sylpheed 0.7.1 release
[claws.git] / src / utils.c
index 67df6503fb5c6584c8e82ae8f584e4ba8a55e2be..24fa9fbd087ab8e0a69a6ac3f1663f5887f8458c 100644 (file)
@@ -1842,20 +1842,28 @@ FILE *my_tmpfile(void)
        return tmpfile();
 }
 
-gchar *write_buffer_to_file(const gchar *buf, guint bufsize)
+FILE *str_open_as_stream(const gchar *str)
 {
        FILE *fp;
-       gchar *tmp_file = NULL;
+       size_t len;
+
+       g_return_val_if_fail(str != NULL, NULL);
+
+       fp = my_tmpfile();
+       if (!fp) {
+               FILE_OP_ERROR("str_open_as_stream", "my_tmpfile");
+               return NULL;
+       }
 
-       tmp_file = get_tmp_file();
-       fp = fopen(tmp_file, "w");
-       if (fp) {
-               fwrite(buf, 1, bufsize, fp);
+       len = strlen(str);
+       if (fwrite(str, len, 1, fp) != 1) {
+               FILE_OP_ERROR("str_open_as_stream", "fwrite");
                fclose(fp);
+               return NULL;
        }
-       else tmp_file = NULL;
 
-       return tmp_file;
+       rewind(fp);
+       return fp;
 }
 
 gint execute_async(gchar *const argv[])