summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile3
-rw-r--r--examples/example.c44
2 files changed, 47 insertions, 0 deletions
diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644
index 00000000..59007930
--- /dev/null
+++ b/examples/Makefile
@@ -0,0 +1,3 @@
+CFLAGS = -I../src -O0 -g -Wall
+LDFLAGS = -L../target/debug -lsequoia
+all: example
diff --git a/examples/example.c b/examples/example.c
new file mode 100644
index 00000000..ae727b43
--- /dev/null
+++ b/examples/example.c
@@ -0,0 +1,44 @@
+#define _GNU_SOURCE
+#include <error.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sequoia.h>
+
+int
+main (int argc, char **argv)
+{
+ struct stat st;
+ int fd;
+ char *b;
+ struct sq_tpk *tpk;
+
+ if (argc != 2)
+ error (1, 0, "Usage: %s <file>", argv[0]);
+
+ if (stat (argv[1], &st))
+ error (1, errno, "%s", argv[1]);
+
+ fd = open (argv[1], O_RDONLY);
+ if (fd == -1)
+ error (1, errno, "%s", argv[1]);
+
+ b = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (b == MAP_FAILED)
+ error (1, errno, "mmap");
+
+ tpk = sq_tpk_from_bytes (b, st.st_size);
+ if (tpk == NULL)
+ error (1, 0, "sq_tpk_from_bytes failed");
+
+ sq_tpk_dump (tpk);
+ sq_tpk_free (tpk);
+ munmap (b, st.st_size);
+ close (fd);
+ return 0;
+}