X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=lib%2Fev-file-helpers.c;h=b093853565c5292fb798386ce82106e56e48d4c7;hb=274f17472f798aa469fe6089291efa5379de157c;hp=d9daf6a5739b056b2ee0e221fc19db65c42d07f2;hpb=11368f9b50db86ce4f2ae0b549fb575a19af2a74;p=evince.git diff --git a/lib/ev-file-helpers.c b/lib/ev-file-helpers.c index d9daf6a5..b0938535 100644 --- a/lib/ev-file-helpers.c +++ b/lib/ev-file-helpers.c @@ -25,10 +25,13 @@ #include #include #include +#include #include "ev-file-helpers.h" static char *dot_dir = NULL; +static char *tmp_dir = NULL; +static int count = 0; static gboolean ensure_dir_exists (const char *dir) @@ -77,7 +80,47 @@ ev_file_helpers_init (void) void ev_file_helpers_shutdown (void) -{ +{ + rmdir (tmp_dir); + + g_free (tmp_dir); g_free (dot_dir); + dot_dir = NULL; + tmp_dir = NULL; +} + +gchar* +ev_tmp_filename (void) +{ + gchar *basename; + gchar *filename = NULL; + + if (tmp_dir == NULL) { + gboolean exists; + gchar *dirname; + + dirname = g_strdup_printf ("evince-%u", getpid()); + tmp_dir = g_build_filename (g_get_tmp_dir (), + dirname, + NULL); + g_free (dirname); + + exists = ensure_dir_exists (tmp_dir); + g_assert (exists); + } + + + do { + if (filename != NULL) + g_free (filename); + + basename = g_strdup_printf ("document-%d", count ++); + + filename = g_build_filename (tmp_dir, basename, NULL); + + g_free (basename); + } while (g_file_test (filename, G_FILE_TEST_EXISTS)); + + return filename; }