diff --git a/bgrep.c b/bgrep.c index 34149c7..98e93a8 100644 --- a/bgrep.c +++ b/bgrep.c @@ -1,4 +1,6 @@ // Copyright 2009 Felix Domke . All rights reserved. +// Copyright 2014 Jirka Hladky . +// Added support for large files (previously 4GB, now 2^64 bytes, 16EiB Exbibytes) // // Redistribution and use in source and binary forms, with or without modification, are // permitted provided that the following conditions are met: @@ -24,6 +26,9 @@ // authors and should not be interpreted as representing official policies, either expressed // or implied, of the copyright holder. // +/* +gcc -Wall -Wextra -O2 -o bgrep bgrep.c +*/ #include #include @@ -33,8 +38,9 @@ #include #include #include +#include -#define BGREP_VERSION "0.2" +#define BGREP_VERSION "0.3" int ascii2hex(char c) { @@ -56,7 +62,7 @@ int ascii2hex(char c) void searchfile(const char *filename, int fd, const unsigned char *value, const unsigned char *mask, int len) { - off_t offset = 0; + uint64_t offset = 0; unsigned char buf[1024]; len--; @@ -75,15 +81,16 @@ void searchfile(const char *filename, int fd, const unsigned char *value, const } else if (!r) return; - int o, i; - for (o = offset ? 0 : len; o < r; ++o) + int i; + uint64_t o; + for (o = offset ? 0 : len; o < (unsigned) r; ++o) { for (i = 0; i <= len; ++i) if ((buf[o + i] & mask[i]) != value[i]) break; if (i > len) { - printf("%s: %08llx\n", filename, (unsigned long long)(offset + o - len)); + printf("%s: %016" PRIx64 "\n", filename, (uint64_t)(offset + o - len)); } } diff --git a/test/bgrep-random.py b/test/bgrep-random.py index f59d3a0..7a12a4a 100644 --- a/test/bgrep-random.py +++ b/test/bgrep-random.py @@ -20,7 +20,7 @@ def test_bgrep(datalen, searchlen): bgrep_res = subprocess.Popen([BGREP, search.encode('hex'), filename], stdout=subprocess.PIPE).communicate()[0] - expected_res = ''.join(["%s: %08x\n" % (filename, i) for i in results]) + expected_res = ''.join(["%s: %016x\n" % (filename, i) for i in results]) if bgrep_res != expected_res: print "search: %s" % search.encode('hex') diff --git a/test/bgrep-test.sh b/test/bgrep-test.sh index 25a5bd8..f0c2522 100755 --- a/test/bgrep-test.sh +++ b/test/bgrep-test.sh @@ -19,7 +19,7 @@ if [ $PREPARE -eq 1 ]; then for index in `seq 0 1025`;do fileIndex=`printf "%04i" ${index}` perl -e 'print "A"x'"${index}"';print "BBBC";print "A"x20;' > /tmp/bgrepTest${fileIndex}.txt - printf "%08x\n" ${index} >> /tmp/bgrepExpectedResult.txt + printf "%016x\n" ${index} >> /tmp/bgrepExpectedResult.txt done # @@ -28,7 +28,7 @@ if [ $PREPARE -eq 1 ]; then # for index in `seq 1020 1025`;do perl -e 'print "A"x'"${index}"';print "BBB"' > /tmp/bgrepTestSpecial${index}.txt - printf "%08x\n" ${index} >> /tmp/bgrepExpectedResult.txt + printf "%016x\n" ${index} >> /tmp/bgrepExpectedResult.txt done fi