Unify directory canonicalization into FcStrAddFilename.

Instead of making filename canonicalization occur in multiple places, it
occurs only in FcStrAddFilename now, as all filenames pass through that
function at one point.
This commit is contained in:
Keith Packard 2006-09-02 14:52:37 -07:00
parent 813258dc8e
commit 9b511b2905
4 changed files with 17 additions and 28 deletions

View File

@ -452,7 +452,7 @@ main (int argc, char **argv)
} }
while (argv[i]) while (argv[i])
{ {
if (!FcStrSetAdd (dirs, (FcChar8 *) argv[i])) if (!FcStrSetAddFilename (dirs, (FcChar8 *) argv[i]))
{ {
fprintf (stderr, "%s: Can't add directory\n", argv[0]); fprintf (stderr, "%s: Can't add directory\n", argv[0]);
return 1; return 1;

View File

@ -321,7 +321,7 @@ main (int argc, char **argv)
{ {
for (; i < argc; i++) for (; i < argc; i++)
{ {
if (!FcStrSetAdd (args, argv[i])) if (!FcStrSetAddFilename (args, argv[i]))
{ {
fprintf (stderr, "%s: malloc failure\n", argv[0]); fprintf (stderr, "%s: malloc failure\n", argv[0]);
return 1; return 1;

View File

@ -234,26 +234,17 @@ FcCache *
FcDirCacheRead (const FcChar8 *dir, FcBool force, FcConfig *config) FcDirCacheRead (const FcChar8 *dir, FcBool force, FcConfig *config)
{ {
FcCache *cache = NULL; FcCache *cache = NULL;
FcChar8 *canon_dir;
canon_dir = FcStrCanonFilename (dir); if (config && !FcConfigAcceptFilename (config, dir))
if (!canon_dir) canon_dir = (FcChar8 *) dir; return NULL;
if (config && !FcConfigAcceptFilename (config, canon_dir)) {
goto bail;
}
/* Try to use existing cache file */ /* Try to use existing cache file */
if (!force) if (!force)
cache = FcDirCacheLoad (canon_dir, config, NULL); cache = FcDirCacheLoad (dir, config, NULL);
/* Not using existing cache file, construct new cache */ /* Not using existing cache file, construct new cache */
if (!cache) if (!cache)
cache = FcDirCacheScan (canon_dir, config); cache = FcDirCacheScan (dir, config);
bail:
if (canon_dir != dir)
free (canon_dir);
return cache; return cache;
} }

View File

@ -764,26 +764,21 @@ FcStrCopyFilename (const FcChar8 *s)
if (*s == '~') if (*s == '~')
{ {
FcChar8 *home = FcConfigHome (); FcChar8 *home = FcConfigHome ();
FcChar8 *full;
int size; int size;
if (!home) if (!home)
return 0; return 0;
size = strlen ((char *) home) + strlen ((char *) s); size = strlen ((char *) home) + strlen ((char *) s);
new = (FcChar8 *) malloc (size); full = (FcChar8 *) malloc (size);
if (!new) if (!new)
return 0; return 0;
FcMemAlloc (FC_MEM_STRING, size); strcpy ((char *) full, (char *) home);
strcpy ((char *) new, (char *) home); strcat ((char *) full, (char *) s + 1);
strcat ((char *) new, (char *) s + 1); new = FcStrCanonFilename (full);
free (full);
} }
else else
{ new = FcStrCanonFilename (s);
int size = strlen ((char *) s) + 1;
new = (FcChar8 *) malloc (size);
if (!new)
return 0;
FcMemAlloc (FC_MEM_STRING, size);
memcpy (new, s, size);
}
return new; return new;
} }
@ -841,6 +836,7 @@ FcStrCanonFilename (const FcChar8 *s)
FcChar8 *file; FcChar8 *file;
FcChar8 *f; FcChar8 *f;
const FcChar8 *slash; const FcChar8 *slash;
int size;
if (*s != '/') if (*s != '/')
{ {
@ -855,9 +851,11 @@ FcStrCanonFilename (const FcChar8 *s)
FcStrFree (full); FcStrFree (full);
return file; return file;
} }
file = malloc (strlen ((char *) s) + 1); size = strlen ((char *) s) + 1;
file = malloc (size);
if (!file) if (!file)
return NULL; return NULL;
FcMemAlloc (FC_MEM_STRING, size);
slash = NULL; slash = NULL;
f = file; f = file;
for (;;) { for (;;) {