Fix the build issue on GNU/Hurd
PATH_MAX isn't defined on GNU/Hurd. according to the porting guidelines (https://www.gnu.org/software/hurd/hurd/porting/guidelines.html) allocate a memory dynamically instead of relying on the length of a string with PATH_MAX. https://bugs.freedesktop.org/show_bug.cgi?id=97512
This commit is contained in:
parent
9878b306f6
commit
abdb6d658e
|
@ -148,17 +148,34 @@ retry:
|
||||||
prgname = FcStrdup ("");
|
prgname = FcStrdup ("");
|
||||||
#else
|
#else
|
||||||
# if defined (HAVE_GETEXECNAME)
|
# if defined (HAVE_GETEXECNAME)
|
||||||
const char *p = getexecname ();
|
char *p = FcStrdup(getexecname ());
|
||||||
# elif defined (HAVE_READLINK)
|
# elif defined (HAVE_READLINK)
|
||||||
char buf[PATH_MAX + 1];
|
size_t size = FC_PATH_MAX;
|
||||||
int len;
|
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
|
|
||||||
len = readlink ("/proc/self/exe", buf, sizeof (buf) - 1);
|
while (1)
|
||||||
if (len != -1)
|
|
||||||
{
|
{
|
||||||
buf[len] = '\0';
|
char *buf = malloc (size);
|
||||||
p = buf;
|
ssize_t len;
|
||||||
|
|
||||||
|
if (!buf)
|
||||||
|
break;
|
||||||
|
|
||||||
|
len = readlink ("/proc/self/exe", buf, size - 1);
|
||||||
|
if (len < 0)
|
||||||
|
{
|
||||||
|
free (buf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (len < size - 1)
|
||||||
|
{
|
||||||
|
buf[len] = 0;
|
||||||
|
p = buf;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free (buf);
|
||||||
|
size *= 2;
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
|
@ -176,6 +193,9 @@ retry:
|
||||||
|
|
||||||
if (!prgname)
|
if (!prgname)
|
||||||
prgname = FcStrdup ("");
|
prgname = FcStrdup ("");
|
||||||
|
|
||||||
|
if (p)
|
||||||
|
free (p);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!fc_atomic_ptr_cmpexch (&default_prgname, NULL, prgname)) {
|
if (!fc_atomic_ptr_cmpexch (&default_prgname, NULL, prgname)) {
|
||||||
|
|
|
@ -70,6 +70,12 @@ extern pfnSHGetFolderPathA pSHGetFolderPathA;
|
||||||
# define FC_DIR_SEPARATOR_S "/"
|
# define FC_DIR_SEPARATOR_S "/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PATH_MAX
|
||||||
|
#define FC_PATH_MAX PATH_MAX
|
||||||
|
#else
|
||||||
|
#define FC_PATH_MAX 128
|
||||||
|
#endif
|
||||||
|
|
||||||
#if __GNUC__ >= 4
|
#if __GNUC__ >= 4
|
||||||
#define FC_UNUSED __attribute__((unused))
|
#define FC_UNUSED __attribute__((unused))
|
||||||
#else
|
#else
|
||||||
|
|
12
src/fcstat.c
12
src/fcstat.c
|
@ -278,8 +278,13 @@ FcDirChecksum (const FcChar8 *dir, time_t *checksum)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
char f[PATH_MAX + 1];
|
char *f = malloc (len + 1 + dlen + 1);
|
||||||
|
|
||||||
|
if (!f)
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto bail;
|
||||||
|
}
|
||||||
memcpy (f, dir, len);
|
memcpy (f, dir, len);
|
||||||
f[len] = FC_DIR_SEPARATOR;
|
f[len] = FC_DIR_SEPARATOR;
|
||||||
memcpy (&f[len + 1], files[n]->d_name, dlen);
|
memcpy (&f[len + 1], files[n]->d_name, dlen);
|
||||||
|
@ -287,11 +292,16 @@ FcDirChecksum (const FcChar8 *dir, time_t *checksum)
|
||||||
if (lstat (f, &statb) < 0)
|
if (lstat (f, &statb) < 0)
|
||||||
{
|
{
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
free (f);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
if (S_ISDIR (statb.st_mode))
|
if (S_ISDIR (statb.st_mode))
|
||||||
|
{
|
||||||
|
free (f);
|
||||||
goto bail;
|
goto bail;
|
||||||
|
}
|
||||||
|
|
||||||
|
free (f);
|
||||||
dtype = statb.st_mode;
|
dtype = statb.st_mode;
|
||||||
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue