On Wed, Jul 15, 2009 at 11:51:41PM +0200, Jim Meyering wrote:
If it matters, we can come up with a more efficient (yet still
portable)
way to compare the last two bytes of each file to "\n\n".
I went ahead and wrote a nearly-minimal script to do that.
Rather than reading/processing all 27MB of sources,
this reads just the last 2 bytes of each of the 1048 files,
comparing those bytes to "\n\n" and printing the name when
there's a match:
I just strace'd the 'tail' program and that does the right
thing too
# strace tail -c 2 somefile
....
open("somefile", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0664, st_size=10600, ...}) = 0
_llseek(3, 0, [0], SEEK_CUR) = 0
_llseek(3, 0, [10600], SEEK_END) = 0
_llseek(3, -2, [10598], SEEK_END) = 0
read(3, "l\n"..., 2) = 2
git ls-files -z \
| xargs -0 perl -le '
foreach my $f (@ARGV) {
open F,"<",$f or (warn "failed to open $f: $!\n"), next;
my $p = sysseek(F, -2, 2);
# seek failure probably means file has < 2 bytes; ignore
my $two;
defined $p and $p = sysread F,$two,2;
close F;
# ignore read failure
$p && $two eq "\n\n" and (print $f),$fail=1;
} END {exit defined $fail ? 1 : 0}'
So using 'tail' instead of this perl script would be more readable
and efficient.
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|