]> granicus.if.org Git - php/commitdiff
added fnmatch() and glob() functions
authorHartmut Holzgraefe <hholzgra@php.net>
Thu, 21 Mar 2002 19:18:13 +0000 (19:18 +0000)
committerHartmut Holzgraefe <hholzgra@php.net>
Thu, 21 Mar 2002 19:18:13 +0000 (19:18 +0000)
could someone please check if i got the virtual dir stuff right?

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

index 69d224392d401ce8071326c9ef306f9acba06d47..c1bbb016e64758683e5279a8de990db55d8f8530 100644 (file)
@@ -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)
index 130664c3618df59cb7d5f57b0fb90c5c0b61e9df..46021a0eff221cd110c21d27fee5ff00b5207695 100644 (file)
@@ -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
index ffc67a26bea1a3d067ebb32618182c6134ed64f4..a4eb21024f9eae735b67b9668d8d45d53ce2df82 100644 (file)
 #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:
index 801970b9fe3fc9684007a6c2494622592e42b63a..8e392e68cbecf2ed288539dfd1ebd0c6a03400e5 100644 (file)
@@ -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
index ec17259ea438ef5c55c45c7f44a88a492f3c8798..4770f888b85db938d6b0b7a82ed990137c65d832 100644 (file)
@@ -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);
index 069f584acb35a936ca304e95764695f6e74baac8..f95f3afa52dd4c0148c4dcb39a444d4cf0dabae4 100644 (file)
@@ -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 */