-/* $OpenBSD: ar_io.c,v 1.10 1997/02/20 06:54:31 tholo Exp $ */
+/* $OpenBSD: ar_io.c,v 1.11 1997/02/27 23:32:56 michaels Exp $ */
/* $NetBSD: ar_io.c,v 1.5 1996/03/26 23:54:13 mrg Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: ar_io.c,v 1.10 1997/02/20 06:54:31 tholo Exp $";
+static char rcsid[] = "$OpenBSD: ar_io.c,v 1.11 1997/02/27 23:32:56 michaels Exp $";
#endif
#endif /* not lint */
if (arfd < 0)
return(-1);
+ if (chdname != NULL)
+ if (chdir(chdname) != 0)
+ syswarn(1, errno, "Failed chdir to %s", chdname);
/*
* set up is based on device type
*/
-/* $OpenBSD: ar_subs.c,v 1.5 1997/01/24 19:41:19 millert Exp $ */
+/* $OpenBSD: ar_subs.c,v 1.6 1997/02/27 23:32:57 michaels Exp $ */
/* $NetBSD: ar_subs.c,v 1.5 1995/03/21 09:07:06 cgd Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)ar_subs.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: ar_subs.c,v 1.5 1997/01/24 19:41:19 millert Exp $";
+static char rcsid[] = "$OpenBSD: ar_subs.c,v 1.6 1997/02/27 23:32:57 michaels Exp $";
#endif
#endif /* not lint */
/*
* if required, chdir around.
*/
- if ((arcn->pat != NULL) && (arcn->pat->chdnam != NULL)) {
- if (chdir(arcn->pat->chdnam) < 0) {
+ if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL))
+ if (chdir(arcn->pat->chdname) != 0)
syswarn(1, errno, "Cannot chdir to %s",
- arcn->pat->chdnam);
- return;
- }
- }
+ arcn->pat->chdname);
/*
* all ok, extract this member based on type
/*
* if required, chdir around.
*/
- if ((arcn->pat != NULL) && (arcn->pat->chdnam != NULL)) {
- if (chdir(cwdpt) < 0) {
- syswarn(0, errno, "Can't chdir to %s", cwdpt);
- return;
- }
- }
+ if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL))
+ if (chdir(cwdpt) != 0)
+ syswarn(1, errno, "Can't chdir to %s", cwdpt);
}
/*
-/* $OpenBSD: extern.h,v 1.9 1997/01/26 10:33:22 downsj Exp $ */
+/* $OpenBSD: extern.h,v 1.10 1997/02/27 23:32:57 michaels Exp $ */
/* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */
/*-
OPLIST * opt_next __P((void));
int opt_add __P((register char *));
int bad_opt __P((void));
+char *chdname;
/*
* pat_rep.c
-/* $OpenBSD: options.c,v 1.14 1997/02/20 06:54:34 tholo Exp $ */
+/* $OpenBSD: options.c,v 1.15 1997/02/27 23:32:58 michaels Exp $ */
/* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: options.c,v 1.14 1997/02/20 06:54:34 tholo Exp $";
+static char rcsid[] = "$OpenBSD: options.c,v 1.15 1997/02/27 23:32:58 michaels Exp $";
#endif
#endif /* not lint */
{
register int c;
int fstdin = 0;
- char *chdnam = (char *)NULL;
/*
* process option flags
*/
break;
case 'C':
- chdnam = optarg;
+ chdname = optarg;
break;
case 'H':
/*
default:
{
int sawpat = 0;
-
+
while (*argv != (char *)NULL) {
- if (!strcmp(*argv, "-C")) {
+ if (strcmp(*argv, "-C") == 0) {
if(*++argv == (char *)NULL)
break;
- chdnam = *argv++;
+ chdname = *argv++;
continue;
}
- if (pat_add(*argv++, chdnam) < 0)
+ if (pat_add(*argv++, chdname) < 0)
tar_usage();
sawpat++;
}
-
/*
- * If there were no patterns, but there was a chdir,
- * we do it now.
- */
- if ((sawpat == 0) && (chdnam != (char *)NULL)) {
- if (chdir(chdnam) < 0) {
- syswarn(0, errno, "Can't chdir to %s",
- chdnam);
- exit(exit_val);
- }
- }
+ * if patterns were added, we are doing chdir()
+ * on a file-by-file basis, else, just one
+ * global chdir (if any) after opening input.
+ */
+ if (sawpat > 0)
+ chdname = NULL;
}
break;
case ARCHIVE:
case APPND:
- if (chdnam != (char *)NULL) { /* initial chdir() */
- if (ftree_add(chdnam, 1) < 0)
+ if (chdname != (char *)NULL) { /* initial chdir() */
+ if (ftree_add(chdname, 1) < 0)
tar_usage();
}
-/* $OpenBSD: pat_rep.c,v 1.5 1996/10/27 06:45:12 downsj Exp $ */
+/* $OpenBSD: pat_rep.c,v 1.6 1997/02/27 23:32:59 michaels Exp $ */
/* $NetBSD: pat_rep.c,v 1.4 1995/03/21 09:07:33 cgd Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)pat_rep.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: pat_rep.c,v 1.5 1996/10/27 06:45:12 downsj Exp $";
+static char rcsid[] = "$OpenBSD: pat_rep.c,v 1.6 1997/02/27 23:32:59 michaels Exp $";
#endif
#endif /* not lint */
#if __STDC__
int
-pat_add(char *str, char *chdnam)
+pat_add(char *str, char *chdname)
#else
int
-pat_add(str, chdnam)
+pat_add(str, chdname)
char *str;
- char *chdnam;
+ char *chdname;
#endif
{
register PATTERN *pt;
pt->plen = strlen(str);
pt->fow = NULL;
pt->flgs = 0;
- if (chdnam != (char *)NULL) {
- pt->chdnam = strdup(chdnam);
- if (pt->chdnam == (char *)NULL) {
- paxwarn(1,
- "Unable to allocate memory for pattern string");
- return(-1);
- }
- } else
- pt->chdnam = (char *)NULL;
+ pt->chdname = chdname;
+
if (pathead == NULL) {
pattail = pathead = pt;
return(0);
return(-1);
}
*ppt = pt->fow;
- if (pt->chdnam != (char *)NULL)
- (void)free(pt->chdnam);
(void)free((char *)pt);
arcn->pat = NULL;
return(0);
-/* $OpenBSD: pax.h,v 1.6 1996/12/09 12:00:16 deraadt Exp $ */
+/* $OpenBSD: pax.h,v 1.7 1997/02/27 23:32:59 michaels Exp $ */
/* $NetBSD: pax.h,v 1.3 1995/03/21 09:07:41 cgd Exp $ */
/*-
typedef struct pattern {
char *pstr; /* pattern to match, user supplied */
char *pend; /* end of a prefix match */
- char *chdnam;
+ char *chdname; /* the dir to change to if not NULL. */
int plen; /* length of pstr */
int flgs; /* processing/state flags */
#define MTCH 0x1 /* pattern has been matched */