summaryrefslogtreecommitdiff
path: root/src/od.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-08-15 22:44:45 +0200
committerJim Meyering <jim@meyering.net>2007-08-15 22:45:55 +0200
commit535a9fe5122808161398345f5ab317bd1ef6bde8 (patch)
tree833a5c6fd16059dc1fcfa56331b72857ea599dfd /src/od.c
parent9ee7933b5cdf40ed4fd82b21fc521db5135446bf (diff)
downloadcoreutils-535a9fe5122808161398345f5ab317bd1ef6bde8.tar.xz
od --skip (-j) works even on files in /proc, when the kernel lies
* src/od.c (skip): Don't let kernel misinformation (nonempty files in /proc with stat.st_size == 0) make "od -j N" misbehave. Patch by Paul Eggert. * NEWS: Document this work-around. * tests/misc/od-zero-len: New file, test for the above.
Diffstat (limited to 'src/od.c')
-rw-r--r--src/od.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/od.c b/src/od.c
index 0abce599a..8a07418d0 100644
--- a/src/od.c
+++ b/src/od.c
@@ -1035,9 +1035,11 @@ skip (uintmax_t n_skip)
/* The st_size field is valid only for regular files
(and for symbolic links, which cannot occur here).
If the number of bytes left to skip is larger than
- the size of the current file, we can decrement
- n_skip and go on to the next file. */
- if (S_ISREG (file_stats.st_mode) && 0 <= file_stats.st_size)
+ the size of the current file, we can decrement n_skip
+ and go on to the next file. Skip this optimization also
+ when st_size is 0, because some kernels report that
+ nonempty files in /proc have st_size == 0. */
+ if (S_ISREG (file_stats.st_mode) && 0 < file_stats.st_size)
{
if ((uintmax_t) file_stats.st_size < n_skip)
n_skip -= file_stats.st_size;