aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fontconfig/src/fcstat.c2
-rw-r--r--fontconfig/src/fcxml.c3
-rw-r--r--fontconfig/src/makefile1
-rw-r--r--include/dirent.h78
4 files changed, 81 insertions, 3 deletions
diff --git a/fontconfig/src/fcstat.c b/fontconfig/src/fcstat.c
index c2d9fe9ee..0c15f8700 100644
--- a/fontconfig/src/fcstat.c
+++ b/fontconfig/src/fcstat.c
@@ -218,7 +218,7 @@ static int
FcFStatFs (int fd, FcStatFS *statb)
{
const char *p = NULL;
- int ret;
+ int ret=0;
FcBool flag = FcFalse;
memset (statb, 0, sizeof (FcStatFS));
diff --git a/fontconfig/src/fcxml.c b/fontconfig/src/fcxml.c
index e6fdf7f7e..799352e6f 100644
--- a/fontconfig/src/fcxml.c
+++ b/fontconfig/src/fcxml.c
@@ -1850,7 +1850,8 @@ FcParseDir (FcConfigParse *parse)
#ifdef _WIN32
FcChar8 buffer[MAX_PATH];
#endif
- const FcChar8 *attr, *data;
+ const FcChar8 *attr;
+ FcChar8 *data;
FcChar8 *prefix = NULL;
attr = FcConfigGetAttribute (parse, "prefix");
diff --git a/fontconfig/src/makefile b/fontconfig/src/makefile
index f27d62fa5..a289c5f6e 100644
--- a/fontconfig/src/makefile
+++ b/fontconfig/src/makefile
@@ -33,6 +33,7 @@ CSRCS = \
fcname.c \
fcpat.c \
fcserialize.c \
+ fcstat.c \
fcstr.c \
fcxml.c \
\
diff --git a/include/dirent.h b/include/dirent.h
index 39ff0f38f..4c0f36b0c 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -177,7 +177,7 @@ static void rewinddir(DIR* dirp);
/* Set errno variable */
#if defined(_MSC_VER)
-#define DIRENT_SET_ERRNO(x) _set_errno (x)
+#define DIRENT_SET_ERRNO(x) _set_errno(x)
#else
#define DIRENT_SET_ERRNO(x) (errno = (x))
#endif
@@ -357,6 +357,82 @@ static void rewinddir(DIR* dirp)
}
}
+static int
+scandir (const char *dir,
+ struct dirent ***namelist,
+ int (*select) (const struct dirent *),
+ int (*compar) (const struct dirent **, const struct dirent **))
+{
+ DIR *dirp;
+ struct dirent *ent, *etmp, **nl = NULL, **ntmp;
+ int count = 0;
+ int allocated = 0;
+ int prior_errno;
+
+ if (!(dirp = opendir (dir)))
+ return -1;
+
+ _get_errno(&prior_errno);
+ _set_errno(0);
+
+ while ((ent = readdir (dirp)))
+ {
+ if (!select || select (ent))
+ {
+
+ /* Ignore error from readdir/select. See POSIX specs. */
+ _set_errno(0);
+
+ if (count == allocated)
+ {
+
+ if (allocated == 0)
+ allocated = 10;
+ else
+ allocated *= 2;
+
+ ntmp = (struct dirent **) realloc (nl, allocated * sizeof *nl);
+ if (!ntmp)
+ {
+ _set_errno(ENOMEM);
+ break;
+ }
+ nl = ntmp;
+ }
+
+ if (!(etmp = (struct dirent *) malloc (sizeof *ent)))
+ {
+ _set_errno(ENOMEM);
+ break;
+ }
+ *etmp = *ent;
+ nl[count++] = etmp;
+ }
+ }
+
+ _get_errno(&prior_errno);
+ if (prior_errno != 0)
+ {
+ closedir (dirp);
+ if (nl)
+ {
+ while (count > 0)
+ free (nl[--count]);
+ free (nl);
+ }
+ /* Ignore errors from closedir() and what not else. */
+ _set_errno(prior_errno);
+ return -1;
+ }
+
+ closedir (dirp);
+ _set_errno(prior_errno);
+
+ qsort (nl, count, sizeof *nl, (int (*)(const void *, const void *)) compar);
+ if (namelist)
+ *namelist = nl;
+ return count;
+}
#ifdef __cplusplus
}