Skip to content

Use st_blksize and st_blocks members conditionally #18964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/phar/func_interceptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion ext/phar/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be possible to simplify a tad as if there is st_blksize, there is st_blocks, wdyt ?

Copy link
Member Author

@petk petk Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could do that, yes. Having st_blksize also most likely implies having st_blocks. And that would be good to get rid of this anomaly also in configure.ac then:

dnl AC_STRUCT_ST_BLOCKS will screw QNX because fileblocks.o does not exist.
if test "$(uname -s 2>/dev/null)" != "QNX"; then
  AC_STRUCT_ST_BLOCKS
fi

But I'm not sure. Should this be done all over php-src or only on this place?

Copy link
Member Author

@petk petk Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Yes, I think this would be completely fine then to only check for st_blksize. If it's already in ext/phar and working out there when this condition is used #ifndef PHP_WIN32, then just checking for #ifdef HAVE_STRUCT_ST_BLKSIZE is the way to go in PHP. Because I don't see any build errors from ext/phar regarding these struct members...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll recheck this a bit. Yes, everyone uses both checks and check them separately but this can totally be simplified indeed. Today's platforms all should have either both (POSIX) or none (Windows). I've already checked some BSDs, macOS, Solaris 10, Haiku...

#endif
}
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/ftp_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion ext/zip/zip_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion main/streams/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down