diff options
author | Sara Golemon <pollita@php.net> | 2004-01-28 22:21:54 +0000 |
---|---|---|
committer | Sara Golemon <pollita@php.net> | 2004-01-28 22:21:54 +0000 |
commit | 6d10371ec642cbb42d61b9ee82448128c89cdf63 (patch) | |
tree | 2bd640225274195a8753b1a6818b363d8c0e3667 /main/streams/streams.c | |
parent | e691cbd4ee3d6a86e20ca93b1365996af7f23f62 (diff) | |
download | php-git-6d10371ec642cbb42d61b9ee82448128c89cdf63.tar.gz |
'Bug Fix': scandir, being a new function in PHP5 should have always been wrapper aware.
Diffstat (limited to 'main/streams/streams.c')
-rwxr-xr-x | main/streams/streams.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/main/streams/streams.c b/main/streams/streams.c index ece1870ce1..dc7a4f37ed 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1834,6 +1834,65 @@ PHPAPI int php_stream_context_del_link(php_stream_context *context, } /* }}} */ +/* {{{ php_stream_dirent_alphasort + */ +PHPAPI int php_stream_dirent_alphasort(const php_stream_dirent **a, const php_stream_dirent **b) +{ + return strcoll((*a)->d_name,(*b)->d_name); +} +/* }}} */ + +/* {{{ php_stream_dirent_alphasortr + */ +PHPAPI int php_stream_dirent_alphasortr(const php_stream_dirent **a, const php_stream_dirent **b) +{ + return strcoll((*b)->d_name,(*a)->d_name); +} +/* }}} */ + +/* {{{ php_stream_scandir + */ +PHPAPI int _php_stream_scandir(char *dirname, php_stream_dirent **namelist[], int flags, php_stream_context *context, + int (*compare) (const php_stream_dirent **a, const php_stream_dirent **b) TSRMLS_DC) +{ + php_stream *stream; + php_stream_dirent sdp; + php_stream_dirent **vector = NULL; + int vector_size = 0; + int nfiles = 0; + + if (!namelist) { + return FAILURE; + } + + stream = php_stream_opendir(dirname, ENFORCE_SAFE_MODE | REPORT_ERRORS, context); + if (!stream) { + return FAILURE; + } + + while (php_stream_readdir(stream, &sdp)) { + if (nfiles == vector_size) { + if (vector_size == 0) { + vector_size = 10; + } else { + vector_size *= 2; + } + vector = (php_stream_dirent **) erealloc(vector, vector_size * sizeof(php_stream_dirent *)); + } + + vector[nfiles++] = (php_stream_dirent*)estrndup(&sdp, sizeof(php_stream_dirent) + ((strlen(sdp.d_name) + 1) * sizeof(char))); + } + php_stream_closedir(stream); + + *namelist = vector; + + if (compare) { + qsort(*namelist, nfiles, sizeof(php_stream_dirent *), compare); + } + return nfiles; +} +/* }}} */ + /* * Local variables: * tab-width: 4 |