summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhalex <halex@openbsd.org>2014-02-05 20:35:42 +0000
committerhalex <halex@openbsd.org>2014-02-05 20:35:42 +0000
commite1fb501da5b2060200cf708af9ac38fb8f4e981d (patch)
treefcb850d0acebc8e617eaf6a6d5bcad7837b4945d
parentcheck return values in libfuse. (diff)
downloadwireguard-openbsd-e1fb501da5b2060200cf708af9ac38fb8f4e981d.tar.xz
wireguard-openbsd-e1fb501da5b2060200cf708af9ac38fb8f4e981d.zip
make pax cope with a stripped down format list, e.g. when compiled
with -DNOCPIO - ignore empty entries (millert@, halex@) - replace bsort with linear scan (guenther@) ok millert@ guenther@
-rw-r--r--bin/pax/ar_subs.c7
-rw-r--r--bin/pax/options.c43
2 files changed, 21 insertions, 29 deletions
diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c
index 19dd7015ed9..bbefbe94398 100644
--- a/bin/pax/ar_subs.c
+++ b/bin/pax/ar_subs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar_subs.c,v 1.37 2014/01/30 13:30:11 espie Exp $ */
+/* $OpenBSD: ar_subs.c,v 1.38 2014/02/05 20:35:42 halex Exp $ */
/* $NetBSD: ar_subs.c,v 1.5 1995/03/21 09:07:06 cgd Exp $ */
/*-
@@ -1159,7 +1159,7 @@ get_arc(void)
* to read the archive.
*/
for (i = 0; ford[i] >= 0; ++i) {
- if (fsub[ford[i]].hsz < minhd)
+ if (fsub[ford[i]].name != NULL && fsub[ford[i]].hsz < minhd)
minhd = fsub[ford[i]].hsz;
}
if (rd_start() < 0)
@@ -1210,7 +1210,8 @@ get_arc(void)
* important).
*/
for (i = 0; ford[i] >= 0; ++i) {
- if ((*fsub[ford[i]].id)(hdbuf, hdsz) < 0)
+ if (fsub[ford[i]].name == NULL ||
+ (*fsub[ford[i]].id)(hdbuf, hdsz) < 0)
continue;
frmt = &(fsub[ford[i]]);
/*
diff --git a/bin/pax/options.c b/bin/pax/options.c
index 074d8d9d643..80b81821b0c 100644
--- a/bin/pax/options.c
+++ b/bin/pax/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.82 2014/01/30 13:30:11 espie Exp $ */
+/* $OpenBSD: options.c,v 1.83 2014/02/05 20:35:42 halex Exp $ */
/* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */
/*-
@@ -61,7 +61,6 @@ static OPLIST *optail = NULL; /* option tail */
static int no_op(void);
static void printflg(unsigned int);
-static int c_frmt(const void *, const void *);
static off_t str_offt(char *);
static char *get_line(FILE *fp);
static void pax_options(int, char **);
@@ -82,7 +81,7 @@ static int getline_error;
#define BZIP2_CMD "bzip2" /* command to run as bzip2 */
/*
- * Format specific routine table - MUST BE IN SORTED ORDER BY NAME
+ * Format specific routine table
* (see pax.h for description of each function)
*
* name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
@@ -195,11 +194,10 @@ static void
pax_options(int argc, char **argv)
{
int c;
- int i;
+ unsigned i;
unsigned int flg = 0;
unsigned int bflg = 0;
char *pt;
- FSUB tmp;
/*
* process option flags
@@ -381,16 +379,20 @@ pax_options(int argc, char **argv)
/*
* specify an archive format on write
*/
- tmp.name = optarg;
- if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
- sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL) {
+ for (i = 0; i < sizeof(fsub)/sizeof(FSUB); ++i)
+ if (fsub[i].name != NULL &&
+ strcmp(fsub[i].name, optarg) == 0)
+ break;
+ if (i < sizeof(fsub)/sizeof(FSUB)) {
flg |= XF;
break;
}
paxwarn(1, "Unknown -x format: %s", optarg);
(void)fputs("pax: Known -x formats are:", stderr);
for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
- (void)fprintf(stderr, " %s", fsub[i].name);
+ if (fsub[i].name != NULL)
+ (void)fprintf(stderr, " %s",
+ fsub[i].name);
(void)fputs("\n\n", stderr);
pax_usage();
break;
@@ -1054,9 +1056,9 @@ mkpath(path)
static void
cpio_options(int argc, char **argv)
{
- int c, i;
+ int c;
+ unsigned i;
char *str;
- FSUB tmp;
FILE *fp;
kflag = 1;
@@ -1227,9 +1229,10 @@ cpio_options(int argc, char **argv)
/*
* specify an archive format on write
*/
- tmp.name = optarg;
- if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
- sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL)
+ for (i = 0; i < sizeof(fsub)/sizeof(FSUB); ++i)
+ if (fsub[i].name != NULL &&
+ strcmp(fsub[i].name, optarg) == 0)
+ if (i < sizeof(fsub)/sizeof(FSUB))
break;
paxwarn(1, "Unknown -H format: %s", optarg);
(void)fputs("cpio: Known -H formats are:", stderr);
@@ -1334,18 +1337,6 @@ printflg(unsigned int flg)
}
/*
- * c_frmt()
- * comparison routine used by bsearch to find the format specified
- * by the user
- */
-
-static int
-c_frmt(const void *a, const void *b)
-{
- return(strcmp(((FSUB *)a)->name, ((FSUB *)b)->name));
-}
-
-/*
* opt_next()
* called by format specific options routines to get each format specific
* flag and value specified with -o