Hi, Simple patch attached. Gnulib's ST_BLKSIZE has a bit more complete checks to estimate block size than what Diffutils uses.
Collin
>From 9a69d9e871f6ec5ade2f193ec6edae883ba3afe9 Mon Sep 17 00:00:00 2001 From: Collin Funk <collin.fu...@gmail.com> Date: Sat, 12 Oct 2024 20:53:15 -0700 Subject: [PATCH] maint: use Gnulib's stat-time over our own version * bootstrap.conf (gnulib_modules): Add stat-time. * configure.ac: Remove check for the st_blksize in struct stat. * src/system.h: Include stat-time.h. (STAT_BLOCKSIZE): Remove definition. * src/analyze.c (diff_2_files): * src/cmp.c (main): * src/diff3.c (read_diff): * src/io.c (sip): Use ST_BLKSIZE instead of STAT_BLOCKSIZE. --- bootstrap.conf | 1 + configure.ac | 1 - src/analyze.c | 4 ++-- src/cmp.c | 4 ++-- src/diff3.c | 4 ++-- src/io.c | 4 ++-- src/system.h | 9 +-------- 7 files changed, 10 insertions(+), 17 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 08dc2ba..32ad185 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -102,6 +102,7 @@ signal sigprocmask stat stat-macros +stat-size stat-time stdbool stdc_bit_width diff --git a/configure.ac b/configure.ac index 8904d28..48a14eb 100644 --- a/configure.ac +++ b/configure.ac @@ -145,7 +145,6 @@ AC_DEFINE([DEFAULT_EDITOR_PROGRAM], ["ed"], AC_PATH_PROG([PR_PROGRAM], [pr], [""]) AC_DEFINE_UNQUOTED([PR_PROGRAM], ["$PR_PROGRAM"], [Name of "pr" program.]) -AC_CHECK_MEMBERS([struct stat.st_blksize]) AC_CHECK_MEMBERS([struct stat.st_rdev]) AC_HEADER_DIRENT AC_HEADER_SYS_WAIT diff --git a/src/analyze.c b/src/analyze.c index d517a96..55f6e1b 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -480,8 +480,8 @@ diff_2_files (struct comparison *cmp) /* Allocate same-sized buffers for both files. */ idx_t lcm_max = IDX_MAX - 1, blksize[2]; for (int f = 0; f < 2; f++) - if (STAT_BLOCKSIZE (cmp->file[f].stat) < 0 - || ckd_add (&blksize[f], STAT_BLOCKSIZE (cmp->file[f].stat), 0)) + if (ST_BLKSIZE (cmp->file[f].stat) < 0 + || ckd_add (&blksize[f], ST_BLKSIZE (cmp->file[f].stat), 0)) blksize[f] = 0; idx_t buffer_size = buffer_lcm (sizeof (word), diff --git a/src/cmp.c b/src/cmp.c index 9a8bfc4..32efcc3 100644 --- a/src/cmp.c +++ b/src/cmp.c @@ -370,8 +370,8 @@ main (int argc, char **argv) idx_t blksize[2]; for (int f = 0; f < 2; f++) - if (STAT_BLOCKSIZE (stat_buf[0]) < 0 - || ckd_add (&blksize[f], STAT_BLOCKSIZE (stat_buf[0]), 0)) + if (ST_BLKSIZE (stat_buf[0]) < 0 + || ckd_add (&blksize[f], ST_BLKSIZE (stat_buf[0]), 0)) blksize[f] = 0; buf_size = buffer_lcm (blksize[0], blksize[1], IDX_MAX - sizeof (word)); diff --git a/src/diff3.c b/src/diff3.c index 19aa317..571992e 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -1166,8 +1166,8 @@ read_diff (char const *filea, struct stat pipestat; idx_t current_chunk_size; if (fstat (fd, &pipestat) < 0 - || STAT_BLOCKSIZE (pipestat) <= 0 - || ckd_add (¤t_chunk_size, STAT_BLOCKSIZE (pipestat), 0)) + || ST_BLKSIZE (pipestat) <= 0 + || ckd_add (¤t_chunk_size, ST_BLKSIZE (pipestat), 0)) current_chunk_size = 8 * 1024; char *diff_result = ximalloc (current_chunk_size); idx_t total = 0; diff --git a/src/io.c b/src/io.c index 51eb169..3bf27c2 100644 --- a/src/io.c +++ b/src/io.c @@ -128,8 +128,8 @@ sip (struct file_data *current, bool skip_test) else { idx_t blksize; - if (STAT_BLOCKSIZE (current->stat) < 0 - || ckd_add (&blksize, STAT_BLOCKSIZE (current->stat), 0)) + if (ST_BLKSIZE (current->stat) < 0 + || ckd_add (&blksize, ST_BLKSIZE (current->stat), 0)) blksize = 0; current->bufsize = buffer_lcm (sizeof (word), blksize, IDX_MAX); current->buffer = ximalloc (current->bufsize); diff --git a/src/system.h b/src/system.h index 1259a68..7bc778b 100644 --- a/src/system.h +++ b/src/system.h @@ -26,17 +26,10 @@ #include <sys/stat.h> #include <stat-macros.h> +#include <stat-size.h> #include <stat-time.h> #include <timespec.h> -#ifndef STAT_BLOCKSIZE -# if HAVE_STRUCT_STAT_ST_BLKSIZE -# define STAT_BLOCKSIZE(s) ((s).st_blksize) -# else -# define STAT_BLOCKSIZE(s) (8 * 1024) -# endif -#endif - #include <unistd.h> #include <fcntl.h> -- 2.47.0