[babl] babl-cache: use getenv("TEMP") for folder location on win32, and fix mk_ancestry
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] babl-cache: use getenv("TEMP") for folder location on win32, and fix mk_ancestry
- Date: Sun, 20 Nov 2016 20:45:14 +0000 (UTC)
commit 1764ff583e5967622469ac687eecbaaf96c2343d
Author: Øyvind Kolås <pippin gimp org>
Date: Sun Nov 20 18:17:52 2016 +0100
babl-cache: use getenv("TEMP") for folder location on win32, and fix mk_ancestry
Inspired by initial work in patch for bug 774491 provided by Edward E
babl/babl-cache.c | 66 +++++++++++++++++++++++++++++++++++++---------------
1 files changed, 47 insertions(+), 19 deletions(-)
---
diff --git a/babl/babl-cache.c b/babl/babl-cache.c
index 926d9f1..0ef3f83 100644
--- a/babl/babl-cache.c
+++ b/babl/babl-cache.c
@@ -22,40 +22,68 @@
#include "babl-internal.h"
#include "git-version.h"
-static const char *fish_cache_path (void)
+static void
+mk_ancestry_iter (const char *path)
{
-#ifdef _WIN32 // XXX: fixme - make this work - and be a reasonable location
- // on windows
- return "C:\\babl.txt";
+ char copy[4096];
+ strncpy (copy, path, 4096);
+ if (strrchr (copy, '/'))
+ {
+ *strrchr (copy, '/') = '\0';
+ if (copy[0])
+ {
+ struct stat stat_buf;
+ if ( ! (stat (copy, &stat_buf)==0 && S_ISDIR(stat_buf.st_mode)))
+ {
+ mk_ancestry_iter (copy);
+#ifndef _WIN32
+ mkdir (copy, S_IRWXU);
#else
- // FIXME: need a location for this temporary file on win32
+ mkdir (copy);
+#endif
+ }
+ }
+ }
+}
+
+static void
+mk_ancestry (char *path)
+{
+#ifdef _WIN32
+ for (char *c = path; *c; c++)
+ if (*c == '\\')
+ *c = '/';
+#endif
+ mk_ancestry_iter (path);
+}
+
+static const char *fish_cache_path (void)
+{
struct stat stat_buf;
static char resolved[4096];
char *ret = NULL;
+
+#ifndef _WIN32
if (getenv ("HOME"))
- {
- sprintf (resolved, "%s/.cache/babl/fishes", getenv("HOME"));
- }
+ sprintf (resolved, "%s/.cache/babl/babl-fishes", getenv("HOME"));
else
- {
- return "/tmp/babl.db";
- }
+ strncpy (resolved, "/tmp/babl.db", 4096);
+#else
+ if (getenv ("TEMP"))
+ sprintf (resolved, "%s\\babl-fishes.txt", getenv("TEMP"));
+ else
+ strncpy (resolved, "c:\\babl-fishes.txt", 4096);
+#endif
if (stat (resolved, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
return resolved;
- ret = strdup (resolved);
-
- while (strrchr (resolved, '/'))
- {
- *strrchr (resolved, '/') = '\0';
- mkdir (resolved, S_IRWXU);
- }
+ ret = strdup (resolved);
+ mk_ancestry (ret);
strcpy (resolved, ret);
free (ret);
return resolved;
-#endif
}
static char *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]