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); 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 #else
char buf[8192]; char buf[PATH_MAX + 1];
unsigned int len; 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); len = readlink ("/proc/self/exe", buf, sizeof (buf) - 1);
if (len > 0) if (len > 0)
{ {
char *p; buf[len] = '\0';
p = buf;
p = strrchr (buf, '/');
if (p)
p++;
else
p = buf;
prgname = FcStrdup (p);
} }
#endif #endif
if (p)
{
char *r = strrchr (p, '/');
if (r)
r++;
else
r = p;
prgname = FcStrdup (r);
}
if (!prgname) if (!prgname)
prgname = FcStrdup (""); prgname = FcStrdup ("");
@ -175,6 +176,7 @@ retry:
free (prgname); free (prgname);
goto retry; goto retry;
} }
#endif
} }
if (prgname && !prgname[0]) if (prgname && !prgname[0])