summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-06-13 17:51:15 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-06-13 17:51:15 +0000
commita42016a89f1868417d387d1913b585cc085f838f (patch)
tree18254b99fdacd0fa29113af2a4a37b68887d3ed9
parent2beff53b1604b0bf21610bf30d8b0b92f8a29a53 (diff)
Add a -0 flag to make pax use a NUL instead of a newline as the
pathname separator. Works in list mode as well as read/copy mode. Based on a patch from David Leonard; closes PR 3310
-rw-r--r--bin/pax/extern.h3
-rw-r--r--bin/pax/ftree.c58
-rw-r--r--bin/pax/gen_subs.c16
-rw-r--r--bin/pax/options.c14
-rw-r--r--bin/pax/options.h5
-rw-r--r--bin/pax/pax.124
-rw-r--r--bin/pax/pax.c5
7 files changed, 102 insertions, 23 deletions
diff --git a/bin/pax/extern.h b/bin/pax/extern.h
index 54d1250f2aa..91f9f88b6fc 100644
--- a/bin/pax/extern.h
+++ b/bin/pax/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.25 2003/06/02 23:32:08 millert Exp $ */
+/* $OpenBSD: extern.h,v 1.26 2003/06/13 17:51:14 millert Exp $ */
/* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */
/*-
@@ -222,6 +222,7 @@ extern int Lflag;
extern int Xflag;
extern int Yflag;
extern int Zflag;
+extern int zeroflag;
extern int vfpart;
extern int patime;
extern int pmtime;
diff --git a/bin/pax/ftree.c b/bin/pax/ftree.c
index 63d4e854763..3107867934c 100644
--- a/bin/pax/ftree.c
+++ b/bin/pax/ftree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftree.c,v 1.22 2003/06/02 23:32:08 millert Exp $ */
+/* $OpenBSD: ftree.c,v 1.23 2003/06/13 17:51:14 millert Exp $ */
/* $NetBSD: ftree.c,v 1.4 1995/03/21 09:07:21 cgd Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static const char sccsid[] = "@(#)ftree.c 8.2 (Berkeley) 4/18/94";
#else
-static const char rcsid[] = "$OpenBSD: ftree.c,v 1.22 2003/06/02 23:32:08 millert Exp $";
+static const char rcsid[] = "$OpenBSD: ftree.c,v 1.23 2003/06/13 17:51:14 millert Exp $";
#endif
#endif /* not lint */
@@ -80,6 +80,7 @@ static FTSENT *ftent = NULL; /* current file tree entry */
static int ftree_skip; /* when set skip to next file arg */
static int ftree_arg(void);
+static char *getpathname(char *, int);
/*
* ftree_start()
@@ -259,7 +260,6 @@ ftree_chk(void)
static int
ftree_arg(void)
{
- char *pt;
/*
* close off the current file tree
@@ -279,10 +279,8 @@ ftree_arg(void)
* the user didn't supply any args, get the file trees
* to process from stdin;
*/
- if (fgets(farray[0], PAXPATHLEN+1, stdin) == NULL)
+ if (getpathname(farray[0], PAXPATHLEN+1) == NULL)
return(-1);
- if ((pt = strchr(farray[0], '\n')) != NULL)
- *pt = '\0';
} else {
/*
* the user supplied the file args as arguments to pax
@@ -499,3 +497,51 @@ next_file(ARCHD *arcn)
arcn->org_name = ftent->fts_path;
return(0);
}
+
+/*
+ * getpathname()
+ * Reads a pathname from stdin, handling NUL- or newline-termination.
+ * Return:
+ * NULL at end of file, otherwise the NUL-terminated buffer.
+ */
+
+static char *
+getpathname(char *buf, int buflen)
+{
+ char *bp, *ep;
+ int ch, term;
+
+ if (zeroflag) {
+ /*
+ * Read a NUL-terminated pathname, being especially
+ * paranoid about proper termination and pathname length.
+ */
+ for (bp = buf, ep = buf + buflen; bp < ep; bp++) {
+ if ((ch = getchar()) == EOF) {
+ if (bp != buf)
+ paxwarn(1, "Ignoring unterminated "
+ "pathname at EOF");
+ return(NULL);
+ }
+ if ((*bp = ch) == '\0')
+ return(buf);
+ }
+ /* Too long - skip this path */
+ *--bp = '\0';
+ term = '\0';
+ } else {
+ if (fgets(buf, buflen, stdin) == NULL)
+ return(NULL);
+ if ((bp = strchr(buf, '\n')) != NULL || feof(stdin)) {
+ if (bp != NULL)
+ *bp = '\0';
+ return(buf);
+ }
+ /* Too long - skip this path */
+ term = '\n';
+ }
+ while ((ch = getchar()) != term && ch != EOF)
+ ;
+ paxwarn(1, "Ignoring too-long pathname: %s", buf);
+ return(NULL);
+}
diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c
index 6d2f47ce1f0..00ae4b674af 100644
--- a/bin/pax/gen_subs.c
+++ b/bin/pax/gen_subs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gen_subs.c,v 1.16 2003/06/02 23:32:08 millert Exp $ */
+/* $OpenBSD: gen_subs.c,v 1.17 2003/06/13 17:51:14 millert Exp $ */
/* $NetBSD: gen_subs.c,v 1.5 1995/03/21 09:07:26 cgd Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static const char sccsid[] = "@(#)gen_subs.c 8.1 (Berkeley) 5/31/93";
#else
-static const char rcsid[] = "$OpenBSD: gen_subs.c,v 1.16 2003/06/02 23:32:08 millert Exp $";
+static const char rcsid[] = "$OpenBSD: gen_subs.c,v 1.17 2003/06/13 17:51:14 millert Exp $";
#endif
#endif /* not lint */
@@ -82,13 +82,19 @@ ls_list(ARCHD *arcn, time_t now, FILE *fp)
char f_mode[MODELEN];
char f_date[DATELEN];
const char *timefrmt;
+ int term;
+
+ term = zeroflag ? '\0' : '\n'; /* path termination character */
/*
* if not verbose, just print the file name
*/
if (!vflag) {
- safe_print(arcn->name, fp);
- (void)putc('\n', fp);
+ if (zeroflag)
+ (void)fputs(arcn->name, fp);
+ else
+ safe_print(arcn->name, fp);
+ (void)putc(term, fp);
(void)fflush(fp);
return;
}
@@ -151,7 +157,7 @@ ls_list(ARCHD *arcn, time_t now, FILE *fp)
fputs(" => ", fp);
safe_print(arcn->ln_name, fp);
}
- (void)putc('\n', fp);
+ (void)putc(term, fp);
(void)fflush(fp);
return;
}
diff --git a/bin/pax/options.c b/bin/pax/options.c
index 2c7b636608e..2aaf3f74230 100644
--- a/bin/pax/options.c
+++ b/bin/pax/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.57 2003/06/02 23:32:08 millert Exp $ */
+/* $OpenBSD: options.c,v 1.58 2003/06/13 17:51:14 millert Exp $ */
/* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static const char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
#else
-static const char rcsid[] = "$OpenBSD: options.c,v 1.57 2003/06/02 23:32:08 millert Exp $";
+static const char rcsid[] = "$OpenBSD: options.c,v 1.58 2003/06/13 17:51:14 millert Exp $";
#endif
#endif /* not lint */
@@ -194,7 +194,7 @@ pax_options(int argc, char **argv)
/*
* process option flags
*/
- while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLPT:U:XYZ"))
+ while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLPT:U:XYZ0"))
!= -1) {
switch (c) {
case 'a':
@@ -505,6 +505,14 @@ pax_options(int argc, char **argv)
Zflag = 1;
flg |= CZF;
break;
+ case '0':
+ /*
+ * Use \0 as pathname terminator.
+ * (For use with the -print0 option of find(1).)
+ */
+ zeroflag = 1;
+ flg |= C0F;
+ break;
default:
pax_usage();
break;
diff --git a/bin/pax/options.h b/bin/pax/options.h
index 6d932afa6bf..30d0e89de86 100644
--- a/bin/pax/options.h
+++ b/bin/pax/options.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.h,v 1.3 2003/06/02 23:32:08 millert Exp $ */
+/* $OpenBSD: options.h,v 1.4 2003/06/13 17:51:14 millert Exp $ */
/* $NetBSD: options.h,v 1.3 1995/03/21 09:07:32 cgd Exp $ */
/*-
@@ -84,12 +84,13 @@
#define CXF 0x08000000
#define CYF 0x10000000 /* nonstandard extension */
#define CZF 0x20000000 /* nonstandard extension */
+#define C0F 0x40000000 /* nonstandard extension */
/*
* ascii string indexed by bit position above (alter the above and you must
* alter this string) used to tell the user what flags caused us to complain
*/
-#define FLGCH "abcdfiklnoprstuvwxBDEGHLPTUXYZ"
+#define FLGCH "abcdfiklnoprstuvwxBDEGHLPTUXYZ0"
/*
* legal pax operation bit patterns
diff --git a/bin/pax/pax.1 b/bin/pax/pax.1
index da840c9f295..06612c73dc8 100644
--- a/bin/pax/pax.1
+++ b/bin/pax/pax.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pax.1,v 1.39 2003/06/02 23:32:08 millert Exp $
+.\" $OpenBSD: pax.1,v 1.40 2003/06/13 17:51:14 millert Exp $
.\" $NetBSD: pax.1,v 1.3 1995/03/21 09:07:37 cgd Exp $
.\"
.\" Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
.Nd read and write file archives and copy directory hierarchies
.Sh SYNOPSIS
.Nm pax
-.Op Fl cdnvz
+.Op Fl 0cdnvz
.Bk -words
.Op Fl f Ar archive
.Ek
@@ -105,7 +105,7 @@
.Op Ar pattern ...
.Nm pax
.Fl w
-.Op Fl dituvzHLPX
+.Op Fl 0dituvzHLPX
.Bk -words
.Op Fl b Ar blocksize
.Ek
@@ -148,7 +148,7 @@
.Nm pax
.Fl r
.Fl w
-.Op Fl diklntuvDHLPXYZ
+.Op Fl 0diklntuvDHLPXYZ
.Bk -words
.Op Fl p Ar string
.Ar ...
@@ -380,6 +380,22 @@ archive or have other unpredictable results.
Tape drives in particular are more likely to not support an append operation.
An archive stored in a regular file system file or on a disk device will
usually support an append operation.
+.It Fl 0
+Use the NUL
+.Pq Ql \e0
+character as a pathname terminator, instead of newline
+.Pq Ql \en .
+This applies only to the pathnames read from standard input in
+the write and copy modes,
+and to the pathnames written to standard output in list mode.
+This option is expected to be used in concert with the
+.Fl print0
+function in
+.Xr find 1
+or the
+.Fl 0
+flag in
+.Xr xargs 1 .
.It Fl b Ar blocksize
When
.Em writing
diff --git a/bin/pax/pax.c b/bin/pax/pax.c
index 4629622bb2c..098b10ad18c 100644
--- a/bin/pax/pax.c
+++ b/bin/pax/pax.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pax.c,v 1.23 2003/06/02 23:32:09 millert Exp $ */
+/* $OpenBSD: pax.c,v 1.24 2003/06/13 17:51:14 millert Exp $ */
/* $NetBSD: pax.c,v 1.5 1996/03/26 23:54:20 mrg Exp $ */
/*-
@@ -44,7 +44,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94";
#else
-static const char rcsid[] = "$OpenBSD: pax.c,v 1.23 2003/06/02 23:32:09 millert Exp $";
+static const char rcsid[] = "$OpenBSD: pax.c,v 1.24 2003/06/13 17:51:14 millert Exp $";
#endif
#endif /* not lint */
@@ -91,6 +91,7 @@ int Lflag; /* follow symlinks when writing */
int Xflag; /* archive files with same device id only */
int Yflag; /* same as Dflg except after name mode */
int Zflag; /* same as uflg except after name mode */
+int zeroflag; /* use \0 as pathname terminator */
int vfpart; /* is partial verbose output in progress */
int patime = 1; /* preserve file access time */
int pmtime = 1; /* preserve file modification times */