|
|||||||||||
|
user/3310: enhancement to pax(1): -0
From: David Leonard <d(at)adaptive-enterprises.com.au>
Date: Wed Jun 11 2003 - 10:28:48 EDT
System : OpenBSD 3.3 Architecture: OpenBSD.sparc Machine : sparc >How-To-Repeat: >Fix:
RCS file: /openbsd/cvs/src/bin/pax/extern.h,v retrieving revision 1.24 diff -u -u -r1.24 extern.h --- extern.h 18 Oct 2002 15:38:11 -0000 1.24 +++ extern.h 17 May 2003 04:55:37 -0000 @@ -226,6 +226,7 @@ extern int Xflag; extern int Yflag; extern int Zflag; +extern int zeroflag; extern int vfpart; extern int patime; extern int pmtime; Index: ftree.c RCS file: /openbsd/cvs/src/bin/pax/ftree.c,v retrieving revision 1.21 diff -u -u -r1.21 ftree.c --- ftree.c 16 Oct 2002 19:20:02 -0000 1.21 +++ ftree.c 17 May 2003 04:55:37 -0000 @@ -84,6 +84,7 @@ static int ftree_skip; /* when set skip to next file arg */
static int ftree_arg(void);
/*
/*
* close off the current file tree
@@ -283,10 +283,8 @@
* 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
@@ -502,4 +500,56 @@
arcn->nlen = strlcpy(arcn->name, ftent->fts_path, sizeof(arcn->name));
arcn->org_name = ftent->fts_path;
return(0);
+}
+
+/*
+ * getpathname()
+ * Reads a pathname from stdin, handling null- or newline-termination.
+ * Return:
+ * NULL at end of file, otherwise the null-terminated buffer.
+ */
+
+static char *
+getpathname(buf, buflen)
+ char *buf;
+ int buflen;
+{
+ char *pt;
+ int i, ch;
+
+ if (zeroflag) {
+ /*
+ * Read a null-terminated pathname, being
+ * especially paranoid about proper termination
+ * and pathname length.
+ */
+ i = 0;
+ while ((ch = getchar()) != EOF) {
+ if (ch == '\0') {
+ buf[i] = '\0';
+ return buf;
+ }
+ if (i < buflen - 1)
+ buf[i++] = ch;
+ else {
+ /* Too long - skip this path */
+ buf[i] = '\0';
+ paxwarn(1, "Ignoring too-long pathname: %s", buf);
+ while ((ch = getchar()) != '\0')
+ if (ch == EOF)
+ return(NULL);
+ i = 0;
+ }
+ }
+ /* Ignore truncated/corrupt pathnames at EOF. */
+ if (i > 0)
+ paxwarn(1,"Ignoring unterminated pathname at EOF");
+ return NULL;
+ } else {
+ if (fgets(buf, buflen, stdin) == NULL)
+ return(NULL);
+ if ((pt = strchr(buf, '\n')) != NULL)
+ *pt = '\0';
+ return buf;
+ }
} Index: gen_subs.c RCS file: /openbsd/cvs/src/bin/pax/gen_subs.c,v retrieving revision 1.15 diff -u -u -r1.15 gen_subs.c
--- gen_subs.c 16 Oct 2002 19:20:02 -0000 1.15
+++ gen_subs.c 17 May 2003 04:55:37 -0000
@@ -91,8 +91,13 @@
* 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);
+ (void)putc('\0', fp);
+ } else {
+ safe_print(arcn->name, fp);
+ (void)putc('\n', fp);
+ }
(void)fflush(fp);
return;
}
Index: options.c RCS file: /openbsd/cvs/src/bin/pax/options.c,v retrieving revision 1.55 diff -u -u -r1.55 options.c
--- options.c 18 Oct 2002 15:38:11 -0000 1.55
+++ options.c 17 May 2003 04:55:37 -0000
@@ -198,7 +198,7 @@
/*
* 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':
@@ -508,6 +508,14 @@
*/
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();
Index: options.h RCS file: /openbsd/cvs/src/bin/pax/options.h,v retrieving revision 1.2 diff -u -u -r1.2 options.h --- options.h 23 Jun 1996 14:20:37 -0000 1.2 +++ options.h 17 May 2003 04:55:37 -0000 @@ -88,12 +88,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
/*
>Release-Note:
This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:29:58 EDT |
||||||||||
|
|||||||||||