Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad8ee74

Browse files
committed
Merge remote-tracking branch 'origin/PHP-5.6'
Conflicts: ext/standard/file.c
2 parents 3b6cd5f + 342d56b commit ad8ee74

File tree

1 file changed

+56
-64
lines changed

1 file changed

+56
-64
lines changed

ext/standard/file.c

Lines changed: 56 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -339,33 +339,33 @@ static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN };
339339
Portable file locking */
340340
PHP_FUNCTION(flock)
341341
{
342-
zval *arg1, *arg3 = NULL;
342+
zval *res, *wouldblock = NULL;
343343
int act;
344344
php_stream *stream;
345345
zend_long operation = 0;
346346

347-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z/", &arg1, &operation, &arg3) == FAILURE) {
347+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &res, &operation, &wouldblock) == FAILURE) {
348348
return;
349349
}
350350

351-
PHP_STREAM_TO_ZVAL(stream, arg1);
351+
PHP_STREAM_TO_ZVAL(stream, res);
352352

353353
act = operation & 3;
354354
if (act < 1 || act > 3) {
355355
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal operation argument");
356356
RETURN_FALSE;
357357
}
358358

359-
if (arg3) {
360-
zval_dtor(arg3);
361-
ZVAL_LONG(arg3, 0);
359+
if (wouldblock) {
360+
zval_dtor(wouldblock);
361+
ZVAL_LONG(wouldblock, 0);
362362
}
363363

364364
/* flock_values contains all possible actions if (operation & 4) we won't block on the lock */
365365
act = flock_values[act - 1] | (operation & PHP_LOCK_NB ? LOCK_NB : 0);
366366
if (php_stream_lock(stream, act)) {
367-
if (operation && errno == EWOULDBLOCK && arg3) {
368-
ZVAL_LONG(arg3, 1);
367+
if (operation && errno == EWOULDBLOCK && wouldblock) {
368+
ZVAL_LONG(wouldblock, 1);
369369
}
370370
RETURN_FALSE;
371371
}
@@ -887,20 +887,20 @@ PHP_NAMED_FUNCTION(php_if_fopen)
887887
Close an open file pointer */
888888
PHPAPI PHP_FUNCTION(fclose)
889889
{
890-
zval *arg1;
890+
zval *res;
891891
php_stream *stream;
892892

893893
#ifndef FAST_ZPP
894-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
894+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
895895
RETURN_FALSE;
896896
}
897897
#else
898898
ZEND_PARSE_PARAMETERS_START(1, 1)
899-
Z_PARAM_RESOURCE(arg1)
899+
Z_PARAM_RESOURCE(res)
900900
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
901901
#endif
902902

903-
PHP_STREAM_TO_ZVAL(stream, arg1);
903+
PHP_STREAM_TO_ZVAL(stream, res);
904904

905905
if ((stream->flags & PHP_STREAM_FLAG_NO_FCLOSE) != 0) {
906906
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)
965965
Close a file pointer opened by popen() */
966966
PHP_FUNCTION(pclose)
967967
{
968-
zval *arg1;
968+
zval *res;
969969
php_stream *stream;
970970

971-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
971+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
972972
RETURN_FALSE;
973973
}
974974

975-
PHP_STREAM_TO_ZVAL(stream, arg1);
975+
PHP_STREAM_TO_ZVAL(stream, res);
976976

977977
FG(pclose_wait) = 1;
978978
zend_list_close(stream->res);
@@ -985,14 +985,14 @@ PHP_FUNCTION(pclose)
985985
Test for end-of-file on a file pointer */
986986
PHPAPI PHP_FUNCTION(feof)
987987
{
988-
zval *arg1;
988+
zval *res;
989989
php_stream *stream;
990990

991-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
991+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
992992
RETURN_FALSE;
993993
}
994994

995-
PHP_STREAM_TO_ZVAL(stream, arg1);
995+
PHP_STREAM_TO_ZVAL(stream, res);
996996

997997
if (php_stream_eof(stream)) {
998998
RETURN_TRUE;
@@ -1006,18 +1006,18 @@ PHPAPI PHP_FUNCTION(feof)
10061006
Get a line from file pointer */
10071007
PHPAPI PHP_FUNCTION(fgets)
10081008
{
1009-
zval *arg1;
1009+
zval *res;
10101010
zend_long len = 1024;
10111011
char *buf = NULL;
10121012
int argc = ZEND_NUM_ARGS();
10131013
size_t line_len = 0;
10141014
php_stream *stream;
10151015

1016-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &len) == FAILURE) {
1016+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &len) == FAILURE) {
10171017
RETURN_FALSE;
10181018
}
10191019

1020-
PHP_STREAM_TO_ZVAL(stream, arg1);
1020+
PHP_STREAM_TO_ZVAL(stream, res);
10211021

10221022
if (argc == 1) {
10231023
/* ask streams to give us a buffer of an appropriate size */
@@ -1062,16 +1062,16 @@ PHPAPI PHP_FUNCTION(fgets)
10621062
Get a character from file pointer */
10631063
PHPAPI PHP_FUNCTION(fgetc)
10641064
{
1065-
zval *arg1;
1065+
zval *res;
10661066
char buf[2];
10671067
int result;
10681068
php_stream *stream;
10691069

1070-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
1070+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
10711071
RETURN_FALSE;
10721072
}
10731073

1074-
PHP_STREAM_TO_ZVAL(stream, arg1);
1074+
PHP_STREAM_TO_ZVAL(stream, res);
10751075

10761076
result = php_stream_getc(stream);
10771077

@@ -1193,39 +1193,31 @@ PHP_FUNCTION(fscanf)
11931193
Binary-safe file write */
11941194
PHPAPI PHP_FUNCTION(fwrite)
11951195
{
1196-
zval *arg1;
1197-
char *arg2;
1198-
size_t arg2len;
1196+
zval *res;
1197+
char *input;
1198+
size_t inputlen;
11991199
size_t ret;
12001200
size_t num_bytes;
1201-
zend_long arg3 = 0;
1202-
char *buffer = NULL;
1201+
zend_long maxlen = 0;
12031202
php_stream *stream;
12041203

1205-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &arg2, &arg2len, &arg3) == FAILURE) {
1204+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &res, &input, &inputlen, &maxlen) == FAILURE) {
12061205
RETURN_FALSE;
12071206
}
12081207

12091208
if (ZEND_NUM_ARGS() == 2) {
1210-
num_bytes = arg2len;
1209+
num_bytes = inputlen;
12111210
} else {
1212-
if (arg3 > 0) {
1213-
num_bytes = MIN((size_t)arg3, arg2len);
1214-
} else {
1215-
num_bytes = 0;
1216-
}
1211+
num_bytes = MAX(0, MIN((size_t) maxlen, inputlen));
12171212
}
12181213

12191214
if (!num_bytes) {
12201215
RETURN_LONG(0);
12211216
}
12221217

1223-
PHP_STREAM_TO_ZVAL(stream, arg1);
1218+
PHP_STREAM_TO_ZVAL(stream, res);
12241219

1225-
ret = php_stream_write(stream, buffer ? buffer : arg2, num_bytes);
1226-
if (buffer) {
1227-
efree(buffer);
1228-
}
1220+
ret = php_stream_write(stream, input, num_bytes);
12291221

12301222
RETURN_LONG(ret);
12311223
}
@@ -1235,15 +1227,15 @@ PHPAPI PHP_FUNCTION(fwrite)
12351227
Flushes output */
12361228
PHPAPI PHP_FUNCTION(fflush)
12371229
{
1238-
zval *arg1;
1230+
zval *res;
12391231
int ret;
12401232
php_stream *stream;
12411233

1242-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
1234+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
12431235
RETURN_FALSE;
12441236
}
12451237

1246-
PHP_STREAM_TO_ZVAL(stream, arg1);
1238+
PHP_STREAM_TO_ZVAL(stream, res);
12471239

12481240
ret = php_stream_flush(stream);
12491241
if (ret) {
@@ -1257,14 +1249,14 @@ PHPAPI PHP_FUNCTION(fflush)
12571249
Rewind the position of a file pointer */
12581250
PHPAPI PHP_FUNCTION(rewind)
12591251
{
1260-
zval *arg1;
1252+
zval *res;
12611253
php_stream *stream;
12621254

1263-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
1255+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
12641256
RETURN_FALSE;
12651257
}
12661258

1267-
PHP_STREAM_TO_ZVAL(stream, arg1);
1259+
PHP_STREAM_TO_ZVAL(stream, res);
12681260

12691261
if (-1 == php_stream_rewind(stream)) {
12701262
RETURN_FALSE;
@@ -1277,15 +1269,15 @@ PHPAPI PHP_FUNCTION(rewind)
12771269
Get file pointer's read/write position */
12781270
PHPAPI PHP_FUNCTION(ftell)
12791271
{
1280-
zval *arg1;
1272+
zval *res;
12811273
zend_long ret;
12821274
php_stream *stream;
12831275

1284-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
1276+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
12851277
RETURN_FALSE;
12861278
}
12871279

1288-
PHP_STREAM_TO_ZVAL(stream, arg1);
1280+
PHP_STREAM_TO_ZVAL(stream, res);
12891281

12901282
ret = php_stream_tell(stream);
12911283
if (ret == -1) {
@@ -1299,17 +1291,17 @@ PHPAPI PHP_FUNCTION(ftell)
12991291
Seek on a file pointer */
13001292
PHPAPI PHP_FUNCTION(fseek)
13011293
{
1302-
zval *arg1;
1303-
zend_long arg2, whence = SEEK_SET;
1294+
zval *res;
1295+
zend_long offset, whence = SEEK_SET;
13041296
php_stream *stream;
13051297

1306-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &arg1, &arg2, &whence) == FAILURE) {
1298+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &res, &offset, &whence) == FAILURE) {
13071299
RETURN_FALSE;
13081300
}
13091301

1310-
PHP_STREAM_TO_ZVAL(stream, arg1);
1302+
PHP_STREAM_TO_ZVAL(stream, res);
13111303

1312-
RETURN_LONG(php_stream_seek(stream, arg2, (int)whence));
1304+
RETURN_LONG(php_stream_seek(stream, offset, (int) whence));
13131305
}
13141306
/* }}} */
13151307

@@ -1411,7 +1403,7 @@ PHP_FUNCTION(readfile)
14111403
Return or change the umask */
14121404
PHP_FUNCTION(umask)
14131405
{
1414-
zend_long arg1 = 0;
1406+
zend_long mask = 0;
14151407
int oldumask;
14161408

14171409
oldumask = umask(077);
@@ -1420,14 +1412,14 @@ PHP_FUNCTION(umask)
14201412
BG(umask) = oldumask;
14211413
}
14221414

1423-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &arg1) == FAILURE) {
1415+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mask) == FAILURE) {
14241416
RETURN_FALSE;
14251417
}
14261418

14271419
if (ZEND_NUM_ARGS() == 0) {
14281420
umask(oldumask);
14291421
} else {
1430-
umask((int)arg1);
1422+
umask((int) mask);
14311423
}
14321424

14331425
RETURN_LONG(oldumask);
@@ -1438,15 +1430,15 @@ PHP_FUNCTION(umask)
14381430
Output all remaining data from a file pointer */
14391431
PHPAPI PHP_FUNCTION(fpassthru)
14401432
{
1441-
zval *arg1;
1433+
zval *res;
14421434
size_t size;
14431435
php_stream *stream;
14441436

1445-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
1437+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
14461438
RETURN_FALSE;
14471439
}
14481440

1449-
PHP_STREAM_TO_ZVAL(stream, arg1);
1441+
PHP_STREAM_TO_ZVAL(stream, res);
14501442

14511443
size = php_stream_passthru(stream);
14521444
RETURN_LONG(size);
@@ -1780,15 +1772,15 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
17801772
Binary-safe file read */
17811773
PHPAPI PHP_FUNCTION(fread)
17821774
{
1783-
zval *arg1;
1775+
zval *res;
17841776
zend_long len;
17851777
php_stream *stream;
17861778

1787-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &len) == FAILURE) {
1779+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &len) == FAILURE) {
17881780
RETURN_FALSE;
17891781
}
17901782

1791-
PHP_STREAM_TO_ZVAL(stream, arg1);
1783+
PHP_STREAM_TO_ZVAL(stream, res);
17921784

17931785
if (len <= 0) {
17941786
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");

0 commit comments

Comments
 (0)