[babl] babl-cache: Add a #define for FALLBACK_CACHE_PATH



commit ef962e03042c8edda42b384e5c44ef93a23721f5
Author: Edward E <develinthedetail gmail com>
Date:   Tue Nov 22 20:50:34 2016 +0100

    babl-cache: Add a #define for FALLBACK_CACHE_PATH
    
    Also return fallback cache path if failing to create location for constructed
    path.

 NEWS              |    4 ++++
 babl/babl-cache.c |   26 +++++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/NEWS b/NEWS
index 4648db8..a885050 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@ the news section both in the README and the webpage.
 
 
                                                                           -->
+2016-11-05 babl-0.1.22                                              </dt><dd>
+Added cache of profiled conversions, added HCY color model, some precision and
+performance updated for fast paths.
+                                                                    </dd><dt>
 2016-11-05 babl-0.1.20                                              </dt><dd>
 Fix run-time errors, leaks, and race conditions. Add conditional fast paths.
                                                                     </dd><dt>
diff --git a/babl/babl-cache.c b/babl/babl-cache.c
index 5d19216..db8c3b5 100644
--- a/babl/babl-cache.c
+++ b/babl/babl-cache.c
@@ -22,6 +22,12 @@
 #include "babl-internal.h"
 #include "git-version.h"
 
+#ifdef _WIN32
+#define FALLBACK_CACHE_PATH  "C:/babl-fishes.txt"
+#else
+#define FALLBACK_CACHE_PATH  "/tmp/babl-fishes.txt"
+#endif
+
 static int
 mk_ancestry_iter (const char *path)
 {
@@ -64,26 +70,24 @@ mk_ancestry (const char *path)
 static const char *fish_cache_path (void)
 {
   struct stat stat_buf;
-  static char resolved[4096];
+  static char path[4096];
 
+  strncpy (path, FALLBACK_CACHE_PATH, 4096);
 #ifndef _WIN32 
   if (getenv ("HOME"))
-    sprintf (resolved, "%s/.cache/babl/babl-fishes", getenv("HOME"));
-  else
-    strncpy (resolved, "/tmp/babl.db", 4096);
+    sprintf (path, "%s/.cache/babl/babl-fishes", getenv("HOME"));
 #else
   if (getenv ("TEMP"))
-    sprintf (resolved, "%s\\babl-fishes.txt", getenv("TEMP"));
-  else
-    strncpy (resolved, "c:\\babl-fishes.txt", 4096);
+    sprintf (path, "%s\\babl-fishes.txt", getenv("TEMP"));
 #endif
 
-  if (stat (resolved, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
-    return resolved;
+  if (stat (path, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
+    return path;
 
-  mk_ancestry (resolved);
+  if (mk_ancestry (path) != 0)
+    return FALLBACK_CACHE_PATH;
 
-  return resolved;
+  return path;
 }
 
 static char *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]