summaryrefslogtreecommitdiff
path: root/src/od.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1995-11-11 22:08:16 +0000
committerJim Meyering <jim@meyering.net>1995-11-11 22:08:16 +0000
commit849a1c46cfa48ebaf4339a5a5b7f2ec9ddce5fb9 (patch)
treeefaa263531fa5c3576c21e0ae5b9a4a84bc698af /src/od.c
parent7c863aef95d0041c518c3b4037f2d7ea67087c06 (diff)
downloadcoreutils-849a1c46cfa48ebaf4339a5a5b7f2ec9ddce5fb9.tar.xz
(skip): Cast fseek's offset argument to `long'.
Erik Bennett <bennett@cvo.oneworld.com> reported that this is necessary on BSDI systems. And if offset doesn't fit in a long, then try using lseek instead.
Diffstat (limited to 'src/od.c')
-rw-r--r--src/od.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/od.c b/src/od.c
index 559626a19..0293b11a1 100644
--- a/src/od.c
+++ b/src/od.c
@@ -981,7 +981,13 @@ skip (off_t n_skip)
}
else
{
- if (fseek (in_stream, n_skip, SEEK_SET) == 0)
+ /* fseek may work on some streams for which lseek doesn't.
+ But fseek's offset argument is restricted to the range
+ of type `long'. So if N_SKIP is too large or if fseek
+ fails, try lseek. */
+ if ((n_skip <= LONG_MAX
+ && fseek (in_stream, (long) n_skip, SEEK_SET) == 0)
+ || lseek (fileno (in_stream), n_skip, SEEK_SET) >= 0)
{
n_skip = 0;
break;
@@ -989,7 +995,8 @@ skip (off_t n_skip)
}
}
- /* fseek didn't work or wasn't attempted; do it the slow way. */
+ /* Seek didn't work or wasn't attempted; position the file pointer
+ by reading. */
for (j = n_skip / BUFSIZ; j >= 0; j--)
{