55
55
* Number of matches in the current invocation of glob.
56
56
*/
57
57
58
- #if defined(HAVE_GLOB )
58
+ #if defined(HAVE_GLOB ) && defined(PHP_SYSTEM_GLOB )
59
+ #else
59
60
60
61
#ifdef PHP_WIN32
61
62
#if _MSC_VER < 1800
81
82
# endif
82
83
#endif
83
84
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
+
84
90
#include "php.h"
85
91
#include <sys/stat.h>
86
92
92
98
#include <unistd.h>
93
99
#endif
94
100
#include <errno.h>
95
- #include "glob .h"
101
+ #include "php_glob .h"
96
102
#include <limits.h>
97
103
#include <stdint.h>
98
104
#include <stdio.h>
@@ -210,29 +216,29 @@ reallocarray(void *optr, size_t nmemb, size_t size)
210
216
static int compare (const void * , const void * );
211
217
static int compare_gps (const void * , const void * );
212
218
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 * );
215
221
static Char * g_strchr (const Char * , int );
216
222
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 * );
220
226
static int glob2 (Char * , Char * , Char * , Char * , Char * , Char * ,
221
- glob_t * , struct glob_lim * );
227
+ php_glob_t * , struct glob_lim * );
222
228
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 * ,
225
231
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 * ,
229
235
struct glob_lim * );
230
236
static int match (Char * , Char * , Char * );
231
237
#ifdef DEBUG
232
238
static void qprintf (const char * , Char * );
233
239
#endif
234
240
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 )
236
242
{
237
243
const uint8_t * patnext ;
238
244
int c ;
@@ -295,7 +301,7 @@ PHPAPI int glob(const char *pattern, int flags, int (*errfunc)(const char *, int
295
301
* invoke the standard globbing routine to glob the rest of the magic
296
302
* characters
297
303
*/
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 )
299
305
{
300
306
const Char * ptr = pattern ;
301
307
@@ -315,7 +321,7 @@ static int globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
315
321
* If it succeeds then it invokes globexp1 with the new pattern.
316
322
* If it fails then it tries to glob the rest of the pattern and returns.
317
323
*/
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 )
319
325
{
320
326
int i , rv ;
321
327
Char * lm , * ls ;
@@ -420,7 +426,7 @@ static int globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, struct
420
426
/*
421
427
* expand tilde from the passwd file.
422
428
*/
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 )
424
430
{
425
431
#ifndef PHP_WIN32
426
432
struct passwd pwstore , * pwd = NULL ;
@@ -538,7 +544,7 @@ static int g_charclass(const Char **patternp, Char **bufnextp)
538
544
* if things went well, nonzero if errors occurred. It is not an error
539
545
* to find no matches.
540
546
*/
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 )
542
548
{
543
549
const Char * qpatnext ;
544
550
int c , err ;
@@ -674,7 +680,7 @@ static int compare_gps(const void *_p, const void *_q)
674
680
return (strcmp (p -> gps_path , q -> gps_path ));
675
681
}
676
682
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 )
678
684
{
679
685
Char pathbuf [PATH_MAX ];
680
686
@@ -691,7 +697,7 @@ static int glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_l
691
697
* of recursion for each segment in the pattern that contains one or more
692
698
* meta characters.
693
699
*/
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 )
695
701
{
696
702
zend_stat_t sb ;
697
703
Char * p , * q ;
@@ -757,7 +763,7 @@ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend
757
763
/* NOTREACHED */
758
764
}
759
765
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 )
761
767
{
762
768
struct dirent * dp ;
763
769
DIR * dirp ;
@@ -841,7 +847,7 @@ static int glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend
841
847
842
848
843
849
/*
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,
845
851
* add the new item, and update gl_pathc.
846
852
*
847
853
* 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
850
856
*
851
857
* Return 0 if new item added, error code if memory couldn't be allocated.
852
858
*
853
- * Invariant of the glob_t structure:
859
+ * Invariant of the php_glob_t structure:
854
860
* Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
855
861
* gl_pathv points to (gl_offs + gl_pathc + 1) items.
856
862
*/
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 )
858
864
{
859
865
char * * pathv ;
860
866
size_t i , newn , len ;
@@ -1025,8 +1031,8 @@ static int match(Char *name, Char *pat, Char *patend)
1025
1031
return (0 );
1026
1032
}
1027
1033
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 )
1030
1036
{
1031
1037
size_t i ;
1032
1038
char * * pp ;
@@ -1047,7 +1053,7 @@ PHPAPI void globfree(glob_t *pglob)
1047
1053
}
1048
1054
}
1049
1055
1050
- static DIR * g_opendir (Char * str , glob_t * pglob )
1056
+ static DIR * g_opendir (Char * str , php_glob_t * pglob )
1051
1057
{
1052
1058
char buf [PATH_MAX ];
1053
1059
@@ -1064,7 +1070,7 @@ static DIR *g_opendir(Char *str, glob_t *pglob)
1064
1070
return (opendir (buf ));
1065
1071
}
1066
1072
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 )
1068
1074
{
1069
1075
char buf [PATH_MAX ];
1070
1076
@@ -1075,7 +1081,7 @@ static int g_lstat(Char *fn, zend_stat_t *sb, glob_t *pglob)
1075
1081
return (php_sys_lstat (buf , sb ));
1076
1082
}
1077
1083
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 )
1079
1085
{
1080
1086
char buf [PATH_MAX ];
1081
1087
0 commit comments