Module Name: othersrc
Committed By: agc
Date: Fri Jul 15 05:33:42 UTC 2011
Modified Files:
othersrc/external/bsd/mat/dist: frontends.c
othersrc/external/bsd/mat/libmat: Makefile
othersrc/external/bsd/mat/mat: Makefile
Log Message:
Use the getopt2(3) library to parse arguments in mat_tar() and mat_pax().
This protects the global getopt(3) arguments from modification by lower-level
routines in a destructive way.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/mat/dist/frontends.c
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/mat/libmat/Makefile
cvs rdiff -u -r1.4 -r1.5 othersrc/external/bsd/mat/mat/Makefile
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/external/bsd/mat/dist/frontends.c
diff -u othersrc/external/bsd/mat/dist/frontends.c:1.3 othersrc/external/bsd/mat/dist/frontends.c:1.4
--- othersrc/external/bsd/mat/dist/frontends.c:1.3 Sat Jun 25 17:05:34 2011
+++ othersrc/external/bsd/mat/dist/frontends.c Fri Jul 15 05:33:42 2011
@@ -31,6 +31,8 @@
#include <string.h>
#include <unistd.h>
+#include "getopt2.h"
+
#include "mat.h"
#ifndef TMPDIR
@@ -148,6 +150,7 @@
mat_tar(int argc, char **argv)
{
const char *action;
+ getopt2_t options;
mat_t mat;
char newarg[MAT_PATH_MAX + 256];
char temp[MAT_PATH_MAX];
@@ -170,13 +173,14 @@
(void) snprintf(newarg, sizeof(newarg), "-%s", argv[1]);
argv[1] = newarg;
}
- while ((i = getopt(argc, argv, "C:T:Vacf:ps:tvx")) != -1) {
+ getopt2_init(&options);
+ while ((i = getopt2(&options, argc, argv, "C:T:Vacf:ps:tvx")) != -1) {
switch(i) {
case 'C':
- dir = optarg;
+ dir = options.optarg;
break;
case 'T':
- metalog = optarg;
+ metalog = options.optarg;
break;
case 'V':
action = "verify";
@@ -188,13 +192,13 @@
action = "create";
break;
case 'f':
- f = optarg;
+ f = options.optarg;
break;
case 'p':
mat.preserve = 1;
break;
case 's':
- if (!compile_subst(&mat, optarg)) {
+ if (!compile_subst(&mat, options.optarg)) {
return 0;
}
break;
@@ -234,7 +238,7 @@
}
if (metalog) {
ok = read_metalog(&mat, metalog);
- } else if (argc == optind) {
+ } else if (argc == options.optind) {
if (strcmp(action, "list") == 0) {
ok = mat_list(&mat, NULL, stdout);
} else if (strcmp(action, "verify") == 0) {
@@ -248,7 +252,7 @@
return 0;
}
} else {
- for (ok = 1, i = optind ; i < argc ; i++) {
+ for (ok = 1, i = options.optind ; i < argc ; i++) {
if (strcmp(action, "create") == 0) {
if (!mat_add(&mat, argv[i])) {
ok = 0;
@@ -305,6 +309,7 @@
mat_pax(int argc, char **argv)
{
const char *action;
+ getopt2_t options;
mat_t mat;
char temp[MAT_PATH_MAX];
char cwd[MAT_PATH_MAX];
@@ -323,10 +328,11 @@
ok = 1;
action = "list";
deltemp = 0;
- while ((i = getopt(argc, argv, "C:Vaf:lrs:wv")) != -1) {
+ getopt2_init(&options);
+ while ((i = getopt2(&options, argc, argv, "C:Vaf:lrs:wv")) != -1) {
switch(i) {
case 'C':
- dir = optarg;
+ dir = options.optarg;
break;
case 'V':
action = "verify";
@@ -335,7 +341,7 @@
action = "audit";
break;
case 'f':
- archive = optarg;
+ archive = options.optarg;
break;
case 'l':
action = "list";
@@ -344,8 +350,8 @@
action = "extract";
break;
case 's':
- if (!compile_subst(&mat, optarg)) {
- (void) fprintf(stderr, "bad regexp '%s'\n", optarg);
+ if (!compile_subst(&mat, options.optarg)) {
+ (void) fprintf(stderr, "bad regexp '%s'\n", options.optarg);
return 0;
}
break;
@@ -378,7 +384,7 @@
}
if (metalog != NULL) {
ok = read_metalog(&mat, metalog);
- } else if (argc == optind) {
+ } else if (argc == options.optind) {
if (strcmp(action, "list") == 0) {
ok = mat_list(&mat, NULL, stdout);
} else if (strcmp(action, "verify") == 0) {
@@ -390,7 +396,7 @@
return 0;
}
} else {
- for (ok = 1, i = optind ; i < argc ; i++) {
+ for (ok = 1, i = options.optind ; i < argc ; i++) {
if (strcmp(action, "create") == 0) {
if (!mat_add(&mat, argv[i])) {
ok = 0;
Index: othersrc/external/bsd/mat/libmat/Makefile
diff -u othersrc/external/bsd/mat/libmat/Makefile:1.2 othersrc/external/bsd/mat/libmat/Makefile:1.3
--- othersrc/external/bsd/mat/libmat/Makefile:1.2 Mon Jun 20 14:58:53 2011
+++ othersrc/external/bsd/mat/libmat/Makefile Fri Jul 15 05:33:42 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2011/06/20 14:58:53 agc Exp $
+# $NetBSD: Makefile,v 1.3 2011/07/15 05:33:42 agc Exp $
.include <bsd.own.mk>
@@ -16,4 +16,6 @@
INCS+= mat.h
INCSDIR=/usr/include
+LIBDPLIBS+= getopt2 ${.CURDIR}/../../getopt2/libgetopt2
+
.include <bsd.lib.mk>
Index: othersrc/external/bsd/mat/mat/Makefile
diff -u othersrc/external/bsd/mat/mat/Makefile:1.4 othersrc/external/bsd/mat/mat/Makefile:1.5
--- othersrc/external/bsd/mat/mat/Makefile:1.4 Sat Jun 25 17:05:35 2011
+++ othersrc/external/bsd/mat/mat/Makefile Fri Jul 15 05:33:42 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2011/06/25 17:05:35 agc Exp $
+# $NetBSD: Makefile,v 1.5 2011/07/15 05:33:42 agc Exp $
.include <bsd.own.mk>
@@ -12,6 +12,10 @@
LDADD+= -L${LIBMATDIR} -lmat
DPADD+= ${LIBMATDIR}/libmat.a
+LIBGETOPT2DIR!= cd ${.CURDIR}/../../getopt2/libgetopt2 && ${PRINTOBJDIR}
+LDADD+= -L${LIBGETOPT2DIR} -lgetopt2
+DPADD+= ${LIBGETOPT2DIR}/libgetopt2.a
+
LINKS+= ${BINDIR}/mat ${BINDIR}/mattar
LINKS+= ${BINDIR}/mat ${BINDIR}/matpax