Skip to content

Commit fb1daf0

Browse files
committed
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.
1 parent 22e444c commit fb1daf0

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

ext/phar/func_interceptors.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,10 @@ static void phar_file_stat(const char *filename, size_t filename_length, int typ
637637
if (data) {
638638
sb.st_ino = data->inode;
639639
}
640-
#ifndef PHP_WIN32
640+
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
641641
sb.st_blksize = -1;
642+
#endif
643+
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
642644
sb.st_blocks = -1;
643645
#endif
644646
phar_fancy_stat(&sb, type, return_value);

ext/phar/stream.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,10 @@ void phar_dostat(phar_archive_data *phar, phar_entry_info *data, php_stream_stat
527527
if (!is_temp_dir) {
528528
ssb->sb.st_ino = data->inode;
529529
}
530-
#ifndef PHP_WIN32
530+
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
531531
ssb->sb.st_blksize = -1;
532+
#endif
533+
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
532534
ssb->sb.st_blocks = -1;
533535
#endif
534536
}

ext/standard/ftp_fopen_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, const char *url,
872872
ssb->sb.st_rdev = -1;
873873
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
874874
ssb->sb.st_blksize = 4096; /* Guess since FTP won't expose this information */
875-
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
875+
#if defined(HAVE_STRUCT_STAT_ST_BLOCKS) && defined(HAVE_STRUCT_STAT_ST_BLKSIZE)
876876
ssb->sb.st_blocks = (int)((4095 + ssb->sb.st_size) / ssb->sb.st_blksize); /* emulate ceil */
877877
#endif
878878
#endif

ext/zip/zip_stream.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ static int php_zip_ops_stat(php_stream *stream, php_stream_statbuf *ssb) /* {{{
184184
ssb->sb.st_ctime = sb.mtime;
185185
ssb->sb.st_nlink = 1;
186186
ssb->sb.st_rdev = -1;
187-
#ifndef PHP_WIN32
187+
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
188188
ssb->sb.st_blksize = -1;
189+
#endif
190+
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
189191
ssb->sb.st_blocks = -1;
190192
#endif
191193
ssb->sb.st_ino = -1;

main/streams/memory.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb) /
213213
/* generate unique inode number for alias/filename, so no phars will conflict */
214214
ssb->sb.st_ino = 0;
215215

216-
#ifndef PHP_WIN32
216+
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
217217
ssb->sb.st_blksize = -1;
218+
#endif
219+
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
218220
ssb->sb.st_blocks = -1;
219221
#endif
220222

0 commit comments

Comments
 (0)