Fix the build fail on Solaris
It's introduced by 0ac6c98294
.
Use lstat() and S_ISDIR() to check if it's the directory or not
if there are no d_type in struct dirent.
This commit is contained in:
parent
0ac6c98294
commit
4a741e9a0a
|
@ -154,6 +154,8 @@ if test "x$ac_cv_func_fstatfs" = "xyes"; then
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#endif])
|
#endif])
|
||||||
fi
|
fi
|
||||||
|
AC_CHECK_MEMBERS([struct dirent.d_type],,,
|
||||||
|
[#include <dirent.h>])
|
||||||
#
|
#
|
||||||
# regex
|
# regex
|
||||||
#
|
#
|
||||||
|
|
61
src/fcstat.c
61
src/fcstat.c
|
@ -163,7 +163,11 @@ Adler32Finish (struct Adler32 *ctx)
|
||||||
static FcBool
|
static FcBool
|
||||||
FcDirChecksumScandirFilter(const struct dirent *entry)
|
FcDirChecksumScandirFilter(const struct dirent *entry)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
||||||
return entry->d_type != DT_DIR;
|
return entry->d_type != DT_DIR;
|
||||||
|
#else
|
||||||
|
return FcFalse;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -177,25 +181,66 @@ FcDirChecksum (const FcChar8 *dir, time_t *checksum)
|
||||||
{
|
{
|
||||||
struct Adler32 ctx;
|
struct Adler32 ctx;
|
||||||
struct dirent **files;
|
struct dirent **files;
|
||||||
int n;
|
int n, ret = 0;
|
||||||
|
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
|
||||||
|
size_t len = strlen ((const char *)dir);
|
||||||
|
#endif
|
||||||
|
|
||||||
Adler32Init (&ctx);
|
Adler32Init (&ctx);
|
||||||
|
|
||||||
n = scandir ((const char *)dir, &files,
|
n = scandir ((const char *)dir, &files,
|
||||||
&FcDirChecksumScandirFilter,
|
&FcDirChecksumScandirFilter,
|
||||||
&FcDirChecksumScandirSorter);
|
&FcDirChecksumScandirSorter);
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (n--)
|
while (n--)
|
||||||
{
|
{
|
||||||
Adler32Update (&ctx, files[n]->d_name, strlen(files[n]->d_name) + 1);
|
size_t dlen = strlen (files[n]->d_name);
|
||||||
Adler32Update (&ctx, (char *)&files[n]->d_type, sizeof(files[n]->d_type));
|
int dtype;
|
||||||
free(files[n]);
|
|
||||||
|
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
||||||
|
dtype = files[n]->d_type;
|
||||||
|
#else
|
||||||
|
struct stat statb;
|
||||||
|
char *f;
|
||||||
|
|
||||||
|
f = malloc (len + 1 + dlen + 1);
|
||||||
|
if (!f)
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto bail;
|
||||||
|
}
|
||||||
|
memcpy (f, dir, len);
|
||||||
|
f[len] = FC_DIR_SEPARATOR;
|
||||||
|
memcpy (&f[len + 1], files[n]->d_name, dlen);
|
||||||
|
f[len + 1 + dlen] = 0;
|
||||||
|
if (lstat (f, &statb) < 0)
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto bail;
|
||||||
|
}
|
||||||
|
if (S_ISDIR (statb.st_mode))
|
||||||
|
goto bail;
|
||||||
|
|
||||||
|
dtype = statb.st_mode;
|
||||||
|
#endif
|
||||||
|
Adler32Update (&ctx, files[n]->d_name, dlen + 1);
|
||||||
|
Adler32Update (&ctx, (char *)&dtype, sizeof (int));
|
||||||
|
|
||||||
|
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
|
||||||
|
bail:
|
||||||
|
if (f)
|
||||||
|
free (f);
|
||||||
|
#endif
|
||||||
|
free (files[n]);
|
||||||
}
|
}
|
||||||
free(files);
|
free (files);
|
||||||
|
if (ret == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
*checksum = Adler32Finish (&ctx);
|
*checksum = Adler32Finish (&ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue