aboutsummaryrefslogtreecommitdiffstats
path: root/g-ir-extract-deps.c
diff options
context:
space:
mode:
authorChristiaan Welvaart <cjw@mageia.org>2011-07-07 16:29:04 +0000
committerChristiaan Welvaart <cjw@mageia.org>2011-07-07 16:29:04 +0000
commit2b0222bf310ddfd221e18d0bae46e803c04db1d2 (patch)
tree31849aab2b50973f490dbbd9471e98a293530cfb /g-ir-extract-deps.c
parent61343fb5caf3dc815a8616cf912af1401ced05ec (diff)
downloadrpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.tar
rpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.tar.gz
rpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.tar.bz2
rpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.tar.xz
rpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.zip
- extract gobject introspection typelib interdependencies using a helper program1.137
Diffstat (limited to 'g-ir-extract-deps.c')
-rw-r--r--g-ir-extract-deps.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/g-ir-extract-deps.c b/g-ir-extract-deps.c
new file mode 100644
index 0000000..1c1735d
--- /dev/null
+++ b/g-ir-extract-deps.c
@@ -0,0 +1,68 @@
+/*
+ extract the dependencies string from a GObject Introspection 1.0 typelib file
+ and print it on stdout
+*/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#define G_IR_MAGIC "GOBJ\nMETADATA\r\n\032"
+
+int main(int argc, char ** argv)
+{
+ FILE * typelib;
+ char * magic;
+ uint32_t deps_offset;
+ char * deps;
+
+ if (argc < 2)
+ {
+ fprintf(stderr, "too few arguments\n");
+ exit(1);
+ }
+
+ typelib = fopen(argv[1], "r");
+ if (typelib == NULL)
+ {
+ fprintf(stderr, "failed to open %s\n", argv[1]);
+ exit(1);
+ }
+ magic = malloc(16);
+ deps = malloc(8192);
+ if ((magic == NULL) || (deps == NULL))
+ {
+ fprintf(stderr, "failed to allocate memory\n");
+ exit(1);
+ }
+ if (fread(magic, 16, 1, typelib) < 1)
+ {
+ fprintf(stderr, "failed to read magic from typelib\n");
+ exit(1);
+ }
+ if (strcmp(magic, G_IR_MAGIC))
+ {
+ fprintf(stderr, "magic mismatch, not a typelib?\n");
+ exit(1);
+ }
+
+ fseek(typelib, 36, SEEK_SET);
+ if (fread(&deps_offset, 4, 1, typelib) < 1)
+ {
+ fprintf(stderr, "failed to read deps offset from typelib\n");
+ exit(1);
+ }
+ fseek(typelib, deps_offset, SEEK_SET);
+ if (fscanf(typelib, "%8191s", deps) < 1)
+ {
+ fprintf(stderr, "failed to read deps from typelib\n");
+ exit(1);
+ }
+
+ free(deps);
+ free(magic);
+ fclose(typelib);
+
+ printf("%s\n", deps);
+ return 0;
+}