* find/pred.c: Include stat-size. Eliminate definitions of DEV_BSIZE, ST_BLKSIZE, ST_NBLOCKS, ST_NBLOCKSIZE macros which are now in stat-size.h (yes, this is the second set of these macros we've removed). (file_sparseness): Use ST_NBLOCKS and ST_NBLOCKSIZE. * cfg.mk (local-checks-to-skip): Don't skip sc_prohibit_stat_st_blocks, because now we no loner access the st_blocks field of struct stat, directly. --- ChangeLog | 13 +++++++++ cfg.mk | 7 ++--- find/pred.c | 76 +++----------------------------------------------------- lib/listfile.c | 9 ------ lib/listfile.h | 4 --- 5 files changed, 20 insertions(+), 89 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 8e8adf4..149d430 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,19 @@ 2011-06-11 James Youngman <[email protected]> + Use stat-size macros in pred.c also. + * find/pred.c: Include stat-size. Eliminate definitions of + DEV_BSIZE, ST_BLKSIZE, ST_NBLOCKS, ST_NBLOCKSIZE macros which are + now in stat-size.h (yes, this is the second set of these macros + we've removed). + (file_sparseness): Use ST_NBLOCKS and ST_NBLOCKSIZE. + * cfg.mk (local-checks-to-skip): Don't skip + sc_prohibit_stat_st_blocks, because now we no loner access the + st_blocks field of struct stat, directly. + * lib/listfile.c (file_blocksize): Eliminate this function, it's + no longer needed. + * lib/listfile.h: Don't declare file_blocksize. + Adopt the new gnulib module stat-size. * lib/listfile.c: Include "stat-size.h". Delete the DEV_BSIZE, ST_BLKSIZE, ST_NBLOCKS, ST_NBLOCKSIZE macros which are now in diff --git a/cfg.mk b/cfg.mk index 341a550..4cb14aa 100644 --- a/cfg.mk +++ b/cfg.mk @@ -43,10 +43,9 @@ local-checks-to-skip += sc_useless_cpp_parens local-checks-to-skip += \ sc_texinfo_acronym -# sc_prohibit_strcmp is broken because it gives false positives for cases -# where neither argument is a string literal. -# sc_prohibit_stat_st_blocks produces a false positive on definition of ST_NBLOCKS. -local-checks-to-skip += sc_prohibit_strcmp sc_prohibit_stat_st_blocks +# sc_prohibit_strcmp is broken because it gives false positives for +# cases where neither argument is a string literal. +local-checks-to-skip += sc_prohibit_strcmp # NEWS hash. We use this to detect unintended edits to bits of the NEWS file diff --git a/find/pred.c b/find/pred.c index 3373378..1ebb36d 100644 --- a/find/pred.c +++ b/find/pred.c @@ -44,6 +44,7 @@ #include "yesno.h" #include "listfile.h" #include "stat-time.h" +#include "stat-size.h" #include "dircallback.h" #include "error.h" #include "verify.h" @@ -79,71 +80,6 @@ #define CLOSEDIR(d) closedir (d) #endif - - - -/* Get or fake the disk device blocksize. - Usually defined by sys/param.h (if at all). */ -#ifndef DEV_BSIZE -# ifdef BSIZE -# define DEV_BSIZE BSIZE -# else /* !BSIZE */ -# define DEV_BSIZE 4096 -# endif /* !BSIZE */ -#endif /* !DEV_BSIZE */ - -/* Extract or fake data from a `struct stat'. - ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes. - ST_NBLOCKS: Number of blocks in the file, including indirect blocks. - ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */ -#ifndef HAVE_STRUCT_STAT_ST_BLOCKS -# define ST_BLKSIZE(statbuf) DEV_BSIZE -# if defined _POSIX_SOURCE || !defined BSIZE /* fileblocks.c uses BSIZE. */ -# define ST_NBLOCKS(statbuf) \ - (S_ISREG ((statbuf).st_mode) \ - || S_ISDIR ((statbuf).st_mode) \ - ? (statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0) : 0) -# else /* !_POSIX_SOURCE && BSIZE */ -# define ST_NBLOCKS(statbuf) \ - (S_ISREG ((statbuf).st_mode) \ - || S_ISDIR ((statbuf).st_mode) \ - ? st_blocks ((statbuf).st_size) : 0) -# endif /* !_POSIX_SOURCE && BSIZE */ -#else /* HAVE_STRUCT_STAT_ST_BLOCKS */ -/* Some systems, like Sequents, return st_blksize of 0 on pipes. */ -# define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \ - ? (statbuf).st_blksize : DEV_BSIZE) -# if defined hpux || defined __hpux__ || defined __hpux -/* HP-UX counts st_blocks in 1024-byte units. - This loses when mixing HP-UX and BSD file systems with NFS. */ -# define ST_NBLOCKSIZE 1024 -# else /* !hpux */ -# if defined _AIX && defined _I386 -/* AIX PS/2 counts st_blocks in 4K units. */ -# define ST_NBLOCKSIZE (4 * 1024) -# else /* not AIX PS/2 */ -# if defined _CRAY -# define ST_NBLOCKS(statbuf) \ - (S_ISREG ((statbuf).st_mode) \ - || S_ISDIR ((statbuf).st_mode) \ - ? (statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE : 0) -# endif /* _CRAY */ -# endif /* not AIX PS/2 */ -# endif /* !hpux */ -#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */ - -#ifndef ST_NBLOCKS -# define ST_NBLOCKS(statbuf) \ - (S_ISREG ((statbuf).st_mode) \ - || S_ISDIR ((statbuf).st_mode) \ - ? (statbuf).st_blocks : 0) -#endif - -#ifndef ST_NBLOCKSIZE -# define ST_NBLOCKSIZE 512 -#endif - - #undef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) @@ -746,22 +682,18 @@ mode_to_filetype (mode_t m) static double file_sparseness (const struct stat *p) { -#if defined HAVE_STRUCT_STAT_ST_BLOCKS if (0 == p->st_size) { - if (0 == p->st_blocks) + if (0 == ST_NBLOCKS(*p)) return 1.0; else - return p->st_blocks < 0 ? -HUGE_VAL : HUGE_VAL; + return ST_NBLOCKS(*p) < 0 ? -HUGE_VAL : HUGE_VAL; } else { - double blklen = file_blocksize (p) * (double)p->st_blocks; + double blklen = ST_NBLOCKSIZE * (double)ST_NBLOCKS(*p); return blklen / p->st_size; } -#else - return 1.0; -#endif } diff --git a/lib/listfile.c b/lib/listfile.c index 2e94bf6..48d8cb2 100644 --- a/lib/listfile.c +++ b/lib/listfile.c @@ -67,15 +67,6 @@ static void print_name (register const char *p, FILE *stream, int literal_control_chars); -size_t -file_blocksize (const struct stat *p) -{ - (void)p; - return ST_NBLOCKSIZE; -} - - - /* NAME is the name to print. RELNAME is the path to access it from the current directory. STATP is the results of stat or lstat on it. diff --git a/lib/listfile.h b/lib/listfile.h index be76d57..9ee71a2 100644 --- a/lib/listfile.h +++ b/lib/listfile.h @@ -19,9 +19,5 @@ #if !defined LISTFILE_H # define LISTFILE_H - void list_file (const char *name, int dir_fd, char *relname, const struct stat *statp, time_t current_time, int output_block_size, int literal_control_chars, FILE *stream); - -size_t file_blocksize(const struct stat *p); - #endif -- 1.7.2.5
