CFLAGS="-O3 -mbmi -m32 -Werror" $(MAKE) -C $(PRGDIR) test
staticAnalyze: clean
- CPPFLAGS=-g scan-build --status-bugs -v $(MAKE) all
+ CPPFLAGS=-g scan-build --status-bugs -v $(MAKE) all
endif
--- /dev/null
+#build
+simple_compression
+simple_decompression
+dictionary_decompression
+
+#test artefact
+tmp*
+test*
+*.zst
--- /dev/null
+# ##########################################################################
+# ZSTD educational examples - Makefile
+# Copyright (C) Yann Collet 2016
+#
+# GPL v2 License
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# You can contact the author at :
+# - zstd homepage : http://www.zstd.net/
+# ##########################################################################
+
+# This Makefile presumes libzstd is installed, using `sudo make install`
+
+LDFLAGS+= -lzstd
+
+.PHONY: default all clean test
+
+default: all
+
+all: simple_compression simple_decompression dictionary_decompression
+
+simple_compression : simple_compression.c
+ $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@
+
+simple_decompression : simple_decompression.c
+ $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@
+
+dictionary_decompression : dictionary_decompression.c
+ $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@
+
+clean:
+ @rm -f core *.o tmp* result* *.zst \
+ simple_compression simple_decompression dictionary_decompression
+ @echo Cleaning completed
+
+test: all
+ cp README.md tmp
+ ./simple_compression tmp
+ @echo starting simple_decompression
+ ./simple_decompression tmp.zst
+ @echo tests completed
}
-static void compress(const char* fname)
+static void saveFile_X(const char* fileName, const void* buff, size_t buffSize)
+{
+ FILE* const oFile = fopen_X(fileName, "wb");
+ size_t const wSize = fwrite(buff, 1, buffSize, oFile);
+ if (wSize != (size_t)buffSize) {
+ printf("fwrite: %s : %s \n", fileName, strerror(errno));
+ exit(5);
+ }
+ size_t const closeError = fclose(oFile);
+ if (closeError) {
+ printf("fclose: %s : %s \n", fileName, strerror(errno));
+ exit(6);
+ }
+}
+
+
+static void compress(const char* fname, const char* oname)
{
size_t fSize;
void* const fBuff = loadFile_X(fname, &fSize);
exit(7);
}
+ saveFile_X(oname, cBuff, cSize);
+
/* success */
- printf("%25s : %6u -> %7u \n", fname, (unsigned)fSize, (unsigned)cSize);
+ printf("%25s : %6u -> %7u - %s \n", fname, (unsigned)fSize, (unsigned)cSize, oname);
free(fBuff);
free(cBuff);
}
+static const char* createOutFilename(const char* filename)
+{
+ size_t const inL = strlen(filename);
+ size_t const outL = inL + 5;
+ void* outSpace = malloc_X(outL);
+ memset(outSpace, 0, outL);
+ strcat(outSpace, filename);
+ strcat(outSpace, ".zst");
+ return (const char*)outSpace;
+}
+
int main(int argc, const char** argv)
{
const char* const exeName = argv[0];
+ const char* const inFilename = argv[1];
if (argc!=2) {
printf("wrong arguments\n");
return 1;
}
- compress(argv[1]);
+ const char* const outFilename = createOutFilename(inFilename);
+ compress(inFilename, outFilename);
- printf("%s compressed. \n", argv[1]);
+ return 0;
}
decompress(argv[1]);
- printf("%s decoded. \n", argv[1]);
+ printf("%s correctly decoded (in memory). \n", argv[1]);
+
+ return 0;
}