diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cli.c | 10 | ||||
| -rw-r--r-- | src/cli.h | 2 | ||||
| -rw-r--r-- | src/compress.c | 2 | ||||
| -rw-r--r-- | src/encoding.c | 2 | ||||
| -rw-r--r-- | src/header.c | 29 |
5 files changed, 24 insertions, 21 deletions
@@ -33,8 +33,8 @@ static void parse_output_path(const char *optarg, struct params *p) { p->out = malloc(p->out_len + 2); strcpy(p->out, optarg); if (p->out[p->out_len - 1] != '/') { - p->out[p->out_len] = '/'; - p->out_len += 1; + p->out[p->out_len] = '/'; + p->out_len += 1; } } @@ -55,6 +55,12 @@ static void parse_game_id(const char *optarg, struct params *p) { /* Returns a params structure parsed from `argv`. */ struct params parse_args(int argc, char **argv) { + /* getopt maintains external state which needs to be reset each time + `parse_args` is called, otherwise strange things will occur. */ + optind = 1; + opterr = 1; + optopt = 63; + struct params p = {0}; if (argc < 2) { @@ -34,8 +34,8 @@ enum { /* Structure for storing options set from the command-line. */ struct params { bool verbose; /* Whether or not to output progress messages. */ - char *out; /* Path to extract files to. */ size_t out_len; /* Length of the output path string. */ + char *out; /* Path to extract files to. */ int mode; /* Current mode of operation. */ int game; /* Which encryption keys to use. */ int vararg_index; /* Start index of paths in argv. */ diff --git a/src/compress.c b/src/compress.c index f9fa8ff..578441b 100644 --- a/src/compress.c +++ b/src/compress.c @@ -43,7 +43,7 @@ struct stream *stream_inflate(struct stream *s, size_t len, strm.next_in = (Bytef *) s->_cur; do { strm.avail_out = decompressed_len; - strm.next_out = (Bytef *) n->_cur; + strm.next_out = (Bytef *) n->_cur; ret = inflate(&strm, Z_NO_FLUSH); if (ret == Z_STREAM_ERROR) { stream_free(n); diff --git a/src/encoding.c b/src/encoding.c index 23d38dc..e7af310 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -22,7 +22,7 @@ /* Wrapper for iconv, using the conversion specified by `conv`. */ static void convert(char *in_buf, char *out_buf, size_t len, iconv_t conv) { - size_t in_size = len, out_size = len; + size_t in_size = len, out_size = len; char *in_start = in_buf, *out_start = out_buf; iconv(conv, &in_start, &in_size, &out_start, &out_size); } diff --git a/src/header.c b/src/header.c index 6389817..82a181c 100644 --- a/src/header.c +++ b/src/header.c @@ -24,8 +24,18 @@ #include "header.h" #include "io.h" -static bool is_xp3(struct header *h); -static bool is_supported(struct header *h); + +/* Checks that the header contains the correct magic number. */ +static bool is_xp3(struct header *h) { + return !memcmp(h->magic, XP3_MAGIC, 11); +} + + +/* Checks that the archive's version is supported, and that it is marked + as compatible with the KiriKiriZ engine. */ +static bool is_supported(struct header *h) { + return h->version == 1 && h->flags & 0x80; +} /* Reads from the given stream into a newly allocated header structure. @@ -36,7 +46,7 @@ struct header *read_header(struct stream *s) { if (h == NULL) return NULL; /* The header structure can't be read into directly because of - potential alignment issues. */ + alignment issues. */ stream_read(h->magic, s, 11); stream_read(&h->info_offset, s, sizeof(uint64_t)); stream_read(&h->version, s, sizeof(uint32_t)); @@ -50,16 +60,3 @@ struct header *read_header(struct stream *s) { } return h; } - - -/* Checks that the header contains the correct magic number. */ -static bool is_xp3(struct header *h) { - return !memcmp(h->magic, XP3_MAGIC, 11); -} - - -/* Checks that the archive's version is supported, and that it is marked - as compatible with the KiriKiriZ engine. */ -static bool is_supported(struct header *h) { - return h->version == 1 && h->flags & 0x80; -} |