allow for 32/64 bit builds
[tridge/junkcode.git] / ctdb_parser.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6
7 #define _STRING_LINE_(s)    #s
8 #define _STRING_LINE2_(s)   _STRING_LINE_(s)
9 #define __LINESTR__       _STRING_LINE2_(__LINE__)
10 #define __location__ __FILE__ ":" __LINESTR__
11
12 static void fatal(const char *msg)
13 {
14         printf("%s\n", msg);
15         exit(1);
16 }
17
18 int main(int argc, const char *argv[])
19 {
20         int fd;
21         unsigned len;
22         unsigned ofs=0;
23
24         fd = open(argv[1], O_RDONLY);
25         
26         while (read(fd, &len, sizeof(len)) == sizeof(len)) {
27                 unsigned char buf[len-4];
28                 ofs += 4;
29                 
30                 if (read(fd, buf, len-4) != (len-4)) {
31                         fatal(__location__);
32                 }
33                 ofs += len-4;
34                 printf("magic: %4.4s length=%u ofs=%u\n", buf, len, ofs);
35         }
36         
37         return 0;
38 }