btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / message.cpp
blob09cead58a15800e469d7bde17506d9265e852756
1 /*
2 * Copyright 2009, Michael Lotz, mmlr@mlotz.ch.
3 * Distributed under the terms of the MIT License.
4 */
6 #include <File.h>
7 #include <Message.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
14 int
15 main(int argc, char *argv[])
17 if (argc < 2 || argc > 3) {
18 printf("usage: %s <flattened message file> [index]\n", argv[0]);
19 return 1;
22 BFile input(argv[1], B_READ_ONLY);
23 if (!input.IsReadable()) {
24 printf("cannot open \"%s\" for reading\n", argv[1]);
25 return 2;
28 off_t fileSize;
29 status_t result;
30 if ((result = input.GetSize(&fileSize)) != B_OK) {
31 printf("cannot determine size of file \"%s\"\n", argv[1]);
32 return 3;
35 int index = argc > 2 ? atoi(argv[2]) : 0;
37 for (int i = 1; input.Position() < fileSize; ++i) {
38 BMessage message;
39 result = message.Unflatten(&input);
40 if (result != B_OK) {
41 printf("failed to unflatten message: %s\n", strerror(result));
42 return 4;
44 if (index == 0 || i == index)
45 message.PrintToStream();
48 return 0;