coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] wc: fix reading of /proc files on aarch64


From: Pádraig Brady
Subject: [PATCH] wc: fix reading of /proc files on aarch64
Date: Wed, 1 Jul 2015 22:44:20 +0100

tests/misc/wc-proc.sh fails when the page size is 64K

* src/wc.c (wc): The lseek adjustment should be based on st_blksize,
rather than on the internal buffer size.  This is significant on
aarch64 where st_blksize in /proc is the 64K (the page size) and
thus larger than the internal buffer.
* src/split.c (main): Even though the similar processing is done
on the internal buffer size, that's based on st_blksize and
so fine in this regard.  Add an assert to enforce this.
---
 src/split.c | 1 +
 src/wc.c    | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/split.c b/src/split.c
index b6fe2dd..407c8b7 100644
--- a/src/split.c
+++ b/src/split.c
@@ -1507,6 +1507,7 @@ main (int argc, char **argv)
         {
           if (usable_st_size (&in_stat_buf))
             {
+              assert (in_blk_size >= ST_BLKSIZE (in_stat_buf));
               file_size = input_file_size (STDIN_FILENO, in_stat_buf.st_size,
                                            buf, in_blk_size);
               if (file_size < in_blk_size)
diff --git a/src/wc.c b/src/wc.c
index eb7b5b6..9fbaee7 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -36,6 +36,7 @@
 #include "quotearg.h"
 #include "readtokens0.h"
 #include "safe-read.h"
+#include "stat-size.h"
 #include "xfreopen.h"
 
 #if !defined iswspace && !HAVE_ISWSPACE
@@ -238,14 +239,14 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, 
off_t current_pos)
       if (0 < fstatus->failed)
         fstatus->failed = fstat (fd, &fstatus->st);
 
-      /* For sized files, seek to one buffer before EOF rather than to EOF.
+      /* For sized files, seek to one st_blksize before EOF rather than to EOF.
          This works better for files in proc-like file systems where
          the size is only approximate.  */
       if (! fstatus->failed && usable_st_size (&fstatus->st)
           && 0 <= fstatus->st.st_size)
         {
           size_t end_pos = fstatus->st.st_size;
-          off_t hi_pos = end_pos - end_pos % BUFFER_SIZE;
+          off_t hi_pos = end_pos - end_pos % (ST_BLKSIZE (fstatus->st) + 1);
           if (current_pos < 0)
             current_pos = lseek (fd, 0, SEEK_CUR);
           if (0 <= current_pos && current_pos < hi_pos
-- 
2.4.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]