From 2abb903344d4f655b1350c117d1a4197ff54096f Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Mon, 19 Aug 2024 17:58:47 +0200 Subject: [PATCH] tests: Add fallback for glob() Fix build on platforms without glob(). --- runtest.c | 30 ++++++++++++++++++++++++++++-- testrecurse.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/runtest.c b/runtest.c index 7bfbfc7b..e1456bb4 100644 --- a/runtest.c +++ b/runtest.c @@ -209,9 +209,35 @@ static void globfree(glob_t *pglob) { } } -#else +#elif HAVE_DECL_GLOB + #include -#endif + +#else /* _WIN32, HAVE_DECL_GLOB */ + +#define GLOB_DOOFFS 0 + +typedef struct { + size_t gl_pathc; /* Count of paths matched so far */ + char **gl_pathv; /* List of matched pathnames. */ + size_t gl_offs; /* Slots to reserve in 'gl_pathv'. */ +} glob_t; + +static int +glob(const char *pattern ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED, + int errfunc(const char *epath, int eerrno) ATTRIBUTE_UNUSED, + glob_t *pglob) { + pglob->gl_pathc = 0; + pglob->gl_pathv = NULL; + + return(0); +} + +static void +globfree(glob_t *pglob ATTRIBUTE_UNUSED) { +} + +#endif /* _WIN32, HAVE_DECL_GLOB */ /************************************************************************ * * diff --git a/testrecurse.c b/testrecurse.c index 47392872..478cb974 100644 --- a/testrecurse.c +++ b/testrecurse.c @@ -145,9 +145,35 @@ static void globfree(glob_t *pglob) { } } -#else +#elif HAVE_DECL_GLOB + #include -#endif + +#else /* _WIN32, HAVE_DECL_GLOB */ + +#define GLOB_DOOFFS 0 + +typedef struct { + size_t gl_pathc; /* Count of paths matched so far */ + char **gl_pathv; /* List of matched pathnames. */ + size_t gl_offs; /* Slots to reserve in 'gl_pathv'. */ +} glob_t; + +static int +glob(const char *pattern ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED, + int errfunc(const char *epath, int eerrno) ATTRIBUTE_UNUSED, + glob_t *pglob) { + pglob->gl_pathc = 0; + pglob->gl_pathv = NULL; + + return(0); +} + +static void +globfree(glob_t *pglob ATTRIBUTE_UNUSED) { +} + +#endif /* _WIN32, HAVE_DECL_GLOB */ /************************************************************************ * *