[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: How high can wc go?
On 06/17/10 10:14, Ray Phillips wrote:
The other day on a NetBSD/i386 5.0.2 machine I made a 1833 GiB file
consisting of 30752636928 64-character lines (including the new line
char). Later I ran wc on it, expecting its output to be incorrect as a
result of overflows in the variables it uses, but the answers were right:
% ls -l /mnt2
-rw-r--r-- 1 root wheel 1968168763392 Jun 14 08:28 1833GiB.txt
% /usr/bin/time wc /mnt/1833GiB.txt
30752636928 30752636928 1968168763392 /mnt2/1833GiB.txt
125997.76 real 121238.03 user 3731.70 sys
1833 2 30^ * 64 /p
30752636928 64 * p
I was wondering if anyone knows how many lines, words, and characters wc
can keep track of? It seems that it uses some kind of tricky technique
like dc to avoid overflows occurring?
If you look in src/usr.bin/wc/wc.c this contains the wc_count_t typedef
typedef u_long wc_count_t;
# define WCFMT " %7lu"
# define WCCAST unsigned long
typedef u_quad_t wc_count_t;
# define WCFMT " %7llu"
# define WCCAST unsigned long long
And this shows that it will support either a 64bit counter or a 32bit
counter. This in a typical case you will notice a wrap when you count
more than 2^64 characters.
>>> print 2**64
Or this amount in byte.
Main Index |
Thread Index |