diff options
author | Jim Meyering <jim@meyering.net> | 2000-01-30 12:09:30 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2000-01-30 12:09:30 +0000 |
commit | 62ec3fd6888c68571634a91ea4146314387fe5e2 (patch) | |
tree | 3c302edbf47bdf71613b2c084886cf0269414926 | |
parent | eda468af140580ca0d039fe28ad362baf61c1549 (diff) | |
download | coreutils-62ec3fd6888c68571634a91ea4146314387fe5e2.tar.xz |
(ST_NBLOCKS): Use st_size only for regular files and
for directories. From H. J. Lu.
-rw-r--r-- | src/system.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/system.h b/src/system.h index 3ed11ea96..87502f17f 100644 --- a/src/system.h +++ b/src/system.h @@ -193,9 +193,15 @@ extern int errno; #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) ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0)) +# 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) (st_blocks ((statbuf).st_size)) +# 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. */ @@ -211,14 +217,20 @@ extern int errno; # define ST_NBLOCKSIZE (4 * 1024) # else /* not AIX PS/2 */ # if defined(_CRAY) -# define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE) +# 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) ((statbuf).st_blocks) +# define ST_NBLOCKS(statbuf) \ + (S_ISREG ((statbuf).st_mode) \ + || S_ISDIR ((statbuf).st_mode) \ + ? (statbuf).st_blocks : 0) #endif #ifndef ST_NBLOCKSIZE |