summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-08-17 15:06:18 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-08-17 15:06:18 +0000
commita91e9498a8be9e26f393cb33f8c1d9ed5e77ff40 (patch)
tree376ee5e596596ce892fc25e1fb091a1ea4c16ef7
parentf7cd08def642d709705b252a48ec1bf784f01ef1 (diff)
downloadmana-a91e9498a8be9e26f393cb33f8c1d9ed5e77ff40.tar.gz
mana-a91e9498a8be9e26f393cb33f8c1d9ed5e77ff40.tar.bz2
mana-a91e9498a8be9e26f393cb33f8c1d9ed5e77ff40.tar.xz
mana-a91e9498a8be9e26f393cb33f8c1d9ed5e77ff40.zip
Added a small program for calculating adler32 checksums of files.
-rw-r--r--ChangeLog7
-rw-r--r--tools/adler32.c67
2 files changed, 73 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a996393e..d5059fdb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-2007-08-15 Philipp Sehmisch <tmw@crushnet.org>
+2007-08-17 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * tools/adler32.c: Added little program for calculating adler32
+ checksums of files.
+
+2007-08-15 Philipp Sehmisch <tmw@crushnet.org>
* data/graphics/sprites/npcs.png, data/graphics/sprites/npc.xml:
Added farmer NPC for woodland village.
diff --git a/tools/adler32.c b/tools/adler32.c
new file mode 100644
index 00000000..4e851713
--- /dev/null
+++ b/tools/adler32.c
@@ -0,0 +1,67 @@
+/*
+ * adler32.c (c) 2006 Bjorn Lindeijer
+ * License: GPL, v2 or later
+ *
+ * Calculates Adler-32 checksums for all files passed as argument.
+ *
+ * Usage: adler32 [file]...
+ */
+
+#include <stdio.h>
+#include <zlib.h>
+
+/**
+ * Calculates the Adler-32 checksum for the given file.
+ */
+unsigned long fadler32(FILE *file)
+{
+ // Obtain file size
+ fseek(file, 0, SEEK_END);
+ long fileSize = ftell(file);
+ rewind(file);
+
+ // Calculate Adler-32 checksum
+ char *buffer = (char*) malloc(fileSize);
+ fread(buffer, 1, fileSize, file);
+ unsigned long adler = adler32(0L, Z_NULL, 0);
+ adler = adler32(adler, (Bytef*) buffer, fileSize);
+ free(buffer);
+
+ return adler;
+}
+
+/**
+ * Prints out usage and exists.
+ */
+void print_usage()
+{
+ printf("Usage: adler32 [file]...\n");
+ exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+ int i; /**< Loops through arguments. */
+
+ if (argc == 1)
+ {
+ print_usage();
+ }
+
+ for (i = 1; i < argc; ++i)
+ {
+ FILE *file = fopen(argv[i], "r");
+
+ if (!file)
+ {
+ printf("Error while opening '%s' for reading!\n", argv[i]);
+ exit(1);
+ }
+
+ unsigned long adler = fadler32(file);
+ printf("%s %lx\n", argv[i], adler);
+ fclose(file);
+ }
+
+ return 0;
+}