]> git.ozlabs.org Git - ccan/blob - ccan/rfc822/examples/headernames.c
endian: add constant versions.
[ccan] / ccan / rfc822 / examples / headernames.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdarg.h>
4 #include <string.h>
5
6 #include <errno.h>
7 #include <unistd.h>
8
9 #include <ccan/talloc/talloc.h>
10 #include <ccan/grab_file/grab_file.h>
11 #include <ccan/rfc822/rfc822.h>
12
13 static void process_file(const char *name)
14 {
15         void *ctx = talloc_new(NULL);
16         size_t size;
17         void *buf;
18         struct rfc822_msg *msg;
19         struct rfc822_header *hdr;
20
21         buf = grab_file(ctx, name, &size);
22
23         msg = rfc822_start(ctx, buf, size);
24
25         rfc822_for_each_header(msg, hdr) {
26                 struct bytestring hname = rfc822_header_raw_name(msg, hdr);
27
28                 printf("%.*s\n", hname.len, hname.ptr);
29         }
30
31         talloc_free(ctx);
32 }
33
34 int main(int argc, char *argv[])
35 {
36         int i;
37
38         for (i = 0; i < (argc - 1); i++)
39                 process_file(argv[i + 1]);
40
41         exit(0);
42 }