[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
read bug in head util
From: |
Wolfram Kleff |
Subject: |
read bug in head util |
Date: |
Sat, 22 Sep 2001 22:55:40 +0200 |
Package: textutils
Version: 2.0-9
Hello,
there is a little nasty bug in the "head" util.
It always tries to read complete blocks in function head_bytes.
This is no problem (except performance loss) for regular files, but leads to
problems in special files.
Here is a patch which should fix this problem:
--- head.c.orig Sat Sep 22 22:36:45 2001
+++ head.c Sat Sep 22 22:36:45 2001
@@ -125,7 +125,10 @@
while (bytes_to_write)
{
- bytes_read = safe_read (fd, buffer, BUFSIZE);
+ if (bytes_to_write < BUFSIZE)
+ bytes_read = safe_read (fd, buffer, bytes_to_write);
+ else
+ bytes_read = safe_read (fd, buffer, BUFSIZE);
if (bytes_read < 0)
{
error (0, errno, "%s", filename);
@@ -133,8 +136,6 @@
}
if (bytes_read == 0)
break;
- if (bytes_read > bytes_to_write)
- bytes_read = bytes_to_write;
if (fwrite (buffer, 1, bytes_read, stdout) == 0)
error (EXIT_FAILURE, errno, _("write error"));
bytes_to_write -= bytes_read;
- read bug in head util,
Wolfram Kleff <=