]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcstr.c
FcStrPathPlus: new helper function
[fontconfig.git] / src / fcstr.c
index b712e5dafd52e698f52defbcb88ba658241c1bc1..0510c2104aab58e12e799e44f4095d486e3de93d 100644 (file)
@@ -63,6 +63,57 @@ FcStrPlus (const FcChar8 *s1, const FcChar8 *s2)
     return s;
 }
 
+FcChar8 *
+FcStrPathPlus (const FcChar8 *s1, ...)
+{
+    va_list ap;
+    const FcChar8 *arg;
+    FcChar8 *s;
+    FcBool addSep;
+    int l;
+    int al;
+
+    va_start (ap, s1);
+    arg = s1;
+    s = NULL;
+    l = 0;
+    do {
+       if (!arg)
+           break;
+       al = strlen ((char *) arg);
+
+       /* make sure there's a single separator */
+       addSep = FcFalse;
+#ifdef _WIN32
+       if ((!arg[0] || (arg[al - 1] != '/' && arg[al - 1] != '\\')) &&
+           !(file[0] == '/' ||
+         file[0] == '\\' ||
+         (isalpha (file[0]) && file[1] == ':' && (file[2] == '/' || file[2] == '\\'))))
+       addSep = FcTrue;
+#else
+       if (s && (s[l] != FC_DIR_SEPARATOR && arg[0] != FC_DIR_SEPARATOR))
+           addSep = FcTrue;
+#endif
+
+       if (addSep)
+           l += 1;
+       s = realloc (s, l + al + 1);
+       if (!s)
+           return 0;
+       if (addSep)
+           s[l - 1] = FC_DIR_SEPARATOR;
+       memcpy (s + l, arg, al + 1);
+       l += al;
+
+       arg = va_arg (ap, const FcChar8 *);
+    } while (1);
+    va_end (ap);
+
+    if (l)
+       FcMemAlloc (FC_MEM_STRING, l + 1);
+    return s;
+}
+
 void
 FcStrFree (FcChar8 *s)
 {