summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakayuki MATSUOKA <takayuki.matsuoka@gmail.com>2015-02-12 12:00:50 (GMT)
committerTakayuki MATSUOKA <takayuki.matsuoka@gmail.com>2015-03-02 04:38:28 (GMT)
commiteed7952101fbb740018cd00d7d2958d192da8344 (patch)
tree5411234677212c230e703f9141129f23f7e981ed
parentb372f45093aa8d86f7a99b7dd5e2deaeffb10033 (diff)
downloadlz4-eed7952101fbb740018cd00d7d2958d192da8344.zip
lz4-eed7952101fbb740018cd00d7d2958d192da8344.tar.gz
lz4-eed7952101fbb740018cd00d7d2958d192da8344.tar.bz2
Add GNU coreutil's is_nul() method to isSparse()
See original source http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/system.h
-rw-r--r--programs/lz4io.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/programs/lz4io.c b/programs/lz4io.c
index c69275d..7315d69 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -255,10 +255,24 @@ static int isSparse(const void* p, size_t size)
}
return 1;
-#else
+#elif 0
/* Neil's */
const char* buf = (const char*) p;
return buf[0] == 0 && !memcmp(buf, buf + 1, size - 1);
+#else
+ /* GNU Core Utilities : coreutils/src/system.h / is_nul() */
+ const U64* wp = (const U64*) p;
+ const char* cbuf = (const char*) p;
+ const char* cp;
+
+ // Find first nonzero *word*, or the word with the sentinel.
+ while(*wp++ == 0) ;
+
+ // Find the first nonzero *byte*, or the sentinel.
+ cp = (const char*) (wp - 1);
+ while(*cp++ == 0) ;
+
+ return cbuf + size < cp;
#endif
}
#endif /* LZ4IO_ENABLE_SPARSE_FILE */
@@ -652,7 +666,12 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput)
outBuffSize = LZ4IO_setBlockSizeID(frameInfo.blockSizeID);
inBuffSize = outBuffSize + 4;
inBuff = (char*)malloc(inBuffSize);
+#if defined(LZ4IO_ENABLE_SPARSE_FILE)
+ outBuff = (char*)malloc(outBuffSize+1);
+ outBuff[outBuffSize] = 1; /* sentinel */
+#else /* LZ4IO_ENABLE_SPARSE_FILE */
outBuff = (char*)malloc(outBuffSize);
+#endif /* LZ4IO_ENABLE_SPARSE_FILE */
if (!inBuff || !outBuff) EXM_THROW(65, "Allocation error : not enough memory");
/* Main Loop */