summaryrefslogtreecommitdiff
path: root/ext/standard/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/file.c')
-rw-r--r--ext/standard/file.c232
1 files changed, 141 insertions, 91 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 52aa07b0b6..d82c2c513e 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -57,13 +57,9 @@
# if HAVE_SYS_SELECT_H
# include <sys/select.h>
# endif
-# if defined(NETWARE) && defined(USE_WINSOCK)
-# include <novsock2.h>
-# else
-# include <sys/socket.h>
-# include <netinet/in.h>
-# include <netdb.h>
-# endif
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <netdb.h>
# if HAVE_ARPA_INET_H
# include <arpa/inet.h>
# endif
@@ -341,9 +337,12 @@ PHP_FUNCTION(flock)
php_stream *stream;
zend_long operation = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|z/", &res, &operation, &wouldblock) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 3)
+ Z_PARAM_RESOURCE(res)
+ Z_PARAM_LONG(operation)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_ZVAL_DEREF(wouldblock)
+ ZEND_PARSE_PARAMETERS_END();
PHP_STREAM_TO_ZVAL(stream, res);
@@ -354,7 +353,7 @@ PHP_FUNCTION(flock)
}
if (wouldblock) {
- zval_dtor(wouldblock);
+ zval_ptr_dtor(wouldblock);
ZVAL_LONG(wouldblock, 0);
}
@@ -390,9 +389,11 @@ PHP_FUNCTION(get_meta_tags)
memset(&md, 0, sizeof(md));
/* Parse arguments */
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|b", &filename, &filename_len, &use_include_path) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 2)
+ Z_PARAM_PATH(filename, filename_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_BOOL(use_include_path)
+ ZEND_PARSE_PARAMETERS_END();
md.stream = php_stream_open_wrapper(filename, "rb",
(use_include_path ? USE_PATH : 0) | REPORT_ERRORS,
@@ -530,9 +531,14 @@ PHP_FUNCTION(file_get_contents)
zend_string *contents;
/* Parse arguments */
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|br!ll", &filename, &filename_len, &use_include_path, &zcontext, &offset, &maxlen) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 5)
+ Z_PARAM_PATH(filename, filename_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_BOOL(use_include_path)
+ Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+ Z_PARAM_LONG(offset)
+ Z_PARAM_LONG(maxlen)
+ ZEND_PARSE_PARAMETERS_END();
if (ZEND_NUM_ARGS() == 5 && maxlen < 0) {
php_error_docref(NULL, E_WARNING, "length must be greater than or equal to zero");
@@ -583,9 +589,13 @@ PHP_FUNCTION(file_put_contents)
php_stream *srcstream = NULL;
char mode[3] = "wb";
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "pz/|lr!", &filename, &filename_len, &data, &flags, &zcontext) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 4)
+ Z_PARAM_PATH(filename, filename_len)
+ Z_PARAM_ZVAL(data)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(flags)
+ Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+ ZEND_PARSE_PARAMETERS_END();
if (Z_TYPE_P(data) == IS_RESOURCE) {
php_stream_from_zval(srcstream, data);
@@ -724,9 +734,13 @@ PHP_FUNCTION(file)
zend_string *target_buf;
/* Parse arguments */
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|lr!", &filename, &filename_len, &flags, &zcontext) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 3)
+ Z_PARAM_PATH(filename, filename_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(flags)
+ Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+ ZEND_PARSE_PARAMETERS_END();
+
if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) {
php_error_docref(NULL, E_WARNING, "'" ZEND_LONG_FMT "' flag is not supported", flags);
RETURN_FALSE;
@@ -807,9 +821,10 @@ PHP_FUNCTION(tempnam)
int fd;
zend_string *p;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp", &dir, &dir_len, &prefix, &prefix_len) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 2)
+ Z_PARAM_PATH(dir, dir_len)
+ Z_PARAM_PATH(prefix, prefix_len)
+ ZEND_PARSE_PARAMETERS_END();
if (php_check_open_basedir(dir)) {
RETURN_FALSE;
@@ -861,9 +876,13 @@ PHP_NAMED_FUNCTION(php_if_fopen)
php_stream *stream;
php_stream_context *context = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ps|br", &filename, &filename_len, &mode, &mode_len, &use_include_path, &zcontext) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 4)
+ Z_PARAM_PATH(filename, filename_len)
+ Z_PARAM_STRING(mode, mode_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_BOOL(use_include_path)
+ Z_PARAM_RESOURCE(zcontext)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
context = php_stream_context_from_zval(zcontext, 0);
@@ -913,9 +932,10 @@ PHP_FUNCTION(popen)
php_stream *stream;
char *posix_mode;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ps", &command, &command_len, &mode, &mode_len) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 2)
+ Z_PARAM_PATH(command, command_len)
+ Z_PARAM_STRING(mode, mode_len)
+ ZEND_PARSE_PARAMETERS_END();
posix_mode = estrndup(mode, mode_len);
#ifndef PHP_WIN32
@@ -954,9 +974,9 @@ PHP_FUNCTION(pclose)
zval *res;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_RESOURCE(res)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
PHP_STREAM_TO_ZVAL(stream, res);
@@ -1049,9 +1069,9 @@ PHPAPI PHP_FUNCTION(fgetc)
int result;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_RESOURCE(res)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
PHP_STREAM_TO_ZVAL(stream, res);
@@ -1081,9 +1101,12 @@ PHPAPI PHP_FUNCTION(fgetss)
char *allowed_tags=NULL;
size_t allowed_tags_len=0;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|ls", &fd, &bytes, &allowed_tags, &allowed_tags_len) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 3)
+ Z_PARAM_RESOURCE(fd)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(bytes)
+ Z_PARAM_STRING(allowed_tags, allowed_tags_len)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
PHP_STREAM_TO_ZVAL(stream, fd);
@@ -1126,9 +1149,11 @@ PHP_FUNCTION(fscanf)
size_t len;
void *what;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs*", &file_handle, &format, &format_len, &args, &argc) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, -1)
+ Z_PARAM_RESOURCE(file_handle)
+ Z_PARAM_STRING(format, format_len)
+ Z_PARAM_VARIADIC('*', args, argc)
+ ZEND_PARSE_PARAMETERS_END();
what = zend_fetch_resource2(Z_RES_P(file_handle), "File-Handle", php_file_le_stream(), php_file_le_pstream());
@@ -1314,9 +1339,13 @@ PHP_FUNCTION(mkdir)
zend_bool recursive = 0;
php_stream_context *context;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|lbr", &dir, &dir_len, &mode, &recursive, &zcontext) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 4)
+ Z_PARAM_PATH(dir, dir_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(mode)
+ Z_PARAM_BOOL(recursive)
+ Z_PARAM_RESOURCE(zcontext)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
context = php_stream_context_from_zval(zcontext, 0);
@@ -1333,9 +1362,11 @@ PHP_FUNCTION(rmdir)
zval *zcontext = NULL;
php_stream_context *context;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|r", &dir, &dir_len, &zcontext) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 2)
+ Z_PARAM_PATH(dir, dir_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_RESOURCE(zcontext)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
context = php_stream_context_from_zval(zcontext, 0);
@@ -1355,9 +1386,12 @@ PHP_FUNCTION(readfile)
php_stream *stream;
php_stream_context *context = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|br!", &filename, &filename_len, &use_include_path, &zcontext) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 3)
+ Z_PARAM_PATH(filename, filename_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_BOOL(use_include_path)
+ Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
context = php_stream_context_from_zval(zcontext, 0);
@@ -1385,9 +1419,10 @@ PHP_FUNCTION(umask)
BG(umask) = oldumask;
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mask) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(0, 1)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(mask)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
if (ZEND_NUM_ARGS() == 0) {
umask(oldumask);
@@ -1407,9 +1442,9 @@ PHPAPI PHP_FUNCTION(fpassthru)
size_t size;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_RESOURCE(res)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
PHP_STREAM_TO_ZVAL(stream, res);
@@ -1428,9 +1463,12 @@ PHP_FUNCTION(rename)
php_stream_wrapper *wrapper;
php_stream_context *context;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp|r", &old_name, &old_name_len, &new_name, &new_name_len, &zcontext) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 3)
+ Z_PARAM_PATH(old_name, old_name_len)
+ Z_PARAM_PATH(new_name, new_name_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_RESOURCE(zcontext)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
wrapper = php_stream_locate_url_wrapper(old_name, NULL, 0);
@@ -1465,9 +1503,11 @@ PHP_FUNCTION(unlink)
zval *zcontext = NULL;
php_stream_context *context = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|r", &filename, &filename_len, &zcontext) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 2)
+ Z_PARAM_PATH(filename, filename_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_RESOURCE(zcontext)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
context = php_stream_context_from_zval(zcontext, 0);
@@ -1494,9 +1534,10 @@ PHP_NAMED_FUNCTION(php_if_ftruncate)
zend_long size;
php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &fp, &size) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 2)
+ Z_PARAM_RESOURCE(fp)
+ Z_PARAM_LONG(size)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
if (size < 0) {
php_error_docref(NULL, E_WARNING, "Negative size is not supported");
@@ -1528,9 +1569,9 @@ PHP_NAMED_FUNCTION(php_if_fstat)
"size", "atime", "mtime", "ctime", "blksize", "blocks"
};
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &fp) == FAILURE) {
- RETURN_FALSE;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_RESOURCE(fp)
+ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
PHP_STREAM_TO_ZVAL(stream, fp);
@@ -1618,9 +1659,12 @@ PHP_FUNCTION(copy)
zval *zcontext = NULL;
php_stream_context *context;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp|r", &source, &source_len, &target, &target_len, &zcontext) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 3)
+ Z_PARAM_PATH(source, source_len)
+ Z_PARAM_PATH(target, target_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_RESOURCE(zcontext)
+ ZEND_PARSE_PARAMETERS_END();
if (php_check_open_basedir(source)) {
RETURN_FALSE;
@@ -1827,12 +1871,14 @@ PHP_FUNCTION(fputcsv)
char *delimiter_str = NULL, *enclosure_str = NULL, *escape_str = NULL;
size_t delimiter_str_len = 0, enclosure_str_len = 0, escape_str_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ra|sss",
- &fp, &fields, &delimiter_str, &delimiter_str_len,
- &enclosure_str, &enclosure_str_len,
- &escape_str, &escape_str_len) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 5)
+ Z_PARAM_RESOURCE(fp)
+ Z_PARAM_ARRAY(fields)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_STRING(delimiter_str, delimiter_str_len)
+ Z_PARAM_STRING(enclosure_str, enclosure_str_len)
+ Z_PARAM_STRING(escape_str, escape_str_len)
+ ZEND_PARSE_PARAMETERS_END();
if (delimiter_str != NULL) {
/* Make sure that there is at least one character in string */
@@ -1959,13 +2005,14 @@ PHP_FUNCTION(fgetcsv)
char *escape_str = NULL;
size_t escape_str_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|zsss",
- &fd, &len_zv, &delimiter_str, &delimiter_str_len,
- &enclosure_str, &enclosure_str_len,
- &escape_str, &escape_str_len) == FAILURE
- ) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(1, 5)
+ Z_PARAM_RESOURCE(fd)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_ZVAL(len_zv)
+ Z_PARAM_STRING(delimiter_str, delimiter_str_len)
+ Z_PARAM_STRING(enclosure_str, enclosure_str_len)
+ Z_PARAM_STRING(escape_str, escape_str_len)
+ ZEND_PARSE_PARAMETERS_END();
if (delimiter_str != NULL) {
/* Make sure that there is at least one character in string */
@@ -2293,7 +2340,7 @@ out:
}
/* }}} */
-#if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS)
+#if (!defined(__BEOS__) && HAVE_REALPATH) || defined(ZTS)
/* {{{ proto string realpath(string path)
Return the resolved path */
PHP_FUNCTION(realpath)
@@ -2440,9 +2487,12 @@ PHP_FUNCTION(fnmatch)
size_t pattern_len, filename_len;
zend_long flags = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp|l", &pattern, &pattern_len, &filename, &filename_len, &flags) == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_START(2, 3)
+ Z_PARAM_PATH(pattern, pattern_len)
+ Z_PARAM_PATH(filename, filename_len)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(flags)
+ ZEND_PARSE_PARAMETERS_END();
if (filename_len >= MAXPATHLEN) {
php_error_docref(NULL, E_WARNING, "Filename exceeds the maximum allowed length of %d characters", MAXPATHLEN);