diff options
Diffstat (limited to 'ext/standard/file.c')
-rw-r--r-- | ext/standard/file.c | 122 |
1 files changed, 58 insertions, 64 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c index ff7c5433eb..4804e49338 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -339,16 +339,16 @@ static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN }; Portable file locking */ PHP_FUNCTION(flock) { - zval *arg1, *arg3 = NULL; + zval *res, *wouldblock = NULL; int act; php_stream *stream; zend_long operation = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z/", &arg1, &operation, &arg3) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z/", &res, &operation, &wouldblock) == FAILURE) { return; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); act = operation & 3; if (act < 1 || act > 3) { @@ -356,16 +356,16 @@ PHP_FUNCTION(flock) RETURN_FALSE; } - if (arg3) { - zval_dtor(arg3); - ZVAL_LONG(arg3, 0); + if (wouldblock) { + zval_dtor(wouldblock); + ZVAL_LONG(wouldblock, 0); } /* flock_values contains all possible actions if (operation & 4) we won't block on the lock */ act = flock_values[act - 1] | (operation & PHP_LOCK_NB ? LOCK_NB : 0); if (php_stream_lock(stream, act)) { - if (operation && errno == EWOULDBLOCK && arg3) { - ZVAL_LONG(arg3, 1); + if (operation && errno == EWOULDBLOCK && wouldblock) { + ZVAL_LONG(wouldblock, 1); } RETURN_FALSE; } @@ -887,20 +887,20 @@ PHP_NAMED_FUNCTION(php_if_fopen) Close an open file pointer */ PHPAPI PHP_FUNCTION(fclose) { - zval *arg1; + zval *res; php_stream *stream; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } #else ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_RESOURCE(arg1) + Z_PARAM_RESOURCE(res) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #endif - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if ((stream->flags & PHP_STREAM_FLAG_NO_FCLOSE) != 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%pd is not a valid stream resource", stream->res->handle); @@ -965,14 +965,14 @@ PHP_FUNCTION(popen) Close a file pointer opened by popen() */ PHP_FUNCTION(pclose) { - zval *arg1; + zval *res; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); FG(pclose_wait) = 1; zend_list_close(stream->res); @@ -985,14 +985,14 @@ PHP_FUNCTION(pclose) Test for end-of-file on a file pointer */ PHPAPI PHP_FUNCTION(feof) { - zval *arg1; + zval *res; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if (php_stream_eof(stream)) { RETURN_TRUE; @@ -1006,18 +1006,18 @@ PHPAPI PHP_FUNCTION(feof) Get a line from file pointer */ PHPAPI PHP_FUNCTION(fgets) { - zval *arg1; + zval *res; zend_long len = 1024; char *buf = NULL; int argc = ZEND_NUM_ARGS(); size_t line_len = 0; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &len) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if (argc == 1) { /* ask streams to give us a buffer of an appropriate size */ @@ -1062,16 +1062,16 @@ exit_failed: Get a character from file pointer */ PHPAPI PHP_FUNCTION(fgetc) { - zval *arg1; + zval *res; char buf[2]; int result; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); result = php_stream_getc(stream); @@ -1193,39 +1193,33 @@ PHP_FUNCTION(fscanf) Binary-safe file write */ PHPAPI PHP_FUNCTION(fwrite) { - zval *arg1; - char *arg2; - size_t arg2len; + zval *res; + char *input; + size_t inputlen; size_t ret; size_t num_bytes; - zend_long arg3 = 0; - char *buffer = NULL; + zend_long maxlen = 0; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &arg2, &arg2len, &arg3) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &res, &input, &inputlen, &maxlen) == FAILURE) { RETURN_FALSE; } if (ZEND_NUM_ARGS() == 2) { - num_bytes = arg2len; + num_bytes = inputlen; + } else if (maxlen <= 0) { + num_bytes = 0; } else { - if (arg3 > 0) { - num_bytes = MIN((size_t)arg3, arg2len); - } else { - num_bytes = 0; - } + num_bytes = MIN((size_t) maxlen, inputlen); } if (!num_bytes) { RETURN_LONG(0); } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); - ret = php_stream_write(stream, buffer ? buffer : arg2, num_bytes); - if (buffer) { - efree(buffer); - } + ret = php_stream_write(stream, input, num_bytes); RETURN_LONG(ret); } @@ -1235,15 +1229,15 @@ PHPAPI PHP_FUNCTION(fwrite) Flushes output */ PHPAPI PHP_FUNCTION(fflush) { - zval *arg1; + zval *res; int ret; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); ret = php_stream_flush(stream); if (ret) { @@ -1257,14 +1251,14 @@ PHPAPI PHP_FUNCTION(fflush) Rewind the position of a file pointer */ PHPAPI PHP_FUNCTION(rewind) { - zval *arg1; + zval *res; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if (-1 == php_stream_rewind(stream)) { RETURN_FALSE; @@ -1277,15 +1271,15 @@ PHPAPI PHP_FUNCTION(rewind) Get file pointer's read/write position */ PHPAPI PHP_FUNCTION(ftell) { - zval *arg1; + zval *res; zend_long ret; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); ret = php_stream_tell(stream); if (ret == -1) { @@ -1299,17 +1293,17 @@ PHPAPI PHP_FUNCTION(ftell) Seek on a file pointer */ PHPAPI PHP_FUNCTION(fseek) { - zval *arg1; - zend_long arg2, whence = SEEK_SET; + zval *res; + zend_long offset, whence = SEEK_SET; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &arg1, &arg2, &whence) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &res, &offset, &whence) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); - RETURN_LONG(php_stream_seek(stream, arg2, (int)whence)); + RETURN_LONG(php_stream_seek(stream, offset, (int) whence)); } /* }}} */ @@ -1411,7 +1405,7 @@ PHP_FUNCTION(readfile) Return or change the umask */ PHP_FUNCTION(umask) { - zend_long arg1 = 0; + zend_long mask = 0; int oldumask; oldumask = umask(077); @@ -1420,14 +1414,14 @@ PHP_FUNCTION(umask) BG(umask) = oldumask; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mask) == FAILURE) { RETURN_FALSE; } if (ZEND_NUM_ARGS() == 0) { umask(oldumask); } else { - umask((int)arg1); + umask((int) mask); } RETURN_LONG(oldumask); @@ -1438,15 +1432,15 @@ PHP_FUNCTION(umask) Output all remaining data from a file pointer */ PHPAPI PHP_FUNCTION(fpassthru) { - zval *arg1; + zval *res; size_t size; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); size = php_stream_passthru(stream); RETURN_LONG(size); @@ -1780,15 +1774,15 @@ safe_to_copy: Binary-safe file read */ PHPAPI PHP_FUNCTION(fread) { - zval *arg1; + zval *res; zend_long len; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &len) == FAILURE) { RETURN_FALSE; } - PHP_STREAM_TO_ZVAL(stream, arg1); + PHP_STREAM_TO_ZVAL(stream, res); if (len <= 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0"); |