GNU bug report logs - #18621
[BUG] wc -c incorrectly counts bytes in /sys

Previous Next

Package: coreutils;

Reported by: George Shuklin <george.shuklin <at> gmail.com>

Date: Fri, 3 Oct 2014 15:13:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: George Shuklin <george.shuklin <at> gmail.com>
To: 18621 <at> debbugs.gnu.org
Subject: bug#18621: [BUG] wc -c incorrectly counts bytes in /sys
Date: Fri, 03 Oct 2014 17:47:19 +0300
There is many sysfs (linux) attributes which reported as '4k files' but 
contains just a few bytes.

wc file and wc -c shows different sizes.

Example:

$cat /sys/kernel/vmcoreinfo
1b74c00 1024

$hexdump -Cv /sys/kernel/vmcoreinfo
00000000  31 62 37 34 63 30 30 20  31 30 32 34 0a           |1b74c00 1024.|
0000000d

$ls -la /sys/kernel/vmcoreinfo
-r--r--r-- 1 root root 4096 Oct  3 17:40 /sys/kernel/vmcoreinfo


Here wc output:

$ wc /sys/kernel/vmcoreinfo
   1    2   13 /sys/kernel/vmcoreinfo

and wc -c:

$ wc -c /sys/kernel/vmcoreinfo
4096 /sys/kernel/vmcoreinfo

4096 is not 13, and manual page for wc says that third number is byte count.

I think problem is in  cnt(const char *file)  function:

	if (dochar || domulti) {
		if (fstat(fd, &sb)) {
			warn("%s: fstat", file);
			(void)close(fd);
			return (1);
		}
		if (S_ISREG(sb.st_mode)) {
			(void)printf(" %7lld", (long long)sb.st_size);
			tcharct += sb.st_size;
			(void)close(fd);
			return (0);
		}
	}






This bug report was last modified 10 years and 289 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.