Create temporary file in /tmp
This commit is contained in:
@@ -486,31 +486,31 @@ Imlib_Image load_image(const char *path, int cached)
|
|||||||
image = imlib_load_image_immediately_without_cache(path);
|
image = imlib_load_image_immediately_without_cache(path);
|
||||||
}
|
}
|
||||||
if (!image && g_str_has_suffix(path, ".svg")) {
|
if (!image && g_str_has_suffix(path, ".svg")) {
|
||||||
char suffix[128];
|
char tmp_filename[128];
|
||||||
sprintf(suffix, "tmpimage-%d.png", getpid());
|
sprintf(tmp_filename, "/tmp/tint2-%d-XXXXXX.png", (int)getpid());
|
||||||
// We fork here because librsvg allocates memory like crazy
|
int fd = mkstemps(tmp_filename, 4);
|
||||||
pid_t pid = fork();
|
if (fd) {
|
||||||
if (pid == 0) {
|
// We fork here because librsvg allocates memory like crazy
|
||||||
// Child
|
pid_t pid = fork();
|
||||||
GError *err = NULL;
|
if (pid == 0) {
|
||||||
RsvgHandle *svg = rsvg_handle_new_from_file(path, &err);
|
// Child
|
||||||
|
GError *err = NULL;
|
||||||
|
RsvgHandle *svg = rsvg_handle_new_from_file(path, &err);
|
||||||
|
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
fprintf(stderr, "Could not load svg image!: %s", err->message);
|
fprintf(stderr, "Could not load svg image!: %s", err->message);
|
||||||
g_error_free(err);
|
g_error_free(err);
|
||||||
|
} else {
|
||||||
|
GdkPixbuf *pixbuf = rsvg_handle_get_pixbuf(svg);
|
||||||
|
gdk_pixbuf_save(pixbuf, tmp_filename, "png", NULL, NULL);
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
gchar *name = g_build_filename(g_get_user_config_dir(), "tint2", suffix, NULL);
|
// Parent
|
||||||
GdkPixbuf *pixbuf = rsvg_handle_get_pixbuf(svg);
|
waitpid(pid, 0, 0);
|
||||||
gdk_pixbuf_save(pixbuf, name, "png", NULL, NULL);
|
image = imlib_load_image_immediately_without_cache(tmp_filename);
|
||||||
|
unlink(tmp_filename);
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user