2 * Copyright (C) 2002 Jorn Baayen
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <libgnome/gnome-init.h>
30 #include "ev-file-helpers.h"
32 static char *dot_dir = NULL;
33 static char *tmp_dir = NULL;
37 ensure_dir_exists (const char *dir)
39 if (g_file_test (dir, G_FILE_TEST_IS_DIR) == FALSE)
41 if (g_file_test (dir, G_FILE_TEST_EXISTS) == TRUE)
43 g_warning ("%s exists, please move it out of the way.", dir);
47 if (mkdir (dir, 488) != 0)
49 g_warning ("Failed to create directory %s.", dir);
64 dot_dir = g_build_filename (gnome_user_dir_get (),
68 exists = ensure_dir_exists (dot_dir);
76 ev_file_helpers_init (void)
81 ev_file_helpers_shutdown (void)
94 ev_tmp_filename (void)
97 gchar *filename = NULL;
99 if (tmp_dir == NULL) {
103 dirname = g_strdup_printf ("evince-%u", getpid());
104 tmp_dir = g_build_filename (g_get_tmp_dir (),
109 exists = ensure_dir_exists (tmp_dir);
115 if (filename != NULL)
118 basename = g_strdup_printf ("document-%d", count ++);
120 filename = g_build_filename (tmp_dir, basename, NULL);
123 } while (g_file_test (filename, G_FILE_TEST_EXISTS));