summaryrefslogtreecommitdiff
path: root/paxtest/paxtest.c
diff options
context:
space:
mode:
Diffstat (limited to 'paxtest/paxtest.c')
-rw-r--r--paxtest/paxtest.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/paxtest/paxtest.c b/paxtest/paxtest.c
new file mode 100644
index 0000000..47eb365
--- /dev/null
+++ b/paxtest/paxtest.c
@@ -0,0 +1,85 @@
+/* This file is part of GNU paxutils
+
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ Written by Sergey Poznyakoff
+
+ GNU paxutils is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GNU paxutils program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with GNU paxutils; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <paxtest.h>
+
+#ifndef DEFAULT_BLOCKING_FACTOR
+# define DEFAULT_BLOCKING_FACTOR 20
+#endif
+
+void
+xalloc_die (void)
+{
+ error(1, ENOMEM, "Exiting");
+}
+
+void
+dump (unsigned char *buf, size_t size)
+{
+ while (size)
+ {
+ int i;
+ for (i = 0; i < 16 && size; i++, size--, buf++)
+ printf ("%02X ", *buf);
+ printf ("\n");
+ }
+}
+
+
+void
+read_and_dump (paxbuf_t pbuf)
+{
+ union block block;
+ size_t size;
+ pax_io_status_t rc;
+
+ while ((rc = paxbuf_read (pbuf, block.buffer, sizeof block, &size))
+ == pax_io_success)
+ {
+ dump (block.buffer, size);
+ }
+ if (rc == pax_io_failure)
+ error (1, 0, "Read error");
+}
+
+int
+main (int argc, char **argv)
+{
+ paxbuf_t pbuf;
+ int rc;
+
+ if (argc == 1)
+ error (1, 0, "Not enough arguments");
+
+ tar_archive_create (&pbuf, argv[1], 0, PAXBUF_READ, DEFAULT_BLOCKING_FACTOR);
+
+ rc = paxbuf_open (pbuf);
+ printf ("Open: %d\n", rc);
+ if (rc)
+ abort ();
+ read_and_dump (pbuf);
+ paxbuf_close (pbuf);
+ paxbuf_destroy (&pbuf);
+ return 0;
+}