]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
Simplify FcValueSave() semantics
[fontconfig.git] / src / fccfg.c
index 853eb7f37a738f7e312b378253194dc1270d2732..95c50162d0959cf93917996182e8d3cf0c1225ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $RCSId: xc/lib/fontconfig/src/fccfg.c,v 1.23 2002/08/31 22:17:32 keithp Exp $
+ * fontconfig/src/fccfg.c
  *
  * Copyright © 2000 Keith Packard
  *
@@ -13,9 +13,9 @@
  * representations about the suitability of this software for any purpose.  It
  * is provided "as is" without express or implied warranty.
  *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
@@ -92,6 +92,8 @@ FcConfigCreate (void)
 
     config->rescanTime = time(0);
     config->rescanInterval = 30;    
+
+    config->ref = 1;
     
     return config;
 
@@ -127,7 +129,7 @@ FcConfigNewestFile (FcStrSet *files)
     if (list)
     {
        while ((file = FcStrListNext (list)))
-           if (stat ((char *) file, &statb) == 0)
+           if (FcStat ((char *) file, &statb) == 0)
                if (!newest.set || statb.st_mtime - newest.time > 0)
                {
                    newest.set = FcTrue;
@@ -156,7 +158,18 @@ FcConfigUptoDate (FcConfig *config)
        (config_dir_time.set && (config_dir_time.time - config->rescanTime) > 0) ||
        (font_time.set && (font_time.time - config->rescanTime) > 0))
     {
-       return FcFalse;
+       /* We need to check for potential clock problems here (OLPC ticket #6046) */
+       if ((config_time.set && (config_time.time - now) > 0) ||
+       (config_dir_time.set && (config_dir_time.time - now) > 0) ||
+        (font_time.set && (font_time.time - now) > 0))
+       {
+           fprintf (stderr,
+                    "Fontconfig warning: Directory/file mtime in the future. New fonts may not be detected\n");
+           config->rescanTime = now;
+           return FcTrue;
+       }
+       else
+           return FcFalse;
     }
     config->rescanTime = now;
     return FcTrue;
@@ -180,11 +193,29 @@ FcSubstDestroy (FcSubst *s)
     }
 }
 
+FcConfig *
+FcConfigReference (FcConfig *config)
+{
+    if (!config)
+    {
+       config = FcConfigGetCurrent ();
+       if (!config)
+           return 0;
+    }
+
+    config->ref++;
+
+    return config;
+}
+
 void
 FcConfigDestroy (FcConfig *config)
 {
     FcSetName  set;
 
+    if (--config->ref > 0)
+       return;
+
     if (config == _fcConfig)
        _fcConfig = 0;
 
@@ -821,7 +852,8 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
        break;
     case FcOpString:
        v.type = FcTypeString;
-       v.u.s = FcStrStaticName(e->u.sval);
+       v.u.s = e->u.sval;
+       v = FcValueSave (v);
        break;
     case FcOpMatrix:
        v.type = FcTypeMatrix;
@@ -1660,9 +1692,10 @@ FcConfigGetPath (void)
 #ifdef _WIN32
        if (fontconfig_path[0] == '\0')
        {
+               char *p;
                if(!GetModuleFileName(NULL, fontconfig_path, sizeof(fontconfig_path)))
                        goto bail1;
-               char *p = strrchr (fontconfig_path, '\\');
+               p = strrchr (fontconfig_path, '\\');
                if (p) *p = '\0';
                strcat (fontconfig_path, "\\fonts");
        }