2018년 5월 17일 목요일

How to build xdelta on Mac

$ git clone https://github.com/jmacd/xdelta.git
$ cd xdelta/xdelta3
$ automake --add-missing
$ autoreconfig
$ ./configure

diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index b9b6fe0..3d37a17 100644
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -167,8 +167,8 @@ typedef ULONGLONG      uint64_t;
 #define _FILE_OFFSET_BITS 64
 #endif
-static_assert(SIZEOF_SIZE_T == sizeof(size_t), "SIZEOF_SIZE_T not correctly set");
-static_assert(SIZEOF_UNSIGNED_LONG_LONG == sizeof(unsigned long long), "SIZEOF_UNSIGNED_LONG_LONG not correctly set");
+//static_assert(SIZEOF_SIZE_T == sizeof(size_t), "SIZEOF_SIZE_T not correctly set");
+//static_assert(SIZEOF_UNSIGNED_LONG_LONG == sizeof(unsigned long long), "SIZEOF_UNSIGNED_LONG_LONG not correctly set");
 /* Set a xoff_t typedef and the "Q" printf insert. */
 #if defined(_WIN32)

$ make

# Test

$ dd if=/dev/zero of=testfile bs=1048576 count=4000
$ cp testfile testfile2
$ python bitflip.py testfile2 10000
$ ./xdelta3 -e -s testfile testfile2 delta
$ ./xdelta3 -d -s testfile delta testfile3
$ diff testfile2 testfile3

bitflip.py


"""Toggle the bit at the specified offset.Syntax: <cmdname> filename bit-offset"""
import sysfname = sys.argv[1]# Convert bit offset to bytes + leftover bitsbitpos = int(sys.argv[2])nbytes, nbits = divmod(bitpos, 8)
# Open in read+write, binary mode; read 1 bytefp = open(fname, "r+b")fp.seek(nbytes, 0)c = fp.read(1)
# Toggle bit at byte position `nbits`toggled = bytes( [ ord(c)^(1<<nbits) ] )# print(toggled) # diagnostic output
# Back up one byte, write out the modified bytefp.seek(-1, 1)  # or absolute: fp.seek(nbytes, 0)fp.write(toggled)
fp.close()