Skip to content

Commit f63410c

Browse files
committed
improve implementation of fsync PHP function
1 parent 344f380 commit f63410c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

main/streams/plain_wrapper.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,17 +523,20 @@ static int php_stdiop_close(php_stream *stream, int close_handle)
523523
static int php_stdiop_sync(php_stream *stream)
524524
{
525525
php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
526-
int ret = 0;
526+
FILE *fp;
527527

528-
assert(data != NULL);
528+
if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS) == FAILURE) {
529+
return 1;
530+
}
529531

530-
if (data->file) {
531-
ret = fflush(data->file);
532-
if (ret == 0) {
533-
return fsync(fileno(data->file));
534-
}
532+
if (php_stdiop_flush(stream) == 0) {
533+
#ifdef PHP_WIN32
534+
return _commit(fileno(fp));
535+
#else
536+
return fsync(fileno(fp));
537+
#endif
535538
}
536-
return ret;
539+
return 1;
537540
}
538541

539542
static int php_stdiop_flush(php_stream *stream)

0 commit comments

Comments
 (0)