Add a 'guard' size parameter to ringbuffer construction, remove hardcoded
[nobug.git] / src / nobug_rbdump.c
blob45d2920f4a1280ee33487dcf5f166beea40917f1
1 /*
2 This file is part of the NoBug debugging library.
4 Copyright (C)
5 2008, Simeon Voelkel <simeon_voelkel@arcor.de>
6 2008, 2009 Christian Thaeter <ct@pipapo.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, contact Christian Thaeter <ct@pipapo.org>.
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <unistd.h>
29 #define NOBUG_LIBNOBUG_C
30 #include "nobug.h"
33 //rbdump HEAD- Dumping Persistent Ringbuffers; rbdump; dumping persistent ringbuffers
34 //rbdump
35 //rbdump NoBug installs the `nobug_rbdump` tool for dumping the content of a persistent
36 //rbdump ringbuffer. It is invoked with the filename of the ringbuffer, the content is then
37 //rbdump printed to stdout.
38 //rbdump
40 int
41 main(int argc, char* argv[])
43 struct stat filestat;
45 if (argc < 2)
47 printf( "usage: %s file\n\n"
48 " nobug ringbuffer dump\n\n"
49 " Copyright (C)\n"
50 " 2008, Simeon Voelkel <simeon_voelkel@arcor.de>\n\n"
51 " This is free software. You may redistribute copies of it under the terms of\n"
52 " the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n"
53 " There is NO WARRANTY, to the extent permitted by law.\n\n",
54 argv[0]
56 return 1;
58 if (argv[1] != NULL)
60 if (stat(argv[1], &filestat))
62 fprintf (stderr, "Can't stat file %s\n", argv[1]);
63 return 2;
66 struct nobug_ringbuffer rb;
68 /* using the file size for the guard too is quite excessive but the only way to be 100% sure any ringbuffer can be read */
69 if (!nobug_ringbuffer_init (&rb, filestat.st_size, filestat.st_size, argv[1], NOBUG_RINGBUFFER_KEEP|NOBUG_RINGBUFFER_APPEND))
71 fprintf (stderr, "Error opening ringbuffer %s\n", argv[1]);
72 return 3;
75 nobug_ringbuffer_save (&rb, stdout);
78 return 0;