Create temporary file in /tmp

This commit is contained in:
o9000
2016-02-12 13:03:52 +01:00
parent 7bdae24ddf
commit e4ced531ad

View File

@@ -486,8 +486,10 @@ Imlib_Image load_image(const char *path, int cached)
image = imlib_load_image_immediately_without_cache(path);
}
if (!image && g_str_has_suffix(path, ".svg")) {
char suffix[128];
sprintf(suffix, "tmpimage-%d.png", getpid());
char tmp_filename[128];
sprintf(tmp_filename, "/tmp/tint2-%d-XXXXXX.png", (int)getpid());
int fd = mkstemps(tmp_filename, 4);
if (fd) {
// We fork here because librsvg allocates memory like crazy
pid_t pid = fork();
if (pid == 0) {
@@ -499,18 +501,16 @@ Imlib_Image load_image(const char *path, int cached)
fprintf(stderr, "Could not load svg image!: %s", err->message);
g_error_free(err);
} else {
gchar *name = g_build_filename(g_get_user_config_dir(), "tint2", suffix, NULL);
GdkPixbuf *pixbuf = rsvg_handle_get_pixbuf(svg);
gdk_pixbuf_save(pixbuf, name, "png", NULL, NULL);
gdk_pixbuf_save(pixbuf, tmp_filename, "png", NULL, NULL);
}
exit(0);
} else {
// Parent
waitpid(pid, 0, 0);
gchar *name = g_build_filename(g_get_user_config_dir(), "tint2", suffix, NULL);
image = imlib_load_image_immediately_without_cache(name);
g_remove(name);
g_free(name);
image = imlib_load_image_immediately_without_cache(tmp_filename);
unlink(tmp_filename);
}
}
} else
#endif