#define RUN_MASK ((1U<<RUN_BITS)-1)
#define COMPUTE_STATS
-#define CHECKSUM_CHAR_OFFSET 2
+#define CHECKSUM_CHAR_OFFSET 0
//#define RUN_CHECKS
//#define LDM_DEBUG
}
}
-// TODO: srcSize and maxDstSize is unused
+// TODO: maxDstSize is unused. This function may seg fault when writing
+// beyond the size of dst, as it does not check maxDstSize. Writing to
+// a buffer and performing checks is a possible solution.
+//
// This is based upon lz4.
size_t LDM_compress(const void *src, size_t srcSize,
void *dst, size_t maxDstSize) {
-// TODO: file size must fit into a U32
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "ldm.h"
+#include "zstd.h"
#define DEBUG
//#define TEST
/* Compress file given by fname and output to oname.
* Returns 0 if successful, error code otherwise.
+ *
+ * TODO: This currently seg faults if the compressed size is > the decompress
+ * size due to the mmapping and output file size allocated to be the input size.
+ * The compress function should check before writing or buffer writes.
*/
static int compress(const char *fname, const char *oname) {
int fdin, fdout;
dst + LDM_HEADER_SIZE, statbuf.st_size);
#endif
*/
-
compressSize = LDM_HEADER_SIZE +
LDM_compress(src, statbuf.st_size,
- dst + LDM_HEADER_SIZE, statbuf.st_size);
+ dst + LDM_HEADER_SIZE, maxCompressSize);
// Write compress and decompress size to header
// TODO: should depend on LDM_DECOMPRESS_SIZE write32
return *(const U32 *)ptr;
}
-//TODO: endianness?
-void LDM_write64(void *memPtr, U64 value) {
- memcpy(memPtr, &value, sizeof(value));
-}
-
U64 LDM_read64(const void *ptr) {
return *(const U64 *)ptr;
}