summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
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));