git.annexia.org
/
pxzcat.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Various fixes.
[pxzcat.git]
/
pxzcat.c
diff --git
a/pxzcat.c
b/pxzcat.c
index
5348be1
..
0ac0eb9
100644
(file)
--- a/
pxzcat.c
+++ b/
pxzcat.c
@@
-43,15
+43,16
@@
#include <sys/types.h>
#include <error.h>
#include <errno.h>
#include <sys/types.h>
#include <error.h>
#include <errno.h>
+#include <getopt.h>
#include <lzma.h>
#define DEBUG 1
#if DEBUG
#include <lzma.h>
#define DEBUG 1
#if DEBUG
-#define debug(fs
...) fprintf (stderr, "pxzcat: debug: " fs ##
__VA_ARGS__)
+#define debug(fs
,...) fprintf (stderr, "pxzcat: debug: " fs, ##
__VA_ARGS__)
#else
#else
-#define debug(fs...) /* nothing */
+#define debug(fs
,
...) /* nothing */
#endif
#define XZ_HEADER_MAGIC "\xfd" "7zXZ\0"
#endif
#define XZ_HEADER_MAGIC "\xfd" "7zXZ\0"
@@
-59,13
+60,15
@@
#define XZ_FOOTER_MAGIC "YZ"
#define XZ_FOOTER_MAGIC_LEN 2
#define XZ_FOOTER_MAGIC "YZ"
#define XZ_FOOTER_MAGIC_LEN 2
+static void usage (int exitcode);
static void xzfile_uncompress (const char *filename, const char *outputfile);
static int check_header_magic (int fd);
static void xzfile_uncompress (const char *filename, const char *outputfile);
static int check_header_magic (int fd);
-static lzma_index *parse_indexes (const char *filename, int fd
, size_t *
);
+static lzma_index *parse_indexes (const char *filename, int fd);
static void iter_indexes (lzma_index *idx);
static struct option long_options[] = {
{ "output", required_argument, 0, 'o' },
static void iter_indexes (lzma_index *idx);
static struct option long_options[] = {
{ "output", required_argument, 0, 'o' },
+ { "help", 0, 0, '?' },
{ NULL, 0, 0, 0 }
};
{ NULL, 0, 0, 0 }
};
@@
-75,11
+78,11
@@
int
main (int argc, char *argv[])
{
int c;
main (int argc, char *argv[])
{
int c;
- int
optind
;
+ int
longopt_index
;
const char *outputfile = NULL;
for (;;) {
const char *outputfile = NULL;
for (;;) {
- c = getopt_long (argc, argv, options, long_options, &
optind
);
+ c = getopt_long (argc, argv, options, long_options, &
longopt_index
);
if (c == -1)
break;
if (c == -1)
break;
@@
-93,17
+96,18
@@
main (int argc, char *argv[])
break;
case '?':
break;
case '?':
+ usage (EXIT_SUCCESS);
+
default:
default:
-
error (EXIT_FAILURE, 0, "usage: %s -o output file\n", argv[0]
);
+
usage (EXIT_FAILURE
);
}
}
if (outputfile == NULL)
}
}
if (outputfile == NULL)
- error (EXIT_FAILURE, 0, "%s: you must give the -o (output file) option\n",
- argv[0]);
+ error (EXIT_FAILURE, 0, "you must give the -o (output file) option\n");
if (optind != argc - 1)
if (optind != argc - 1)
-
error (EXIT_FAILURE, 0, "%s: input.xz\n", argv[0]
);
+
usage (EXIT_FAILURE
);
xzfile_uncompress (argv[optind], outputfile);
xzfile_uncompress (argv[optind], outputfile);
@@
-111,6
+115,13
@@
main (int argc, char *argv[])
}
static void
}
static void
+usage (int exitcode)
+{
+ printf ("usage: pxzcat -o output input.xz\n");
+ exit (exitcode);
+}
+
+static void
xzfile_uncompress (const char *filename, const char *outputfile)
{
int fd;
xzfile_uncompress (const char *filename, const char *outputfile)
{
int fd;
@@
-118,7
+129,7
@@
xzfile_uncompress (const char *filename, const char *outputfile)
lzma_index *idx;
/* Open the file. */
lzma_index *idx;
/* Open the file. */
- fd = open (filename, O_RDONLY
|O_CLOEXEC
);
+ fd = open (filename, O_RDONLY);
if (fd == -1)
error (EXIT_FAILURE, errno, "open: %s", filename);
if (fd == -1)
error (EXIT_FAILURE, errno, "open: %s", filename);
@@
-246,7
+257,7
@@
parse_indexes (const char *filename, int fd)
r = lzma_code (&strm, LZMA_RUN);
} while (r == LZMA_OK);
r = lzma_code (&strm, LZMA_RUN);
} while (r == LZMA_OK);
- if (r != LZMA_STREAM_END)
{
+ if (r != LZMA_STREAM_END)
error (EXIT_FAILURE, 0, "%s: could not parse index (error %d)",
filename, r);
error (EXIT_FAILURE, 0, "%s: could not parse index (error %d)",
filename, r);
@@
-319,8
+330,6
@@
iter_indexes (lzma_index *idx)
}
}
-
- return 0;
}
#if 0
}
#if 0