add -X flag to make the world safe for xargs
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 28 Apr 1991 04:37:41 +0000 (20:37 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 28 Apr 1991 04:37:41 +0000 (20:37 -0800)
SCCS-vsn: usr.bin/find/find.1 6.20
SCCS-vsn: usr.bin/find/find.c 4.37
SCCS-vsn: usr.bin/find/find.h 5.6
SCCS-vsn: usr.bin/find/main.c 5.7

usr/src/usr.bin/find/find.1
usr/src/usr.bin/find/find.c
usr/src/usr.bin/find/find.h
usr/src/usr.bin/find/main.c

index 6ed2cb3..96de09c 100644 (file)
@@ -3,7 +3,7 @@
 .\"
 .\" %sccs.include.redist.man%
 .\"
 .\"
 .\" %sccs.include.redist.man%
 .\"
-.\"     @(#)find.1     6.19 (Berkeley) %G%
+.\"     @(#)find.1     6.20 (Berkeley) %G%
 .\"
 .Vx
 .Vx
 .\"
 .Vx
 .Vx
@@ -15,7 +15,7 @@
 .Nd walk a file hierarchy
 .Sh SYNOPSIS
 .Nm find
 .Nd walk a file hierarchy
 .Sh SYNOPSIS
 .Nm find
-.Op Fl drsx
+.Op Fl drsXx
 .Op Ar path
 .Ar expression
 .Nm find
 .Op Ar path
 .Ar expression
 .Nm find
@@ -86,6 +86,19 @@ returned for each symbolic link to be those of the file referenced by the
 link, not the link itself.
 If the referenced file does not exist, the file information and type will
 be for the link itself.
 link, not the link itself.
 If the referenced file does not exist, the file information and type will
 be for the link itself.
+.Tp Fl X
+The
+.Fl X
+option is a modification to permit
+.Nm
+to be safely used in conjunction with
+.Xr xargs 1 .
+If a file name contains any of the delimiting characters used by
+.Xr xargs ,
+a diagnostic message is displayed on standard error, and the file
+is skipped.
+The delimiting characters include single (`` ' '') and double (`` " '')
+quotes, backslash (``\e''), space, tab and newline characters.
 .Tp Fl x
 The
 .Fl x
 .Tp Fl x
 The
 .Fl x
index 03be2bd..0ade037 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)find.c     4.36 (Berkeley) %G%";
+static char sccsid[] = "@(#)find.c     4.37 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -36,6 +36,7 @@ int isdeprecated;             /* using deprecated syntax */
 int isdepth;                   /* do directories on post-order visit */
 int isoutput;                  /* user specified output operator */
 int isrelative;                        /* can do -exec/ok on relative path */
 int isdepth;                   /* do directories on post-order visit */
 int isoutput;                  /* user specified output operator */
 int isrelative;                        /* can do -exec/ok on relative path */
+int isxargs;                   /* don't permit xargs delimiting chars */
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -197,6 +198,13 @@ find_execute(plan, paths)
                        continue;
                }
 
                        continue;
                }
 
+#define        BADCH   " \t\n\\'\""
+               if (isxargs && strpbrk(entry->fts_path, BADCH)) {
+                       (void)fprintf(stderr,
+                           "find: illegal path: %s\n", entry->fts_path);
+                       continue;
+               }
+                
                /*
                 * call all the functions in the execution plan until one is
                 * false or all have been executed.  This is where we do all
                /*
                 * call all the functions in the execution plan until one is
                 * false or all have been executed.  This is where we do all
index fbeedc9..40f5fe5 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)find.h      5.5 (Berkeley) %G%
+ *     @(#)find.h      5.6 (Berkeley) %G%
  */
 
 /* node definition */
  */
 
 /* node definition */
@@ -83,5 +83,5 @@ typedef struct _plandata {
        (void)fprintf(stderr, "find: %s: %s\n", name, strerror(number));
 
 extern int ftsoptions;
        (void)fprintf(stderr, "find: %s: %s\n", name, strerror(number));
 
 extern int ftsoptions;
-extern int isdeprecated, isdepth, isoutput, isrelative;
+extern int isdeprecated, isdepth, isoutput, isrelative, isxargs;
 void *emalloc();
 void *emalloc();
index 9311753..ed49bee 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -27,7 +27,7 @@ newsyntax(argc, argvp)
        char **argv, **cur;
 
        cur = argv = *argvp;
        char **argv, **cur;
 
        cur = argv = *argvp;
-       while ((ch = getopt(argc, argv, "df:rsx")) != EOF)
+       while ((ch = getopt(argc, argv, "df:rsXx")) != EOF)
                switch(ch) {
                case 'd':
                        isdepth = 1;
                switch(ch) {
                case 'd':
                        isdepth = 1;
@@ -42,6 +42,9 @@ newsyntax(argc, argvp)
                        ftsoptions &= ~FTS_PHYSICAL;
                        ftsoptions |= FTS_LOGICAL;
                        break;
                        ftsoptions &= ~FTS_PHYSICAL;
                        ftsoptions |= FTS_LOGICAL;
                        break;
+               case 'X':
+                       isxargs = 1;
+                       break;
                case 'x':
                        ftsoptions &= ~FTS_NOSTAT;
                        ftsoptions |= FTS_XDEV;
                case 'x':
                        ftsoptions &= ~FTS_NOSTAT;
                        ftsoptions |= FTS_XDEV;