Re: fix for unaligned accesses

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

 



Patrick Lam <plam@xxxxxxx> さんは書きました:

Mike> Maybe it is the best to implement portable version of realpath () in
Mike> fontconfig?

pat> I also think it would be really good to get the approach I started
pat> working properly, because that really *is* a canonical path to a font.
pat> chdir() won't give you a canonical path, it just gives you a path (e.g.
pat> when you have multiple mounts of a directory).

I ditched the idea of using chdir() and getcwc() and tried to get
the approach you started to work properly.

Patch attached.

I made a new function FcConfigAddFontDirSubdirs (config, dir) which
adds all sub directories of "dir" to the list of font directories in
"config".

Using this function in FcInitLoadConfig () then makes FcInitLoadConfig ()
initialize the list of font directories correctly without having
to resort to the expensive FcInitLoadConfigAndFonts () function.

My patch adds some code to check for "." and a final "/" to
FcConfigAddFontDir () to make the common cases

    fc-cache .
    fc-cache /foo/bar/

work correctly for directories outside of the trees configured in the
.conf files as well.

Maybe this is not necessary if fc-cat is improved so that it can take
a directory as an argument and "fc-cat dir" can give info for any
directory.

In that case, the checks for "." and "/" can be omitted and the
following addition to FcConfigAddFontDir () should be enough:

 {
+    if (FcConfigNormalizeFontDir (config, d))
+        return FcTrue; /* directory has already been added */
     return FcStrSetAddFilename (config->fontDirs, d);
 }

My patch also improves an error message in fcxml.c which just said
"out of memory" when a directory could not be added although the
reason why the directory could not be added might be something
completely different.

diff -ru fontconfig-2.3.93.20060125.orig/fc-cache/Makefile.am fontconfig-2.3.93.20060125/fc-cache/Makefile.am
--- fontconfig-2.3.93.20060125.orig/fc-cache/Makefile.am	2005-12-21 16:47:42.000000000 +0100
+++ fontconfig-2.3.93.20060125/fc-cache/Makefile.am	2006-01-25 16:05:38.000000000 +0100
@@ -42,7 +42,7 @@
 stamp:
 	touch $@
 
-INCLUDES=-I${top_srcdir} $(FREETYPE_CFLAGS)
+INCLUDES=-I${top_srcdir}/src -I${top_srcdir} $(FREETYPE_CFLAGS)
 
 bin_PROGRAMS=fc-cache
 
diff -ru fontconfig-2.3.93.20060125.orig/fc-cache/fc-cache.c fontconfig-2.3.93.20060125/fc-cache/fc-cache.c
--- fontconfig-2.3.93.20060125.orig/fc-cache/fc-cache.c	2006-01-16 12:47:55.000000000 +0100
+++ fontconfig-2.3.93.20060125/fc-cache/fc-cache.c	2006-01-25 16:05:38.000000000 +0100
@@ -45,6 +45,8 @@
 #define HAVE_GETOPT_LONG 0
 #endif
 
+#include "fcint.h"
+
 #if HAVE_GETOPT_LONG
 #undef  _GNU_SOURCE
 #define _GNU_SOURCE
@@ -124,6 +126,8 @@
      */
     while ((dir = FcStrListNext (list)))
     {
+	if (!(dir = FcConfigNormalizeFontDir (config, dir)))
+	     continue; /* directory is in the list but doesn't really exist */
 	if (verbose)
 	{
 	    printf ("%s: \"%s\": ", program, dir);
@@ -294,9 +298,10 @@
 	}
 	while (argv[i])
 	{
-	    if (!FcStrSetAdd (dirs, (FcChar8 *) argv[i]))
+	    if (!FcStrSetAdd (dirs, (FcChar8 *) argv[i]) ||
+		!FcConfigAddFontDir (config, (FcChar8 *) argv[i]))
 	    {
-		fprintf (stderr, "%s: Can't add directory\n", argv[0]);
+		fprintf (stderr, "%s: Can't add directory %s\n", argv[0], argv[i]);
 		return 1;
 	    }
 	    i++;
diff -ru fontconfig-2.3.93.20060125.orig/src/fccfg.c fontconfig-2.3.93.20060125/src/fccfg.c
--- fontconfig-2.3.93.20060125.orig/src/fccfg.c	2006-01-25 16:02:45.000000000 +0100
+++ fontconfig-2.3.93.20060125/src/fccfg.c	2006-01-25 16:05:38.000000000 +0100
@@ -385,9 +385,84 @@
 FcConfigAddFontDir (FcConfig	    *config,
 		    const FcChar8   *d)
 {
+    FcChar8 buf[PATH_MAX];
+    FcChar8 *newd;
+    FcBool ret;
+    
+    if (0 == strcmp ((char *) d, "."))
+    {
+	if (NULL == getcwd ((char *) buf, PATH_MAX))
+	{
+	    fprintf (stderr, "cannot get current working directory");
+	    return FcFalse;
+	}
+	else
+	{
+            if (FcConfigNormalizeFontDir (config, buf))
+                return FcTrue; /* directory has already been added */
+            return FcStrSetAddFilename (config->fontDirs, buf);
+	}
+    }
+    /* if there is a final '/', remove it */
+    if (strlen ((char *) d) > 1 && d[strlen ((char *) d) - 1] == '/')
+    {
+	if (!(newd = (FcChar8 *) malloc (strlen ((char *) d) + 1)))
+	{
+	    fprintf (stderr, "out of memory");
+	    return FcFalse;
+	}
+	strcpy (newd, d);
+	newd [strlen ((char *) d) - 1] = 0;
+	if (FcConfigNormalizeFontDir (config, buf))
+	{
+	    free (newd);
+	    return FcTrue; /* directory has already been added */
+	}
+	ret = FcStrSetAddFilename (config->fontDirs, newd);
+	free (newd);
+	return ret;
+    }
+    if (FcConfigNormalizeFontDir (config, d))
+        return FcTrue; /* directory has already been added */
     return FcStrSetAddFilename (config->fontDirs, d);
 }
 
+FcBool
+FcConfigAddFontDirSubdirs (FcConfig	    *config,
+		    const FcChar8   *d)
+{
+    DIR *dir;
+    struct dirent *e;
+    struct stat s;
+    FcChar8 *subdir;
+    
+    if (!(dir = opendir ((char *) d)))
+	return FcFalse;
+    if (!(subdir = (FcChar8 *) malloc (strlen ((char *) d) + FC_MAX_FILE_LEN + 2)))
+    {
+	fprintf (stderr, "out of memory");
+	return FcFalse;
+    }
+    while ((e = readdir (dir)))
+    {
+	if (strcmp (e->d_name, ".") && strcmp (e->d_name, "..") &&
+	    strlen (e->d_name) < FC_MAX_FILE_LEN)
+	{
+	    strcpy (subdir, d);
+	    strcat (subdir, "/");
+	    strcat (subdir, e->d_name);
+	    if(FcFileIsDir (subdir))
+	    {
+	        FcConfigAddFontDir (config, subdir);
+	        FcConfigAddFontDirSubdirs (config, subdir);
+	    }
+	}
+    }
+    free (subdir);
+    closedir (dir);
+    return FcTrue;
+}
+
 const FcChar8 *
 FcConfigNormalizeFontDir (FcConfig  	*config, 
 			  const FcChar8 *d)
diff -ru fontconfig-2.3.93.20060125.orig/src/fcinit.c fontconfig-2.3.93.20060125/src/fcinit.c
--- fontconfig-2.3.93.20060125.orig/src/fcinit.c	2005-11-24 21:32:30.000000000 +0100
+++ fontconfig-2.3.93.20060125/src/fcinit.c	2006-01-25 16:05:38.000000000 +0100
@@ -56,6 +56,7 @@
 FcInitLoadConfig (void)
 {
     FcConfig	*config;
+    int n, nmax;
     
     FcInitDebug ();
     config = FcConfigCreate ();
@@ -68,6 +69,10 @@
 	return FcInitFallbackConfig ();
     }
 
+    nmax = config->fontDirs->num;
+    for (n = 0; n < nmax; n++)
+        FcConfigAddFontDirSubdirs (config, config->fontDirs->strs[n]);
+
     return config;
 }
 
diff -ru fontconfig-2.3.93.20060125.orig/src/fcint.h fontconfig-2.3.93.20060125/src/fcint.h
--- fontconfig-2.3.93.20060125.orig/src/fcint.h	2006-01-16 12:47:55.000000000 +0100
+++ fontconfig-2.3.93.20060125/src/fcint.h	2006-01-25 16:05:38.000000000 +0100
@@ -32,7 +32,9 @@
 #include <ctype.h>
 #include <errno.h>
 #include <unistd.h>
+#include <limits.h>
 #include <sys/types.h>
+#include <dirent.h>
 #include <sys/stat.h>
 #include <time.h>
 #include <fontconfig/fontconfig.h>
@@ -489,6 +491,10 @@
 		    const FcChar8   *d);
 
 FcBool
+FcConfigAddFontDirSubdirs (FcConfig	    *config,
+		    const FcChar8   *d);
+
+FcBool
 FcConfigAddDir (FcConfig	*config,
 		const FcChar8	*d);
 
diff -ru fontconfig-2.3.93.20060125.orig/src/fcxml.c fontconfig-2.3.93.20060125/src/fcxml.c
--- fontconfig-2.3.93.20060125.orig/src/fcxml.c	2005-12-21 16:47:42.000000000 +0100
+++ fontconfig-2.3.93.20060125/src/fcxml.c	2006-01-25 16:05:38.000000000 +0100
@@ -2050,7 +2050,7 @@
 	if (!FcStrUsesHome (data) || FcConfigHome ())
 	{
 	    if (!FcConfigAddDir (parse->config, data))
-		FcConfigMessage (parse, FcSevereError, "out of memory");
+		FcConfigMessage (parse, FcSevereError, "cannot add directory %s", data);
 	}
 	FcStrFree (data);
 	break;

-- 
Mike FABIAN   <mfabian@xxxxxxx>   http://www.suse.de/~mfabian
睡眠不足はいい仕事の敵だ。
_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/fontconfig

[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux