]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
FcStrPathPlus: new helper function
[fontconfig.git] / src / fccfg.c
index 09c59919d8f37bd1998f7d530f7b96865512b8a2..6d55f171e216ca886ec6cbe4e78dc4137b4e2959 100644 (file)
@@ -1689,38 +1689,11 @@ static FcChar8 *
 FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
 {
     FcChar8    *path;
-    int         size;
 
     if (!dir)
-       dir = (FcChar8 *) "";
+       dir = (const FcChar8 *) "";
 
-    size = strlen ((char *) dir) + 1 + strlen ((char *) file) + 1;
-    /*
-     * workaround valgrind warning because glibc takes advantage of how it knows memory is
-     * allocated to implement strlen by reading in groups of 4
-     */
-    size = (size + 3) & ~3;
-
-    path = malloc (size);
-    if (!path)
-       return 0;
-
-    strcpy ((char *) path, (const char *) dir);
-    /* make sure there's a single separator */
-#ifdef _WIN32
-    if ((!path[0] || (path[strlen((char *) path)-1] != '/' &&
-                     path[strlen((char *) path)-1] != '\\')) &&
-       !(file[0] == '/' ||
-         file[0] == '\\' ||
-         (isalpha (file[0]) && file[1] == ':' && (file[2] == '/' || file[2] == '\\'))))
-       strcat ((char *) path, "\\");
-#else
-    if ((!path[0] || path[strlen((char *) path)-1] != '/') && file[0] != '/')
-       strcat ((char *) path, "/");
-#endif
-    strcat ((char *) path, (char *) file);
-
-    FcMemAlloc (FC_MEM_STRING, size);
+    path = FcStrPathPlus (dir, file, NULL);
     if (access ((char *) path, R_OK) == 0)
        return path;