Skip to content

Commit 90ce93f

Browse files
committed
Enable building with win32 glob on non-windows
Kind of broken. We're namespacing the function and struct, but not yet the GLOB_* defines. There are a lot of places callers check if i.e. NOMATCH is defined that would likely become redundant. Currently it also has php_glob and #defines glob php_glob (etc.) - I suspect doing the opposite and changing the callers would make more sense, just doing MVP to geet it to build (even if it fails tests).
1 parent 4338feb commit 90ce93f

File tree

2 files changed

+47
-36
lines changed

2 files changed

+47
-36
lines changed

main/php_glob.c

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
* Number of matches in the current invocation of glob.
5656
*/
5757

58-
#if defined(HAVE_GLOB)
58+
#if defined(HAVE_GLOB) && defined(PHP_SYSTEM_GLOB)
59+
#else
5960

6061
#ifdef PHP_WIN32
6162
#if _MSC_VER < 1800
@@ -81,6 +82,11 @@
8182
# endif
8283
#endif
8384

85+
#ifndef _PW_BUF_LEN
86+
/* XXX: Should be sysconf(_SC_GETPW_R_SIZE_MAX), but then VLA */
87+
#define _PW_BUF_LEN 4096
88+
#endif
89+
8490
#include "php.h"
8591
#include <sys/stat.h>
8692

@@ -92,7 +98,7 @@
9298
#include <unistd.h>
9399
#endif
94100
#include <errno.h>
95-
#include "glob.h"
101+
#include "php_glob.h"
96102
#include <limits.h>
97103
#include <stdint.h>
98104
#include <stdio.h>
@@ -210,29 +216,29 @@ reallocarray(void *optr, size_t nmemb, size_t size)
210216
static int compare(const void *, const void *);
211217
static int compare_gps(const void *, const void *);
212218
static int g_Ctoc(const Char *, char *, size_t);
213-
static int g_lstat(Char *, zend_stat_t *, glob_t *);
214-
static DIR *g_opendir(Char *, glob_t *);
219+
static int g_lstat(Char *, zend_stat_t *, php_glob_t *);
220+
static DIR *g_opendir(Char *, php_glob_t *);
215221
static Char *g_strchr(const Char *, int);
216222
static int g_strncmp(const Char *, const char *, size_t);
217-
static int g_stat(Char *, zend_stat_t *, glob_t *);
218-
static int glob0(const Char *, glob_t *, struct glob_lim *);
219-
static int glob1(Char *, Char *, glob_t *, struct glob_lim *);
223+
static int g_stat(Char *, zend_stat_t *, php_glob_t *);
224+
static int glob0(const Char *, php_glob_t *, struct glob_lim *);
225+
static int glob1(Char *, Char *, php_glob_t *, struct glob_lim *);
220226
static int glob2(Char *, Char *, Char *, Char *, Char *, Char *,
221-
glob_t *, struct glob_lim *);
227+
php_glob_t *, struct glob_lim *);
222228
static int glob3(Char *, Char *, Char *, Char *, Char *,
223-
Char *, Char *, glob_t *, struct glob_lim *);
224-
static int globextend(const Char *, glob_t *, struct glob_lim *,
229+
Char *, Char *, php_glob_t *, struct glob_lim *);
230+
static int globextend(const Char *, php_glob_t *, struct glob_lim *,
225231
zend_stat_t *);
226-
static const Char *globtilde(const Char *, Char *, size_t, glob_t *);
227-
static int globexp1(const Char *, glob_t *, struct glob_lim *);
228-
static int globexp2(const Char *, const Char *, glob_t *,
232+
static const Char *globtilde(const Char *, Char *, size_t, php_glob_t *);
233+
static int globexp1(const Char *, php_glob_t *, struct glob_lim *);
234+
static int globexp2(const Char *, const Char *, php_glob_t *,
229235
struct glob_lim *);
230236
static int match(Char *, Char *, Char *);
231237
#ifdef DEBUG
232238
static void qprintf(const char *, Char *);
233239
#endif
234240

235-
PHPAPI int glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob)
241+
PHPAPI int php_glob(const char *pattern, int flags, int (*errfunc)(const char *, int), php_glob_t *pglob)
236242
{
237243
const uint8_t *patnext;
238244
int c;
@@ -295,7 +301,7 @@ PHPAPI int glob(const char *pattern, int flags, int (*errfunc)(const char *, int
295301
* invoke the standard globbing routine to glob the rest of the magic
296302
* characters
297303
*/
298-
static int globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
304+
static int globexp1(const Char *pattern, php_glob_t *pglob, struct glob_lim *limitp)
299305
{
300306
const Char* ptr = pattern;
301307

@@ -315,7 +321,7 @@ static int globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
315321
* If it succeeds then it invokes globexp1 with the new pattern.
316322
* If it fails then it tries to glob the rest of the pattern and returns.
317323
*/
318-
static int globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
324+
static int globexp2(const Char *ptr, const Char *pattern, php_glob_t *pglob, struct glob_lim *limitp)
319325
{
320326
int i, rv;
321327
Char *lm, *ls;
@@ -420,7 +426,7 @@ static int globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, struct
420426
/*
421427
* expand tilde from the passwd file.
422428
*/
423-
static const Char *globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
429+
static const Char *globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, php_glob_t *pglob)
424430
{
425431
#ifndef PHP_WIN32
426432
struct passwd pwstore, *pwd = NULL;
@@ -538,7 +544,7 @@ static int g_charclass(const Char **patternp, Char **bufnextp)
538544
* if things went well, nonzero if errors occurred. It is not an error
539545
* to find no matches.
540546
*/
541-
static int glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
547+
static int glob0(const Char *pattern, php_glob_t *pglob, struct glob_lim *limitp)
542548
{
543549
const Char *qpatnext;
544550
int c, err;
@@ -674,7 +680,7 @@ static int compare_gps(const void *_p, const void *_q)
674680
return(strcmp(p->gps_path, q->gps_path));
675681
}
676682

677-
static int glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp)
683+
static int glob1(Char *pattern, Char *pattern_last, php_glob_t *pglob, struct glob_lim *limitp)
678684
{
679685
Char pathbuf[PATH_MAX];
680686

@@ -691,7 +697,7 @@ static int glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_l
691697
* of recursion for each segment in the pattern that contains one or more
692698
* meta characters.
693699
*/
694-
static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp)
700+
static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Char *pattern, Char *pattern_last, php_glob_t *pglob, struct glob_lim *limitp)
695701
{
696702
zend_stat_t sb;
697703
Char *p, *q;
@@ -757,7 +763,7 @@ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend
757763
/* NOTREACHED */
758764
}
759765

760-
static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob, struct glob_lim *limitp)
766+
static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Char *pattern, Char *restpattern, Char *restpattern_last, php_glob_t *pglob, struct glob_lim *limitp)
761767
{
762768
struct dirent *dp;
763769
DIR *dirp;
@@ -841,7 +847,7 @@ static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend
841847

842848

843849
/*
844-
* Extend the gl_pathv member of a glob_t structure to accommodate a new item,
850+
* Extend the gl_pathv member of a php_glob_t structure to accommodate a new item,
845851
* add the new item, and update gl_pathc.
846852
*
847853
* This assumes the BSD realloc, which only copies the block when its size
@@ -850,11 +856,11 @@ static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend
850856
*
851857
* Return 0 if new item added, error code if memory couldn't be allocated.
852858
*
853-
* Invariant of the glob_t structure:
859+
* Invariant of the php_glob_t structure:
854860
* Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
855861
* gl_pathv points to (gl_offs + gl_pathc + 1) items.
856862
*/
857-
static int globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, zend_stat_t *sb)
863+
static int globextend(const Char *path, php_glob_t *pglob, struct glob_lim *limitp, zend_stat_t *sb)
858864
{
859865
char **pathv;
860866
size_t i, newn, len;
@@ -1025,8 +1031,8 @@ static int match(Char *name, Char *pat, Char *patend)
10251031
return(0);
10261032
}
10271033

1028-
/* Free allocated data belonging to a glob_t structure. */
1029-
PHPAPI void globfree(glob_t *pglob)
1034+
/* Free allocated data belonging to a php_glob_t structure. */
1035+
PHPAPI void php_globfree(php_glob_t *pglob)
10301036
{
10311037
size_t i;
10321038
char **pp;
@@ -1047,7 +1053,7 @@ PHPAPI void globfree(glob_t *pglob)
10471053
}
10481054
}
10491055

1050-
static DIR *g_opendir(Char *str, glob_t *pglob)
1056+
static DIR *g_opendir(Char *str, php_glob_t *pglob)
10511057
{
10521058
char buf[PATH_MAX];
10531059

@@ -1064,7 +1070,7 @@ static DIR *g_opendir(Char *str, glob_t *pglob)
10641070
return(opendir(buf));
10651071
}
10661072

1067-
static int g_lstat(Char *fn, zend_stat_t *sb, glob_t *pglob)
1073+
static int g_lstat(Char *fn, zend_stat_t *sb, php_glob_t *pglob)
10681074
{
10691075
char buf[PATH_MAX];
10701076

@@ -1075,7 +1081,7 @@ static int g_lstat(Char *fn, zend_stat_t *sb, glob_t *pglob)
10751081
return(php_sys_lstat(buf, sb));
10761082
}
10771083

1078-
static int g_stat(Char *fn, zend_stat_t *sb, glob_t *pglob)
1084+
static int g_stat(Char *fn, zend_stat_t *sb, php_glob_t *pglob)
10791085
{
10801086
char buf[PATH_MAX];
10811087

main/php_glob.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
* @(#)glob.h 8.1 (Berkeley) 6/2/93
3636
*/
3737

38-
#if defined(HAVE_GLOB)
38+
#if defined(HAVE_GLOB) && defined(PHP_SYSTEM_GLOB)
3939
#include <glob.h>
4040
#else
4141

42-
#ifndef _GLOB_H_
43-
#define _GLOB_H_
42+
#ifndef _PHP_GLOB_H_
43+
#define _PHP_GLOB_H_
4444

4545
#ifndef PHP_WIN32
4646
# include <sys/cdefs.h>
@@ -68,7 +68,7 @@ typedef struct {
6868
void *(*gl_opendir)(const char *);
6969
int (*gl_lstat)(const char *, zend_stat_t *);
7070
int (*gl_stat)(const char *, zend_stat_t *);
71-
} glob_t;
71+
} php_glob_t;
7272

7373
#define GLOB_APPEND 0x0001 /* Append to output from previous call. */
7474
#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
@@ -96,11 +96,16 @@ typedef struct {
9696
#endif
9797

9898
BEGIN_EXTERN_C()
99-
PHPAPI int glob(const char *__restrict, int, int (*)(const char *, int),
100-
glob_t *__restrict);
101-
PHPAPI void globfree(glob_t *);
99+
PHPAPI int php_glob(const char *__restrict, int, int (*)(const char *, int),
100+
php_glob_t *__restrict);
101+
PHPAPI void php_globfree(php_glob_t *);
102102
END_EXTERN_C()
103103

104+
// XXX: Invert defs
105+
#define glob_t php_glob_t
106+
#define glob php_glob
107+
#define globfree php_globfree
108+
104109
#endif /* !_GLOB_H_ */
105110

106111
#endif /* defined(HAVE_GLOB) */

0 commit comments

Comments
 (0)