mirror of
https://github.com/php/php-src.git
synced 2026-03-26 01:02:25 +01:00
added fnmatch() and glob() functions
could someone please check if i got the virtual dir stuff right?
This commit is contained in:
@@ -640,6 +640,12 @@ function_entry basic_functions[] = {
|
||||
PHP_FALIAS(realpath, warn_not_available, NULL)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FNMATCH
|
||||
PHP_FE(fnmatch, NULL)
|
||||
#else
|
||||
PHP_FALIAS(fnmatch, warn_not_available, NULL)
|
||||
#endif
|
||||
|
||||
/* functions from fsock.c */
|
||||
PHP_FE(fsockopen, third_and_fourth_args_force_ref)
|
||||
PHP_FE(pfsockopen, third_and_fourth_args_force_ref)
|
||||
@@ -673,7 +679,11 @@ function_entry basic_functions[] = {
|
||||
PHP_FE(rewinddir, NULL)
|
||||
PHP_STATIC_FE("readdir", php_if_readdir, NULL)
|
||||
PHP_FALIAS(dir, getdir, NULL)
|
||||
|
||||
#ifdef HAVE_GLOB
|
||||
PHP_FE(glob, NULL)
|
||||
#else
|
||||
PHP_FALIAS(glob, warn_not_available, NULL)
|
||||
#endif
|
||||
/* functions from filestat.c */
|
||||
PHP_FE(fileatime, NULL)
|
||||
PHP_FE(filectime, NULL)
|
||||
|
||||
@@ -229,6 +229,8 @@ AC_ARG_WITH(system-regex,
|
||||
fi
|
||||
])
|
||||
|
||||
AC_CHECK_FUNCS(fnmatch glob)
|
||||
|
||||
if test "$PHP_SAPI" = "cgi"; then
|
||||
AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function])
|
||||
fi
|
||||
|
||||
@@ -39,6 +39,10 @@
|
||||
#include "win32/readdir.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GLOB
|
||||
#include <glob.h>
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int default_dir;
|
||||
} php_dir_globals;
|
||||
@@ -326,6 +330,7 @@ PHP_FUNCTION(rewinddir)
|
||||
rewinddir(dirp->dir);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string readdir([resource dir_handle])
|
||||
Read directory entry from dir_handle */
|
||||
|
||||
@@ -346,6 +351,41 @@ PHP_NAMED_FUNCTION(php_if_readdir)
|
||||
|
||||
/* }}} */
|
||||
|
||||
#ifdef HAVE_GLOB
|
||||
/* {{{ proto array glob(string pattern [, int flags])
|
||||
*/
|
||||
PHP_FUNCTION(glob)
|
||||
{
|
||||
char *pattern = NULL;
|
||||
int argc = ZEND_NUM_ARGS();
|
||||
int pattern_len;
|
||||
long flags;
|
||||
glob_t globbuf;
|
||||
zval *new_val;
|
||||
int n;
|
||||
char path[MAXPATHLEN];
|
||||
char *ret=NULL;
|
||||
|
||||
if (zend_parse_parameters(argc TSRMLS_CC, "s|l", &pattern, &pattern_len, &flags) == FAILURE)
|
||||
return;
|
||||
|
||||
globbuf.gl_offs = 0;
|
||||
if(glob(pattern, 0, NULL, &globbuf)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
for(n=0;n<globbuf.gl_pathc;n++) {
|
||||
MAKE_STD_ZVAL(new_val);
|
||||
ZVAL_STRING(new_val, globbuf.gl_pathv[n], 1);
|
||||
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val,
|
||||
sizeof(zval *), NULL);
|
||||
ret = VCWD_GETCWD(path, MAXPATHLEN);
|
||||
}
|
||||
globfree(&globbuf);
|
||||
}
|
||||
/* }}} */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
|
||||
@@ -100,6 +100,10 @@ int file_globals_id;
|
||||
php_file_globals file_globals;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FNMATCH
|
||||
#include <fnmatch.h>
|
||||
#endif
|
||||
|
||||
/* }}} */
|
||||
/* {{{ ZTS-stuff / Globals / Prototypes */
|
||||
|
||||
@@ -1999,6 +2003,30 @@ php_meta_tags_token php_next_meta_token(php_meta_tags_data *md TSRMLS_DC)
|
||||
|
||||
/* }}} */
|
||||
|
||||
#ifdef HAVE_FNMATCH
|
||||
/* {{{ proto bool fnmatch(string pattern, string filename [, int flags])
|
||||
Match filename against pattern */
|
||||
PHP_FUNCTION(fnmatch)
|
||||
{
|
||||
char *pattern = NULL;
|
||||
char *filename = NULL;
|
||||
int argc = ZEND_NUM_ARGS();
|
||||
int pattern_len;
|
||||
int filename_len;
|
||||
long flags=0;
|
||||
|
||||
if (zend_parse_parameters(argc TSRMLS_CC, "ss|l",
|
||||
&pattern, &pattern_len,
|
||||
&filename, &filename_len,
|
||||
&flags)
|
||||
== FAILURE)
|
||||
return;
|
||||
|
||||
RETURN_BOOL( ! fnmatch( pattern, filename, flags ));
|
||||
}
|
||||
/* }}} */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
||||
@@ -66,6 +66,7 @@ PHP_FUNCTION(fd_isset);
|
||||
PHP_FUNCTION(select);
|
||||
#if (!defined(PHP_WIN32) && !defined(__BEOS__) && HAVE_REALPATH) || defined(ZTS)
|
||||
PHP_FUNCTION(realpath);
|
||||
PHP_FUNCTION(fnmatch);
|
||||
#endif
|
||||
PHP_NAMED_FUNCTION(php_if_ftruncate);
|
||||
PHP_NAMED_FUNCTION(php_if_fstat);
|
||||
|
||||
@@ -34,5 +34,6 @@ PHP_FUNCTION(getcwd);
|
||||
PHP_FUNCTION(rewinddir);
|
||||
PHP_NAMED_FUNCTION(php_if_readdir);
|
||||
PHP_FUNCTION(getdir);
|
||||
PHP_FUNCTION(glob);
|
||||
|
||||
#endif /* PHP_DIR_H */
|
||||
|
||||
Reference in New Issue
Block a user