From fb1daf09c6817b243ad6776cc851026e44de45c4 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Fri, 27 Jun 2025 22:58:15 +0200 Subject: [PATCH] Use st_blksize and st_blocks members conditionally Instead of filtering Windows specifically, the preprocessor macros HAVE_STRUCT_STAT_ST_BLKSIZE and HAVE_STRUCT_STAT_ST_BLOCKS can be used. These members are mostly present on all POSIX-based systems except on Windows these days but this syncs the usage style across the code base. Additionally, in ext/standard/ftp_fopen_wrapper.c to set ssb->sb.st_blocks, also ssb->sb.st_blksize is added in the condition. --- ext/phar/func_interceptors.c | 4 +++- ext/phar/stream.c | 4 +++- ext/standard/ftp_fopen_wrapper.c | 2 +- ext/zip/zip_stream.c | 4 +++- main/streams/memory.c | 4 +++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ext/phar/func_interceptors.c b/ext/phar/func_interceptors.c index f1b2b0eba1e63..54afe2f5ae340 100644 --- a/ext/phar/func_interceptors.c +++ b/ext/phar/func_interceptors.c @@ -637,8 +637,10 @@ static void phar_file_stat(const char *filename, size_t filename_length, int typ if (data) { sb.st_ino = data->inode; } -#ifndef PHP_WIN32 +#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE sb.st_blksize = -1; +#endif +#ifdef HAVE_STRUCT_STAT_ST_BLOCKS sb.st_blocks = -1; #endif phar_fancy_stat(&sb, type, return_value); diff --git a/ext/phar/stream.c b/ext/phar/stream.c index 38c0c3e6f8010..6855b71538cd3 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -527,8 +527,10 @@ void phar_dostat(phar_archive_data *phar, phar_entry_info *data, php_stream_stat if (!is_temp_dir) { ssb->sb.st_ino = data->inode; } -#ifndef PHP_WIN32 +#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE ssb->sb.st_blksize = -1; +#endif +#ifdef HAVE_STRUCT_STAT_ST_BLOCKS ssb->sb.st_blocks = -1; #endif } diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index 51b7b311a9540..2aa35372ff47a 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -872,7 +872,7 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, const char *url, ssb->sb.st_rdev = -1; #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE ssb->sb.st_blksize = 4096; /* Guess since FTP won't expose this information */ -#ifdef HAVE_STRUCT_STAT_ST_BLOCKS +#if defined(HAVE_STRUCT_STAT_ST_BLOCKS) && defined(HAVE_STRUCT_STAT_ST_BLKSIZE) ssb->sb.st_blocks = (int)((4095 + ssb->sb.st_size) / ssb->sb.st_blksize); /* emulate ceil */ #endif #endif diff --git a/ext/zip/zip_stream.c b/ext/zip/zip_stream.c index a32324347d674..2fbfcac838bd2 100644 --- a/ext/zip/zip_stream.c +++ b/ext/zip/zip_stream.c @@ -184,8 +184,10 @@ static int php_zip_ops_stat(php_stream *stream, php_stream_statbuf *ssb) /* {{{ ssb->sb.st_ctime = sb.mtime; ssb->sb.st_nlink = 1; ssb->sb.st_rdev = -1; -#ifndef PHP_WIN32 +#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE ssb->sb.st_blksize = -1; +#endif +#ifdef HAVE_STRUCT_STAT_ST_BLOCKS ssb->sb.st_blocks = -1; #endif ssb->sb.st_ino = -1; diff --git a/main/streams/memory.c b/main/streams/memory.c index 785109db6582c..1a3882b09af2c 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -213,8 +213,10 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb) / /* generate unique inode number for alias/filename, so no phars will conflict */ ssb->sb.st_ino = 0; -#ifndef PHP_WIN32 +#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE ssb->sb.st_blksize = -1; +#endif +#ifdef HAVE_STRUCT_STAT_ST_BLOCKS ssb->sb.st_blocks = -1; #endif