LBX1 fallback requires files to be named like "archive.lbx.XXX", so we need
to keep track of "archive.lbx".
int lbx_errno = 0;
struct lbx_state {
int lbx_errno = 0;
struct lbx_state {
uint16_t nfiles;
uint32_t offsets[];
};
uint16_t nfiles;
uint32_t offsets[];
};
-struct lbx_state *lbx_fopen(FILE *f)
+struct lbx_state *lbx_fopen(FILE *f, const char *name)
{
struct lbx_state *new = NULL;
uint16_t nfiles, version;
{
struct lbx_state *new = NULL;
uint16_t nfiles, version;
}
*new = (struct lbx_state){
}
*new = (struct lbx_state){
+ .f = f,
+ .foff = sizeof nfiles + sizeof magic + sizeof version,
};
if (fread(new->offsets, sizeof *new->offsets, nfiles+1, f) != nfiles+1)
goto readerr;
};
if (fread(new->offsets, sizeof *new->offsets, nfiles+1, f) != nfiles+1)
goto readerr;
+ new->foff += sizeof *new->offsets * (nfiles+1);
FILE *f;
if ((f = fopen(path, "rb"))) {
FILE *f;
if ((f = fopen(path, "rb"))) {
+ const char *name = strrchr(path, '/');
+ new = lbx_fopen(f, name ? name+1 : path);
} else {
lbx_errno = -errno;
}
} else {
lbx_errno = -errno;
}
typedef struct lbx_state LBX;
/* File operations */
typedef struct lbx_state LBX;
/* File operations */
+LBX *lbx_fopen(FILE *, const char *);
LBX *lbx_open(const char *);
void lbx_close(LBX *);
size_t lbx_numfiles(LBX *);
LBX *lbx_open(const char *);
void lbx_close(LBX *);
size_t lbx_numfiles(LBX *);
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "lbx.h"
#include <getopt.h>
#include "lbx.h"
-int list(FILE *f, int verbose) {
- LBX *lbx = lbx_fopen(f);
+int list(FILE *f, const char *name, int verbose) {
+ LBX *lbx = lbx_fopen(f, name);
if (!lbx) {
errmsg("failed to open archive: %s.\n", lbx_strerror());
return EXIT_FAILURE;
if (!lbx) {
errmsg("failed to open archive: %s.\n", lbx_strerror());
return EXIT_FAILURE;
int main(int argc, char **argv)
{
int mode = MODE_NONE, verbose = 0;
int main(int argc, char **argv)
{
int mode = MODE_NONE, verbose = 0;
+ const char *name = "stdin";
FILE *f = stdin;
int opt;
FILE *f = stdin;
int opt;
- static const char *sopts = "lxf:v";
+ static const char *sopts = "lxf:i:v";
static const struct option lopts[] = {
{ "list", 0, NULL, 'l' },
{ "extract", 0, NULL, 'x' },
{ "file", 1, NULL, 'f' },
static const struct option lopts[] = {
{ "list", 0, NULL, 'l' },
{ "extract", 0, NULL, 'x' },
{ "file", 1, NULL, 'f' },
+ { "index", 1, NULL, 'i' },
{ "verbose", 0, NULL, 'v' },
{ "verbose", 0, NULL, 'v' },
mode = MODE_EXTRACT;
break;
case 'f':
mode = MODE_EXTRACT;
break;
case 'f':
+ if (strcmp(optarg, "-") == 0)
+ break;
+
+ name = strrchr(optarg, '/');
+ name = name ? name+1 : optarg;
+
f = fopen(optarg, "rb");
if (!f) {
errmsg("failed to open file %s: %m\n", optarg);
return EXIT_FAILURE;
}
break;
f = fopen(optarg, "rb");
if (!f) {
errmsg("failed to open file %s: %m\n", optarg);
return EXIT_FAILURE;
}
break;
+ case 'i':
+ /* FIXME: Add index file support. */
+ break;
case 'v':
verbose = 1;
break;
case 'v':
verbose = 1;
break;
switch (mode) {
case MODE_LIST:
switch (mode) {
case MODE_LIST:
- return list(f, verbose);
+ return list(f, name, verbose);
case MODE_EXTRACT:
return EXIT_SUCCESS;
}
case MODE_EXTRACT:
return EXIT_SUCCESS;
}