Fix FC_PRGNAME default

As reported by Raimund Steger.
This commit is contained in:
Behdad Esfahbod 2013-01-16 21:01:28 -06:00
parent 55d39bcad0
commit 2fe5ddfdae
1 changed files with 21 additions and 19 deletions

View File

@ -140,34 +140,35 @@ retry:
prgname = FcStrdup (p);
}
#elif defined (HAVE_GETPROGNAME) && defined (HAVE_REALPATH)
const char *p = getprogname ();
char resolved_path[PATH_MAX + 1];
if (p)
{
if (realpath (p, resolved_path) != NULL)
prgname = FcStrdup (resolved_path);
}
#else
char buf[8192];
char buf[PATH_MAX + 1];
unsigned int len;
char *p = NULL;
#if defined (HAVE_GETPROGNAME) && defined (HAVE_REALPATH)
const char *q = getprogname ();
if (q)
p = realpath (q, buf);
#else
len = readlink ("/proc/self/exe", buf, sizeof (buf) - 1);
if (len > 0)
{
char *p;
p = strrchr (buf, '/');
if (p)
p++;
else
p = buf;
prgname = FcStrdup (p);
buf[len] = '\0';
p = buf;
}
#endif
if (p)
{
char *r = strrchr (p, '/');
if (r)
r++;
else
r = p;
prgname = FcStrdup (r);
}
if (!prgname)
prgname = FcStrdup ("");
@ -175,6 +176,7 @@ retry:
free (prgname);
goto retry;
}
#endif
}
if (prgname && !prgname[0])