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