From 9cbe3256bc932b82f2435b23cda0931f4f5f5ba2 Mon Sep 17 00:00:00 2001 From: Egbert Eich Date: Thu, 19 May 2011 10:38:44 +0200 Subject: Prefer original file over symlink (v2) If a symlink to a fontfile in the same directory exists the file that got picked depends on the order in which readdir() picked entries. This patch gives the file a higher preference than the symlink to it so it will be preferred if the xlfd entries match. v2: Followed a suggestion by Julien Cristau to check for DT_LNK being defined instead of _BSD_SOURCE and fall back to lstat() if d_type is DT_UNKNOWN. Signed-off-by: Egbert Eich --- mkfontscale.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'mkfontscale.c') diff --git a/mkfontscale.c b/mkfontscale.c index 53c5303..b27bb6a 100644 --- a/mkfontscale.c +++ b/mkfontscale.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -826,6 +827,9 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo) while((entry = readdir(dirp)) != NULL) { int have_face = 0; char *xlfd_name = NULL; + struct stat f_stat; + int tprio = 1; + xlfd = NULL; if (xl) { @@ -836,6 +840,19 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo) filename = dsprintf("%s%s", dirname, entry->d_name); +#define PRIO(x) ((x << 1) + tprio) +#ifdef DT_LNK + if (entry->d_type != DT_UNKNOWN) { + if (entry->d_type == DT_LNK) + tprio = 0; + } else +#endif + { + if (lstat(filename, &f_stat)) + goto done; + if (S_ISLNK(f_stat.st_mode)) + tprio = 0; + } if(doBitmaps) rc = bitmapIdentify(filename, &xlfd_name); else @@ -896,7 +913,7 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo) xlfd = listCons(s, xlfd); } else { /* Not a reencodable font -- skip all the rest of the loop body */ - putHash(entries, xlfd_name, entry->d_name, filePrio(entry->d_name)); + putHash(entries, xlfd_name, entry->d_name, PRIO(filePrio(entry->d_name))); goto done; } } @@ -930,7 +947,7 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo) found = 1; snprintf(buf, MAXFONTNAMELEN, "%s-%s", lp->value, encoding->value); - putHash(entries, buf, entry->d_name, filePrio(entry->d_name)); + putHash(entries, buf, entry->d_name, PRIO(filePrio(entry->d_name))); } } for(encoding = extra_encodings; encoding; @@ -939,7 +956,7 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo) /* Do not set found! */ snprintf(buf, MAXFONTNAMELEN, "%s-%s", lp->value, encoding->value); - putHash(entries, buf, entry->d_name, filePrio(entry->d_name)); + putHash(entries, buf, entry->d_name, PRIO(filePrio(entry->d_name))); } } } @@ -949,6 +966,7 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo) deepDestroyList(xlfd); xlfd = NULL; free(filename); +#undef PRIO } closedir(dirp); -- cgit v1.2.3