From 684a9793738321f354b55d138323eceab22dcd02 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Fri, 29 Jan 2021 19:24:10 +0000 Subject: [PATCH 01/18] fsync initial --- ext/standard/basic_functions_arginfo.h | 2 ++ ext/standard/file.c | 20 ++++++++++++++++++++ ext/standard/file.h | 1 + main/php_streams.h | 4 ++++ main/streams/plain_wrapper.c | 16 ++++++++++++++++ main/streams/streams.c | 9 +++++++++ 6 files changed, 52 insertions(+) diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 5eafa59b50bd..1c67d5545f0f 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -2560,6 +2560,7 @@ ZEND_FUNCTION(fstat); ZEND_FUNCTION(fseek); ZEND_FUNCTION(ftell); ZEND_FUNCTION(fflush); +ZEND_FUNCTION(fsync); ZEND_FUNCTION(fwrite); ZEND_FUNCTION(mkdir); ZEND_FUNCTION(rename); @@ -3197,6 +3198,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(fseek, arginfo_fseek) ZEND_FE(ftell, arginfo_ftell) ZEND_FE(fflush, arginfo_fflush) + ZEND_FE(fsync, arginfo_fflush) ZEND_FE(fwrite, arginfo_fwrite) ZEND_FALIAS(fputs, fwrite, arginfo_fputs) ZEND_FE(mkdir, arginfo_mkdir) diff --git a/ext/standard/file.c b/ext/standard/file.c index 6eb85ed73948..1ae72c75147a 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1170,6 +1170,26 @@ PHPAPI PHP_FUNCTION(fwrite) } /* }}} */ +PHPAPI PHP_FUNCTION(fsync) +{ + zval *res; + int ret; + php_stream *stream; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_RESOURCE(res) + ZEND_PARSE_PARAMETERS_END(); + + PHP_STREAM_TO_ZVAL(stream, res); + + ret = php_stream_sync(stream); + if (ret) { + RETURN_FALSE; + } + RETURN_TRUE; + +} + /* {{{ Flushes output */ PHPAPI PHP_FUNCTION(fflush) { diff --git a/ext/standard/file.h b/ext/standard/file.h index f9d153a52a5d..9cf007a0f062 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -29,6 +29,7 @@ PHPAPI PHP_FUNCTION(fgetc); PHPAPI PHP_FUNCTION(fgets); PHPAPI PHP_FUNCTION(fwrite); PHPAPI PHP_FUNCTION(fflush); +PHPAPI PHP_FUNCTION(fsync); PHPAPI PHP_FUNCTION(rewind); PHPAPI PHP_FUNCTION(ftell); PHPAPI PHP_FUNCTION(fseek); diff --git a/main/php_streams.h b/main/php_streams.h index 60be0a79eb49..3a36a7bb3e72 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -117,6 +117,7 @@ typedef struct _php_stream_ops { ssize_t (*read)(php_stream *stream, char *buf, size_t count); int (*close)(php_stream *stream, int close_handle); int (*flush)(php_stream *stream); + int (*sync)(php_stream *stream); const char *label; /* label for this ops structure */ @@ -336,6 +337,9 @@ PHPAPI int _php_stream_putc(php_stream *stream, int c); PHPAPI int _php_stream_flush(php_stream *stream, int closing); #define php_stream_flush(stream) _php_stream_flush((stream), 0) +PHPAPI int _php_stream_sync(php_stream *stream); +#define php_stream_sync(stream) _php_stream_sync((stream)) + PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t *returned_len); #define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index a63c225a0da5..f75f9ac00494 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -520,6 +520,21 @@ static int php_stdiop_close(php_stream *stream, int close_handle) return ret; } +//dwg +static int php_stdiop_sync(php_stream *stream) +{ + php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; + + assert(data != NULL); + + if (data->file) { + fflush(data->file); + return fsync(fileno(data->file)); + } + return 0; + +} + static int php_stdiop_flush(php_stream *stream) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; @@ -958,6 +973,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void PHPAPI php_stream_ops php_stream_stdio_ops = { php_stdiop_write, php_stdiop_read, php_stdiop_close, php_stdiop_flush, + php_stdiop_sync, "STDIO", php_stdiop_seek, php_stdiop_cast, diff --git a/main/streams/streams.c b/main/streams/streams.c index 86522afa8475..2ae6d5989818 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1224,6 +1224,15 @@ static ssize_t _php_stream_write_filtered(php_stream *stream, const char *buf, s return consumed; } +PHPAPI int _php_stream_sync(php_stream *stream) +{ + int ret = 0; + if (stream->ops->sync) { + ret = stream->ops->sync(stream); + } + return ret; +} + PHPAPI int _php_stream_flush(php_stream *stream, int closing) { int ret = 0; From 89e0c2f829bb5d2ce685932815ecaf30e5ccf2e6 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Fri, 29 Jan 2021 23:52:43 +0000 Subject: [PATCH 02/18] fix warnings regarding stream_ops order --- main/php_streams.h | 2 +- main/streams/glob_wrapper.c | 3 ++- main/streams/plain_wrapper.c | 14 ++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/main/php_streams.h b/main/php_streams.h index 3a36a7bb3e72..76429bfbe13c 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -117,7 +117,6 @@ typedef struct _php_stream_ops { ssize_t (*read)(php_stream *stream, char *buf, size_t count); int (*close)(php_stream *stream, int close_handle); int (*flush)(php_stream *stream); - int (*sync)(php_stream *stream); const char *label; /* label for this ops structure */ @@ -126,6 +125,7 @@ typedef struct _php_stream_ops { int (*cast)(php_stream *stream, int castas, void **ret); int (*stat)(php_stream *stream, php_stream_statbuf *ssb); int (*set_option)(php_stream *stream, int option, int value, void *ptrparam); + int (*sync)(php_stream *stream); } php_stream_ops; typedef struct _php_stream_wrapper_ops { diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index 212d905e1609..b1b5fd96d095 100644 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -190,7 +190,8 @@ const php_stream_ops php_glob_stream_ops = { php_glob_stream_rewind, NULL, /* cast */ NULL, /* stat */ - NULL /* set_option */ + NULL, /* set_option */ + NULL }; /* {{{ php_glob_stream_opener */ diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index f75f9ac00494..7cd9eccbf008 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -524,15 +524,17 @@ static int php_stdiop_close(php_stream *stream, int close_handle) static int php_stdiop_sync(php_stream *stream) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; + int ret = 0; assert(data != NULL); if (data->file) { - fflush(data->file); - return fsync(fileno(data->file)); + ret = fflush(data->file); + if (ret != 0) { + return fsync(fileno(data->file)); + } } - return 0; - + return ret; } static int php_stdiop_flush(php_stream *stream) @@ -973,12 +975,12 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void PHPAPI php_stream_ops php_stream_stdio_ops = { php_stdiop_write, php_stdiop_read, php_stdiop_close, php_stdiop_flush, - php_stdiop_sync, "STDIO", php_stdiop_seek, php_stdiop_cast, php_stdiop_stat, - php_stdiop_set_option + php_stdiop_set_option, + php_stdiop_sync, }; /* }}} */ From f42d8bcaf40135dae369412b4764188e69d7e6fa Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sat, 30 Jan 2021 15:57:25 +0000 Subject: [PATCH 03/18] Implement fsync via set_option --- ext/standard/basic_functions.stub.php | 3 ++ ext/standard/file.c | 48 ++++++++++++++++----------- main/php_streams.h | 11 ++++-- main/streams/glob_wrapper.c | 3 +- main/streams/plain_wrapper.c | 14 +++++--- main/streams/streams.c | 14 +++----- 6 files changed, 56 insertions(+), 37 deletions(-) diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 99d0d3c63db7..0e17f444bca3 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -823,6 +823,9 @@ function ftell($stream): int|false {} /** @param resource $stream */ function fflush($stream): bool {} +/** @param resource $stream */ +function fsync($stream): bool {} + /** @param resource $stream */ function fwrite($stream, string $data, ?int $length = null): int|false {} diff --git a/ext/standard/file.c b/ext/standard/file.c index 1ae72c75147a..aeddb1993054 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1170,26 +1170,6 @@ PHPAPI PHP_FUNCTION(fwrite) } /* }}} */ -PHPAPI PHP_FUNCTION(fsync) -{ - zval *res; - int ret; - php_stream *stream; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_RESOURCE(res) - ZEND_PARSE_PARAMETERS_END(); - - PHP_STREAM_TO_ZVAL(stream, res); - - ret = php_stream_sync(stream); - if (ret) { - RETURN_FALSE; - } - RETURN_TRUE; - -} - /* {{{ Flushes output */ PHPAPI PHP_FUNCTION(fflush) { @@ -1487,6 +1467,34 @@ PHP_FUNCTION(unlink) } /* }}} */ +/* {{{ Sync file to storage. Similar to fflush() but blocks until OS buffers have flushed. */ +PHP_FUNCTION(fsync) +{ + zval *res; + int ret; + php_stream *stream; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_RESOURCE(res) + ZEND_PARSE_PARAMETERS_END(); + + PHP_STREAM_TO_ZVAL(stream, res); + + if (!php_stream_sync_supported(stream)) { + php_error_docref(NULL, E_WARNING, "Can't fsync this stream!"); + RETURN_FALSE; + } + + ret = php_stream_sync(stream); + if (ret) { + RETURN_FALSE; + } + RETURN_TRUE; + +} +/* }}} */ + + /* {{{ Truncate file to 'size' length */ PHP_FUNCTION(ftruncate) { diff --git a/main/php_streams.h b/main/php_streams.h index 76429bfbe13c..1437f01d2c62 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -125,7 +125,6 @@ typedef struct _php_stream_ops { int (*cast)(php_stream *stream, int castas, void **ret); int (*stat)(php_stream *stream, php_stream_statbuf *ssb); int (*set_option)(php_stream *stream, int option, int value, void *ptrparam); - int (*sync)(php_stream *stream); } php_stream_ops; typedef struct _php_stream_wrapper_ops { @@ -338,7 +337,7 @@ PHPAPI int _php_stream_flush(php_stream *stream, int closing); #define php_stream_flush(stream) _php_stream_flush((stream), 0) PHPAPI int _php_stream_sync(php_stream *stream); -#define php_stream_sync(stream) _php_stream_sync((stream)) +#define php_stream_sync(stream) _php_stream_sync((stream)) PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t *returned_len); #define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL) @@ -448,6 +447,14 @@ END_EXTERN_C() /* Enable/disable blocking reads on anonymous pipes on Windows. */ #define PHP_STREAM_OPTION_PIPE_BLOCKING 13 +/* Stream can support fsync operation */ +#define PHP_STREAM_OPTION_SYNC_API 14 +#define PHP_STREAM_SYNC_SUPPORTED 0 +#define PHP_STREAM_SYNC_FSYNC 1 + +#define php_stream_sync_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_SYNC_API, PHP_STREAM_SYNC_SUPPORTED, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0) + + #define PHP_STREAM_OPTION_RETURN_OK 0 /* option set OK */ #define PHP_STREAM_OPTION_RETURN_ERR -1 /* problem setting option */ #define PHP_STREAM_OPTION_RETURN_NOTIMPL -2 /* underlying stream does not implement; streams can handle it instead */ diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index b1b5fd96d095..212d905e1609 100644 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -190,8 +190,7 @@ const php_stream_ops php_glob_stream_ops = { php_glob_stream_rewind, NULL, /* cast */ NULL, /* stat */ - NULL, /* set_option */ - NULL + NULL /* set_option */ }; /* {{{ php_glob_stream_opener */ diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 7cd9eccbf008..234b77c52e46 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -520,7 +520,6 @@ static int php_stdiop_close(php_stream *stream, int close_handle) return ret; } -//dwg static int php_stdiop_sync(php_stream *stream) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; @@ -534,7 +533,7 @@ static int php_stdiop_sync(php_stream *stream) return fsync(fileno(data->file)); } } - return ret; + return ret; } static int php_stdiop_flush(php_stream *stream) @@ -902,6 +901,14 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void #endif return PHP_STREAM_OPTION_RETURN_NOTIMPL; + case PHP_STREAM_OPTION_SYNC_API: + switch (value) { + case PHP_STREAM_SYNC_SUPPORTED: + return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; + case PHP_STREAM_SYNC_FSYNC: + return php_stdiop_sync(stream) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + } + case PHP_STREAM_OPTION_TRUNCATE_API: switch (value) { case PHP_STREAM_TRUNCATE_SUPPORTED: @@ -979,8 +986,7 @@ PHPAPI php_stream_ops php_stream_stdio_ops = { php_stdiop_seek, php_stdiop_cast, php_stdiop_stat, - php_stdiop_set_option, - php_stdiop_sync, + php_stdiop_set_option }; /* }}} */ diff --git a/main/streams/streams.c b/main/streams/streams.c index 2ae6d5989818..efcebad002fa 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1224,15 +1224,6 @@ static ssize_t _php_stream_write_filtered(php_stream *stream, const char *buf, s return consumed; } -PHPAPI int _php_stream_sync(php_stream *stream) -{ - int ret = 0; - if (stream->ops->sync) { - ret = stream->ops->sync(stream); - } - return ret; -} - PHPAPI int _php_stream_flush(php_stream *stream, int closing) { int ret = 0; @@ -1415,6 +1406,11 @@ PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, voi return ret; } +PHPAPI int _php_stream_sync(php_stream *stream) +{ + return php_stream_set_option(stream, PHP_STREAM_OPTION_SYNC_API, PHP_STREAM_SYNC_FSYNC, NULL); +} + PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize) { return php_stream_set_option(stream, PHP_STREAM_OPTION_TRUNCATE_API, PHP_STREAM_TRUNCATE_SET_SIZE, &newsize); From b8a54b1d23461ea6c863d2fdf4297b8c4d911181 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sat, 30 Jan 2021 16:06:06 +0000 Subject: [PATCH 04/18] fix typo on fflush condition --- main/streams/plain_wrapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 234b77c52e46..1ed57f45a29d 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -529,7 +529,7 @@ static int php_stdiop_sync(php_stream *stream) if (data->file) { ret = fflush(data->file); - if (ret != 0) { + if (ret == 0) { return fsync(fileno(data->file)); } } From 400e4eeb10e1d07ef280c0ce31e8cfc3026c179e Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sat, 30 Jan 2021 17:34:11 +0000 Subject: [PATCH 05/18] added basic tests --- ext/standard/tests/file/fsync.phpt | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 ext/standard/tests/file/fsync.phpt diff --git a/ext/standard/tests/file/fsync.phpt b/ext/standard/tests/file/fsync.phpt new file mode 100644 index 000000000000..f839999f0613 --- /dev/null +++ b/ext/standard/tests/file/fsync.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test fsync() function: basic functionality +--FILE-- + +--CLEAN-- + +--EXPECT-- +*** Testing fsync(): writing to a file and reading the contents *** +int(63) +bool(true) +first line of string +second line of string +third line of stringint(63) + +*** Testing fsync(): for return type *** +bool(true) + +*** Testing fsync(): for non-file stream *** +Warning: fsync(): Can't fsync this stream! +bool(false) + +*** Done *** From 55ecd46dca9ab31e77a6a51bd7e4dfc88692ca86 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sat, 30 Jan 2021 17:56:26 +0000 Subject: [PATCH 06/18] update test for warning format --- ext/standard/tests/file/fsync.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/tests/file/fsync.phpt b/ext/standard/tests/file/fsync.phpt index f839999f0613..4718978dd31e 100644 --- a/ext/standard/tests/file/fsync.phpt +++ b/ext/standard/tests/file/fsync.phpt @@ -46,7 +46,7 @@ $file_path = __DIR__; $filename = "$file_path/fsync_basic.tmp"; unlink($filename); ?> ---EXPECT-- +--EXPECTF-- *** Testing fsync(): writing to a file and reading the contents *** int(63) bool(true) @@ -58,7 +58,7 @@ third line of stringint(63) bool(true) *** Testing fsync(): for non-file stream *** -Warning: fsync(): Can't fsync this stream! +Warning: fsync(): Can't fsync this stream! in %s on line %d bool(false) *** Done *** From b8a2a29dddd00bd6357526fb376955da5c8fb4da Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sat, 30 Jan 2021 18:17:41 +0000 Subject: [PATCH 07/18] fix test typo: missing new line causing test failure --- ext/standard/tests/file/fsync.phpt | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/standard/tests/file/fsync.phpt b/ext/standard/tests/file/fsync.phpt index 4718978dd31e..3f7a19e59bb1 100644 --- a/ext/standard/tests/file/fsync.phpt +++ b/ext/standard/tests/file/fsync.phpt @@ -58,6 +58,7 @@ third line of stringint(63) bool(true) *** Testing fsync(): for non-file stream *** + Warning: fsync(): Can't fsync this stream! in %s on line %d bool(false) From c4b7d5d7ea38010426e2bd74d5674316e876956b Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sat, 30 Jan 2021 18:57:19 +0000 Subject: [PATCH 08/18] remove manual changes to generated arginfo --- ext/standard/basic_functions_arginfo.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 1c67d5545f0f..5eafa59b50bd 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -2560,7 +2560,6 @@ ZEND_FUNCTION(fstat); ZEND_FUNCTION(fseek); ZEND_FUNCTION(ftell); ZEND_FUNCTION(fflush); -ZEND_FUNCTION(fsync); ZEND_FUNCTION(fwrite); ZEND_FUNCTION(mkdir); ZEND_FUNCTION(rename); @@ -3198,7 +3197,6 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(fseek, arginfo_fseek) ZEND_FE(ftell, arginfo_ftell) ZEND_FE(fflush, arginfo_fflush) - ZEND_FE(fsync, arginfo_fflush) ZEND_FE(fwrite, arginfo_fwrite) ZEND_FALIAS(fputs, fwrite, arginfo_fputs) ZEND_FE(mkdir, arginfo_mkdir) From 344f380e3f5e6023373602e6407bb95fba2e6ccd Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sat, 30 Jan 2021 19:16:03 +0000 Subject: [PATCH 09/18] regenerated args header --- ext/standard/basic_functions_arginfo.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 5eafa59b50bd..13dbf66ffa66 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7540039937587f05584660bc1a1a8a80aa5ccbd1 */ + * Stub hash: 10b34c3c2fc59b9b7d635c69604b4c3d5fd7b19b */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0) @@ -1269,6 +1269,8 @@ ZEND_END_ARG_INFO() #define arginfo_fflush arginfo_rewind +#define arginfo_fsync arginfo_rewind + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_fwrite, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) @@ -2560,6 +2562,7 @@ ZEND_FUNCTION(fstat); ZEND_FUNCTION(fseek); ZEND_FUNCTION(ftell); ZEND_FUNCTION(fflush); +ZEND_FUNCTION(fsync); ZEND_FUNCTION(fwrite); ZEND_FUNCTION(mkdir); ZEND_FUNCTION(rename); @@ -3197,6 +3200,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(fseek, arginfo_fseek) ZEND_FE(ftell, arginfo_ftell) ZEND_FE(fflush, arginfo_fflush) + ZEND_FE(fsync, arginfo_fsync) ZEND_FE(fwrite, arginfo_fwrite) ZEND_FALIAS(fputs, fwrite, arginfo_fputs) ZEND_FE(mkdir, arginfo_mkdir) From f63410cc8c94fd36f499a1d2fd666e9d4b80f8bc Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sun, 31 Jan 2021 19:15:53 +0000 Subject: [PATCH 10/18] improve implementation of fsync PHP function --- main/streams/plain_wrapper.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 1ed57f45a29d..d27300003b0e 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -523,17 +523,20 @@ static int php_stdiop_close(php_stream *stream, int close_handle) static int php_stdiop_sync(php_stream *stream) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; - int ret = 0; + FILE *fp; - assert(data != NULL); + if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS) == FAILURE) { + return 1; + } - if (data->file) { - ret = fflush(data->file); - if (ret == 0) { - return fsync(fileno(data->file)); - } + if (php_stdiop_flush(stream) == 0) { + #ifdef PHP_WIN32 + return _commit(fileno(fp)); + #else + return fsync(fileno(fp)); + #endif } - return ret; + return 1; } static int php_stdiop_flush(php_stream *stream) From e018a8e915a8e359cee340d2e4f6104323bd9434 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sun, 31 Jan 2021 21:20:48 +0000 Subject: [PATCH 11/18] cleanup of stdiop fsync --- main/streams/plain_wrapper.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index d27300003b0e..afc36d087df6 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -524,19 +524,21 @@ static int php_stdiop_sync(php_stream *stream) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; FILE *fp; + int fd; if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS) == FAILURE) { - return 1; + return -1; } if (php_stdiop_flush(stream) == 0) { + PHP_STDIOP_GET_FD(fd, data); #ifdef PHP_WIN32 - return _commit(fileno(fp)); + return _commit(fd); #else - return fsync(fileno(fp)); + return fsync(fd); #endif } - return 1; + return -1; } static int php_stdiop_flush(php_stream *stream) From 994aa8cf28bbee95042d63ad16f937f7a89a4e96 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Sun, 31 Jan 2021 22:10:30 +0000 Subject: [PATCH 12/18] fix ordering for gcc --- main/streams/plain_wrapper.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index afc36d087df6..8d45ef3ed9ed 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -520,6 +520,24 @@ static int php_stdiop_close(php_stream *stream, int close_handle) return ret; } +static int php_stdiop_flush(php_stream *stream) +{ + php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; + + assert(data != NULL); + + /* + * stdio buffers data in user land. By calling fflush(3), this + * data is send to the kernel using write(2). fsync'ing is + * something completely different. + */ + if (data->file) { + return fflush(data->file); + } + return 0; +} + + static int php_stdiop_sync(php_stream *stream) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; @@ -541,23 +559,6 @@ static int php_stdiop_sync(php_stream *stream) return -1; } -static int php_stdiop_flush(php_stream *stream) -{ - php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; - - assert(data != NULL); - - /* - * stdio buffers data in user land. By calling fflush(3), this - * data is send to the kernel using write(2). fsync'ing is - * something completely different. - */ - if (data->file) { - return fflush(data->file); - } - return 0; -} - static int php_stdiop_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; From 8ada0d9865e6640887299e6662a65ead38b33937 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Mon, 1 Feb 2021 16:38:38 +0000 Subject: [PATCH 13/18] add fdatasync --- ext/standard/basic_functions.stub.php | 3 +++ ext/standard/basic_functions_arginfo.h | 6 +++++- ext/standard/file.c | 30 +++++++++++++++++++++++++- main/php_streams.h | 5 +++-- main/streams/plain_wrapper.c | 18 ++++++++++------ main/streams/streams.c | 8 +++++-- 6 files changed, 57 insertions(+), 13 deletions(-) diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 0e17f444bca3..9edc99525bd8 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -826,6 +826,9 @@ function fflush($stream): bool {} /** @param resource $stream */ function fsync($stream): bool {} +/** @param resource $stream */ +function fdatasync($stream): bool {} + /** @param resource $stream */ function fwrite($stream, string $data, ?int $length = null): int|false {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 13dbf66ffa66..caa381581032 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 10b34c3c2fc59b9b7d635c69604b4c3d5fd7b19b */ + * Stub hash: eb45395f5358feea888625ca491c75b677cfe51d */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0) @@ -1271,6 +1271,8 @@ ZEND_END_ARG_INFO() #define arginfo_fsync arginfo_rewind +#define arginfo_fdatasync arginfo_rewind + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_fwrite, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) @@ -2563,6 +2565,7 @@ ZEND_FUNCTION(fseek); ZEND_FUNCTION(ftell); ZEND_FUNCTION(fflush); ZEND_FUNCTION(fsync); +ZEND_FUNCTION(fdatasync); ZEND_FUNCTION(fwrite); ZEND_FUNCTION(mkdir); ZEND_FUNCTION(rename); @@ -3201,6 +3204,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(ftell, arginfo_ftell) ZEND_FE(fflush, arginfo_fflush) ZEND_FE(fsync, arginfo_fsync) + ZEND_FE(fdatasync, arginfo_fdatasync) ZEND_FE(fwrite, arginfo_fwrite) ZEND_FALIAS(fputs, fwrite, arginfo_fputs) ZEND_FE(mkdir, arginfo_mkdir) diff --git a/ext/standard/file.c b/ext/standard/file.c index aeddb1993054..32c51f9051d7 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1485,7 +1485,7 @@ PHP_FUNCTION(fsync) RETURN_FALSE; } - ret = php_stream_sync(stream); + ret = php_stream_sync(stream, 0); if (ret) { RETURN_FALSE; } @@ -1494,6 +1494,34 @@ PHP_FUNCTION(fsync) } /* }}} */ +/* {{{ Sync file data only to storage. Similar to fsync but does not flush modified metadata. POSIX only, aliased to fsync on Win32. */ +PHP_FUNCTION(fdatasync) +{ + zval *res; + int ret; + php_stream *stream; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_RESOURCE(res) + ZEND_PARSE_PARAMETERS_END(); + + PHP_STREAM_TO_ZVAL(stream, res); + + if (!php_stream_sync_supported(stream)) { + php_error_docref(NULL, E_WARNING, "Can't fsync this stream!"); + RETURN_FALSE; + } + + ret = php_stream_sync(stream, 1); + if (ret) { + RETURN_FALSE; + } + RETURN_TRUE; + +} +/* }}} */ + + /* {{{ Truncate file to 'size' length */ PHP_FUNCTION(ftruncate) diff --git a/main/php_streams.h b/main/php_streams.h index 1437f01d2c62..0bae682cedb0 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -336,8 +336,8 @@ PHPAPI int _php_stream_putc(php_stream *stream, int c); PHPAPI int _php_stream_flush(php_stream *stream, int closing); #define php_stream_flush(stream) _php_stream_flush((stream), 0) -PHPAPI int _php_stream_sync(php_stream *stream); -#define php_stream_sync(stream) _php_stream_sync((stream)) +PHPAPI int _php_stream_sync(php_stream *stream, int dataonly); +#define php_stream_sync(stream, d) _php_stream_sync((stream), (d)) PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t *returned_len); #define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL) @@ -451,6 +451,7 @@ END_EXTERN_C() #define PHP_STREAM_OPTION_SYNC_API 14 #define PHP_STREAM_SYNC_SUPPORTED 0 #define PHP_STREAM_SYNC_FSYNC 1 +#define PHP_STREAM_SYNC_FDSYNC 2 #define php_stream_sync_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_SYNC_API, PHP_STREAM_SYNC_SUPPORTED, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 8d45ef3ed9ed..8f93021ba0d1 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -54,6 +54,8 @@ extern int php_get_gid_by_name(const char *name, gid_t *gid); #if defined(PHP_WIN32) # define PLAIN_WRAP_BUF_SIZE(st) (((st) > UINT_MAX) ? UINT_MAX : (unsigned int)(st)) +#define fsync _commit +#define fdatasync fsync #else # define PLAIN_WRAP_BUF_SIZE(st) (st) #endif @@ -538,7 +540,7 @@ static int php_stdiop_flush(php_stream *stream) } -static int php_stdiop_sync(php_stream *stream) +static int php_stdiop_sync(php_stream *stream, int dataonly) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; FILE *fp; @@ -550,11 +552,11 @@ static int php_stdiop_sync(php_stream *stream) if (php_stdiop_flush(stream) == 0) { PHP_STDIOP_GET_FD(fd, data); - #ifdef PHP_WIN32 - return _commit(fd); - #else - return fsync(fd); - #endif + if (dataonly) { + return fdatasync(fd); + } else { + return fsync(fd); + } } return -1; } @@ -912,7 +914,9 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void case PHP_STREAM_SYNC_SUPPORTED: return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; case PHP_STREAM_SYNC_FSYNC: - return php_stdiop_sync(stream) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + return php_stdiop_sync(stream, 0) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + case PHP_STREAM_SYNC_FDSYNC: + return php_stdiop_sync(stream, 1) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; } case PHP_STREAM_OPTION_TRUNCATE_API: diff --git a/main/streams/streams.c b/main/streams/streams.c index efcebad002fa..1be0ad0bb4a4 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1406,9 +1406,13 @@ PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, voi return ret; } -PHPAPI int _php_stream_sync(php_stream *stream) +PHPAPI int _php_stream_sync(php_stream *stream, int dataonly) { - return php_stream_set_option(stream, PHP_STREAM_OPTION_SYNC_API, PHP_STREAM_SYNC_FSYNC, NULL); + int op = PHP_STREAM_SYNC_FSYNC; + if (dataonly) { + op = PHP_STREAM_SYNC_FDSYNC; + } + return php_stream_set_option(stream, PHP_STREAM_OPTION_SYNC_API, op, NULL); } PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize) From e7f84289684d3b439bb23124c00980bb7ad8a026 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Mon, 1 Feb 2021 17:26:30 +0000 Subject: [PATCH 14/18] add ro tests and fdatasync tests --- ext/standard/tests/file/fdatasync.phpt | 73 ++++++++++++++++++++++++++ ext/standard/tests/file/fsync.phpt | 8 +++ 2 files changed, 81 insertions(+) create mode 100644 ext/standard/tests/file/fdatasync.phpt diff --git a/ext/standard/tests/file/fdatasync.phpt b/ext/standard/tests/file/fdatasync.phpt new file mode 100644 index 000000000000..29e33a56a316 --- /dev/null +++ b/ext/standard/tests/file/fdatasync.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test fdatasync() function: basic functionality +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing fdatasync(): writing to a file and reading the contents *** +int(63) +bool(true) +first line of string +second line of string +third line of stringint(63) + +*** Testing fdatasync(): for return type *** +bool(true) + +*** Testing fdatasync(): attempting to sync read-only file *** +bool(false) + +*** Testing fdatasync(): for non-file stream *** + +Warning: fdatasync(): Can't fsync this stream! in %s on line %d +bool(false) + +*** Done *** diff --git a/ext/standard/tests/file/fsync.phpt b/ext/standard/tests/file/fsync.phpt index 3f7a19e59bb1..f38b84d1b6f8 100644 --- a/ext/standard/tests/file/fsync.phpt +++ b/ext/standard/tests/file/fsync.phpt @@ -32,6 +32,11 @@ $return_value = fsync($file_handle); var_dump( is_bool($return_value) ); fclose($file_handle); +echo "\n*** Testing fsync(): attempting to sync read-only file ***\n"; +$file_handle = fopen($filename, "r"); +var_dump(fsync($file_handle)); +fclose($file_handle); + echo "\n*** Testing fsync(): for non-file stream ***\n"; $file_handle = fopen("php://memory", "w"); $return_value = fsync($file_handle); @@ -57,6 +62,9 @@ third line of stringint(63) *** Testing fsync(): for return type *** bool(true) +*** Testing fsync(): attempting to sync read-only file *** +bool(false) + *** Testing fsync(): for non-file stream *** Warning: fsync(): Can't fsync this stream! in %s on line %d From 1f4cc8ed9397da68fa5cbae0f719e8cdf1cc3692 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Tue, 2 Feb 2021 11:45:33 +0000 Subject: [PATCH 15/18] update tests; replace test fsync ro failure on posix --- ext/standard/tests/file/fdatasync.phpt | 6 +++--- ext/standard/tests/file/fsync.phpt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/standard/tests/file/fdatasync.phpt b/ext/standard/tests/file/fdatasync.phpt index 29e33a56a316..7ce0049ae1a5 100644 --- a/ext/standard/tests/file/fdatasync.phpt +++ b/ext/standard/tests/file/fdatasync.phpt @@ -32,8 +32,8 @@ $return_value = fdatasync($file_handle); var_dump( is_bool($return_value) ); fclose($file_handle); -echo "\n*** Testing fdatasync(): attempting to sync read-only file ***\n"; -$file_handle = fopen($filename, "r"); +echo "\n*** Testing fdatasync(): attempting to sync stdin ***\n"; +$file_handle = fopen("php://stdin", "w"); var_dump(fdatasync($file_handle)); fclose($file_handle); @@ -62,7 +62,7 @@ third line of stringint(63) *** Testing fdatasync(): for return type *** bool(true) -*** Testing fdatasync(): attempting to sync read-only file *** +*** Testing fdatasync(): attempting to sync stdin *** bool(false) *** Testing fdatasync(): for non-file stream *** diff --git a/ext/standard/tests/file/fsync.phpt b/ext/standard/tests/file/fsync.phpt index f38b84d1b6f8..a841ecd4cd26 100644 --- a/ext/standard/tests/file/fsync.phpt +++ b/ext/standard/tests/file/fsync.phpt @@ -32,8 +32,8 @@ $return_value = fsync($file_handle); var_dump( is_bool($return_value) ); fclose($file_handle); -echo "\n*** Testing fsync(): attempting to sync read-only file ***\n"; -$file_handle = fopen($filename, "r"); +echo "\n*** Testing fsync(): attempting to sync stdin ***\n"; +$file_handle = fopen("php://stdin", "w"); var_dump(fsync($file_handle)); fclose($file_handle); @@ -62,7 +62,7 @@ third line of stringint(63) *** Testing fsync(): for return type *** bool(true) -*** Testing fsync(): attempting to sync read-only file *** +*** Testing fsync(): attempting to sync stdin *** bool(false) *** Testing fsync(): for non-file stream *** From a9b2ee532368003602325710dc7f868abaeec157 Mon Sep 17 00:00:00 2001 From: David Gebler Date: Wed, 3 Feb 2021 10:56:52 +0000 Subject: [PATCH 16/18] replace spaced indent with tab --- main/streams/plain_wrapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 8f93021ba0d1..f72a719f65c4 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -914,9 +914,9 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void case PHP_STREAM_SYNC_SUPPORTED: return fd == -1 ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; case PHP_STREAM_SYNC_FSYNC: - return php_stdiop_sync(stream, 0) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + return php_stdiop_sync(stream, 0) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; case PHP_STREAM_SYNC_FDSYNC: - return php_stdiop_sync(stream, 1) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; + return php_stdiop_sync(stream, 1) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR; } case PHP_STREAM_OPTION_TRUNCATE_API: From 02739dff5d2f02e1d5b3b8cbb26c2cfdadaae97a Mon Sep 17 00:00:00 2001 From: David Gebler Date: Wed, 24 Mar 2021 22:34:38 +0000 Subject: [PATCH 17/18] address review comments --- ext/standard/file.c | 14 ++------------ ext/standard/file.h | 1 - ext/standard/tests/file/fdatasync.phpt | 2 +- ext/standard/tests/file/fsync.phpt | 2 +- main/php_streams.h | 2 +- main/streams/streams.c | 4 ++-- 6 files changed, 7 insertions(+), 18 deletions(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index 54ca15500c07..aa1fde7fd116 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1481,12 +1481,7 @@ PHP_FUNCTION(fsync) RETURN_FALSE; } - ret = php_stream_sync(stream, 0); - if (ret) { - RETURN_FALSE; - } - RETURN_TRUE; - + RETURN_BOOL(php_stream_sync(stream, /* data_only */ 0) == 0); } /* }}} */ @@ -1508,12 +1503,7 @@ PHP_FUNCTION(fdatasync) RETURN_FALSE; } - ret = php_stream_sync(stream, 1); - if (ret) { - RETURN_FALSE; - } - RETURN_TRUE; - + RETURN_BOOL(php_stream_sync(stream, /* data_only */ 1) == 0); } /* }}} */ diff --git a/ext/standard/file.h b/ext/standard/file.h index 9cf007a0f062..f9d153a52a5d 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -29,7 +29,6 @@ PHPAPI PHP_FUNCTION(fgetc); PHPAPI PHP_FUNCTION(fgets); PHPAPI PHP_FUNCTION(fwrite); PHPAPI PHP_FUNCTION(fflush); -PHPAPI PHP_FUNCTION(fsync); PHPAPI PHP_FUNCTION(rewind); PHPAPI PHP_FUNCTION(ftell); PHPAPI PHP_FUNCTION(fseek); diff --git a/ext/standard/tests/file/fdatasync.phpt b/ext/standard/tests/file/fdatasync.phpt index 7ce0049ae1a5..235669a9943f 100644 --- a/ext/standard/tests/file/fdatasync.phpt +++ b/ext/standard/tests/file/fdatasync.phpt @@ -18,7 +18,7 @@ $file_handle = fopen($filename, "w"); if($file_handle == false) exit("Error:failed to open file $filename"); -if(substr(PHP_OS, 0, 3) == "WIN") { +if(PHP_OS_FAMILY == 'Windows') { $data = str_replace("\r",'', $data); } diff --git a/ext/standard/tests/file/fsync.phpt b/ext/standard/tests/file/fsync.phpt index a841ecd4cd26..7a036a55d4d0 100644 --- a/ext/standard/tests/file/fsync.phpt +++ b/ext/standard/tests/file/fsync.phpt @@ -18,7 +18,7 @@ $file_handle = fopen($filename, "w"); if($file_handle == false) exit("Error:failed to open file $filename"); -if(substr(PHP_OS, 0, 3) == "WIN") { +if(PHP_OS_FAMILY == 'Windows') { $data = str_replace("\r",'', $data); } diff --git a/main/php_streams.h b/main/php_streams.h index 794b8c6a3d49..ba1addd22160 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -336,7 +336,7 @@ PHPAPI int _php_stream_putc(php_stream *stream, int c); PHPAPI int _php_stream_flush(php_stream *stream, int closing); #define php_stream_flush(stream) _php_stream_flush((stream), 0) -PHPAPI int _php_stream_sync(php_stream *stream, int dataonly); +PHPAPI int _php_stream_sync(php_stream *stream, bool data_only); #define php_stream_sync(stream, d) _php_stream_sync((stream), (d)) PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, size_t *returned_len); diff --git a/main/streams/streams.c b/main/streams/streams.c index 4c292f2d6fd9..4965d671f474 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1406,10 +1406,10 @@ PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, voi return ret; } -PHPAPI int _php_stream_sync(php_stream *stream, int dataonly) +PHPAPI int _php_stream_sync(php_stream *stream, bool data_only) { int op = PHP_STREAM_SYNC_FSYNC; - if (dataonly) { + if (data_only) { op = PHP_STREAM_SYNC_FDSYNC; } return php_stream_set_option(stream, PHP_STREAM_OPTION_SYNC_API, op, NULL); From 80cbc2930edbd24b8129174d507ad3dd6192a0db Mon Sep 17 00:00:00 2001 From: David Gebler Date: Wed, 24 Mar 2021 22:43:34 +0000 Subject: [PATCH 18/18] remove unused variable --- ext/standard/file.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index aa1fde7fd116..00dcd5c7b675 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1467,7 +1467,6 @@ PHP_FUNCTION(unlink) PHP_FUNCTION(fsync) { zval *res; - int ret; php_stream *stream; ZEND_PARSE_PARAMETERS_START(1, 1) @@ -1489,7 +1488,6 @@ PHP_FUNCTION(fsync) PHP_FUNCTION(fdatasync) { zval *res; - int ret; php_stream *stream; ZEND_PARSE_PARAMETERS_START(1, 1)