From 1a03de334fd4e6aafb91b806ea35092a7774a8d7 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Mon, 19 Jul 2010 15:56:58 +0200 Subject: Imported Upstream version 4.0.4 --- util.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 57adb46..cb9b043 100644 --- a/util.c +++ b/util.c @@ -1,3 +1,25 @@ +/* util.c + * + * Copyright (C) 2008 Till Kamppeter + * Copyright (C) 2008 Lars Uebernickel + * + * This file is part of foomatic-rip. + * + * Foomatic-rip is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Foomatic-rip is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ #include "util.h" #include "foomaticrip.h" @@ -11,6 +33,33 @@ const char* shellescapes = "|<>&!$\'\"#*?()[]{}"; +const char * temp_dir() +{ + static const char *tmpdir = NULL; + + if (!tmpdir) + { + const char *dirs[] = { getenv("TMPDIR"), P_tmpdir, "/tmp", NULL }; + const char **dir; + + for (dir = dirs; *dir; dir++) + if (access(*dir, W_OK) == 0) { + tmpdir = *dir; + break; + } + if (tmpdir) + { + _log("Storing temporary files in %s\n", tmpdir); + setenv("TMPDIR", tmpdir, 1); /* for child processes */ + } + else + rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, + "Cannot find a writable temp dir."); + } + + return tmpdir; +} + int prefixcmp(const char *str, const char *prefix) { return strncmp(str, prefix, strlen(prefix)); -- cgit v1.2.3