summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-10-07 05:13:59 +0000
committerJim Meyering <jim@meyering.net>2002-10-07 05:13:59 +0000
commitea544336d732ac8f781d3e7c922f5060903e4c62 (patch)
treed14166d62d8370aafb672b59ca41dafd38b7c422 /src
parenta05880e42ba2f74bc10dea2748b301b026ec5a5f (diff)
downloadcoreutils-ea544336d732ac8f781d3e7c922f5060903e4c62.tar.xz
(head_bytes, head_lines): Adapt to new safe_read ABI.
Diffstat (limited to 'src')
-rw-r--r--src/head.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/head.c b/src/head.c
index 540d601c4..0c972e283 100644
--- a/src/head.c
+++ b/src/head.c
@@ -130,7 +130,6 @@ static int
head_bytes (const char *filename, int fd, uintmax_t bytes_to_write)
{
char buffer[BUFSIZE];
- int bytes_read;
size_t bytes_to_read = BUFSIZE;
/* Need BINARY I/O for the byte counts to be accurate. */
@@ -138,10 +137,11 @@ head_bytes (const char *filename, int fd, uintmax_t bytes_to_write)
while (bytes_to_write)
{
+ size_t bytes_read;
if (bytes_to_write < bytes_to_read)
bytes_to_read = bytes_to_write;
bytes_read = safe_read (fd, buffer, bytes_to_read);
- if (bytes_read < 0)
+ if (bytes_read == SAFE_READ_ERROR)
{
error (0, errno, "%s", filename);
return 1;
@@ -165,10 +165,10 @@ head_lines (const char *filename, int fd, uintmax_t lines_to_write)
while (lines_to_write)
{
- int bytes_read = safe_read (fd, buffer, BUFSIZE);
- int bytes_to_write = 0;
+ size_t bytes_read = safe_read (fd, buffer, BUFSIZE);
+ size_t bytes_to_write = 0;
- if (bytes_read < 0)
+ if (bytes_read == SAFE_READ_ERROR)
{
error (0, errno, "%s", filename);
return 1;
@@ -178,10 +178,11 @@ head_lines (const char *filename, int fd, uintmax_t lines_to_write)
while (bytes_to_write < bytes_read)
if (buffer[bytes_to_write++] == '\n' && --lines_to_write == 0)
{
+ off_t n_bytes_past_EOL = bytes_read - bytes_to_write;
/* If we have read more data than that on the specified number
of lines, try to seek back to the position we would have
gotten to had we been reading one byte at a time. */
- if (lseek (fd, bytes_to_write - bytes_read, SEEK_CUR) < 0)
+ if (lseek (fd, -n_bytes_past_EOL, SEEK_CUR) < 0)
{
int e = errno;
struct stat st;