summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorDidier Raboud <didier@raboud.com>2010-07-19 15:57:01 +0200
committerDidier Raboud <didier@raboud.com>2010-07-19 15:57:01 +0200
commit385997f8e67c69cca2f6271d06be5abcf7cd6fc6 (patch)
treef3ad343d620afc856c58491db7d8ad8b8f8bf9d4 /util.c
parent8c895f1d42d2804e1cc8f50d9f28712f760157e1 (diff)
parent1a03de334fd4e6aafb91b806ea35092a7774a8d7 (diff)
Merge commit 'upstream/4.0.4'
Diffstat (limited to 'util.c')
-rw-r--r--util.c49
1 files changed, 49 insertions, 0 deletions
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 <till.kamppeter@gmail.com>
+ * Copyright (C) 2008 Lars Uebernickel <larsuebernickel@gmx.de>
+ *
+ * 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));