cvs: php4 /ext/standard basic_functions.c config.m4 dir.c file.c file.h php_dir.h

From: Date: Thu, 21 Mar 2002 19:18:13 +0000
Subject: cvs: php4 /ext/standard basic_functions.c config.m4 dir.c file.c file.h php_dir.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10540@lists.php.net to get a copy of this message
hholzgra Thu Mar 21 14:18:13 2002 EDT Modified files: /php4/ext/standard basic_functions.c config.m4 dir.c file.c file.h php_dir.h Log: added fnmatch() and glob() functions could someone please check if i got the virtual dir stuff right? Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.462 php4/ext/standard/basic_functions.c:1.463 --- php4/ext/standard/basic_functions.c:1.462 Thu Mar 21 10:28:46 2002 +++ php4/ext/standard/basic_functions.c Thu Mar 21 14:18:11 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.462 2002/03/21 15:28:46 andrei Exp $ */ +/* $Id: basic_functions.c,v 1.463 2002/03/21 19:18:11 hholzgra Exp $ */ #include "php.h" #include "php_streams.h" @@ -640,6 +640,12 @@ 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 @@ 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) Index: php4/ext/standard/config.m4 diff -u php4/ext/standard/config.m4:1.32 php4/ext/standard/config.m4:1.33 --- php4/ext/standard/config.m4:1.32 Thu Mar 7 09:19:38 2002 +++ php4/ext/standard/config.m4 Thu Mar 21 14:18:11 2002 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.32 2002/03/07 14:19:38 sas Exp $ -*- sh -*- +dnl $Id: config.m4,v 1.33 2002/03/21 19:18:11 hholzgra Exp $ -*- sh -*- divert(3)dnl @@ -228,6 +228,8 @@ REGEX_TYPE=php fi ]) + +AC_CHECK_FUNCS(fnmatch glob) if test "$PHP_SAPI" = "cgi"; then AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function]) Index: php4/ext/standard/dir.c diff -u php4/ext/standard/dir.c:1.87 php4/ext/standard/dir.c:1.88 --- php4/ext/standard/dir.c:1.87 Wed Mar 6 13:31:33 2002 +++ php4/ext/standard/dir.c Thu Mar 21 14:18:11 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dir.c,v 1.87 2002/03/06 18:31:33 jflemer Exp $ */ +/* $Id: dir.c,v 1.88 2002/03/21 19:18:11 hholzgra Exp $ */ /* {{{ includes/startup/misc */ @@ -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 @@ rewinddir(dirp->dir); } /* }}} */ + /* {{{ proto string readdir([resource dir_handle]) Read directory entry from dir_handle */ @@ -346,6 +351,41 @@ /* }}} */ +#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: Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.219 php4/ext/standard/file.c:1.220 --- php4/ext/standard/file.c:1.219 Wed Mar 20 20:11:52 2002 +++ php4/ext/standard/file.c Thu Mar 21 14:18:11 2002 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.219 2002/03/21 01:11:52 wez Exp $ */ +/* $Id: file.c,v 1.220 2002/03/21 19:18:11 hholzgra Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -100,6 +100,10 @@ php_file_globals file_globals; #endif +#ifdef HAVE_FNMATCH +#include <fnmatch.h> +#endif + /* }}} */ /* {{{ ZTS-stuff / Globals / Prototypes */ @@ -1998,6 +2002,30 @@ } /* }}} */ + +#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: Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.56 php4/ext/standard/file.h:1.57 --- php4/ext/standard/file.h:1.56 Wed Mar 20 09:38:11 2002 +++ php4/ext/standard/file.h Thu Mar 21 14:18:13 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.h,v 1.56 2002/03/20 14:38:11 wez Exp $ */ +/* $Id: file.h,v 1.57 2002/03/21 19:18:13 hholzgra Exp $ */ /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ @@ -66,6 +66,7 @@ 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); Index: php4/ext/standard/php_dir.h diff -u php4/ext/standard/php_dir.h:1.18 php4/ext/standard/php_dir.h:1.19 --- php4/ext/standard/php_dir.h:1.18 Thu Feb 28 03:26:46 2002 +++ php4/ext/standard/php_dir.h Thu Mar 21 14:18:13 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_dir.h,v 1.18 2002/02/28 08:26:46 sebastian Exp $ */ +/* $Id: php_dir.h,v 1.19 2002/03/21 19:18:13 hholzgra Exp $ */ #ifndef PHP_DIR_H #define PHP_DIR_H @@ -34,5 +34,6 @@ PHP_FUNCTION(rewinddir); PHP_NAMED_FUNCTION(php_if_readdir); PHP_FUNCTION(getdir); +PHP_FUNCTION(glob); #endif /* PHP_DIR_H */

« previous php.cvs (#10540) next »