POSIX 1003.2B/D9 symbolic links
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 1 Apr 1994 22:33:20 +0000 (14:33 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 1 Apr 1994 22:33:20 +0000 (14:33 -0800)
SCCS-vsn: usr.bin/find/find.1 8.4
SCCS-vsn: usr.bin/find/find.c 8.2
SCCS-vsn: usr.bin/find/main.c 8.2

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

index c98c7c3..56d4e6a 100644 (file)
@@ -6,7 +6,7 @@
 .\"
 .\" %sccs.include.redist.roff%
 .\"
-.\"    @(#)find.1      8.3 (Berkeley) %G%
+.\"    @(#)find.1      8.4 (Berkeley) %G%
 .\"
 .Dd 
 .Dt FIND 1
@@ -16,7 +16,8 @@
 .Nd walk a file hierarchy
 .Sh SYNOPSIS
 .Nm find
-.Op Fl HdhXx
+.Op Fl H | Fl L | Fl P
+.Op Fl Xdx
 .Op Fl f Ar file
 .Op Ar file ...
 .Ar expression
@@ -36,12 +37,40 @@ The options are as follows:
 The
 .Fl H
 option causes the file information and file type (see
-.Xr stat  2  ) ,
-returned for each symbolic link encountered on the command line to be 
+.Xr stat 2)
+returned for each symbolic link specified on the command line 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.  File information of all symbolic links not on 
 the command line is that of the link itself.
+.It Fl L
+The
+.Fl L
+option causes the file information and file type (see
+.Xr stat 2)
+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.
+.It Fl P
+The
+.Fl P
+option causes the file information and file type (see
+.Xr stat 2)
+returned for each symbolic link to be those of the link itself.
+.It 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.
 .It Fl d
 The
 .Fl d
@@ -64,28 +93,6 @@ option specifies a file hierarchy for
 to traverse.
 File hierarchies may also be specified as the operands immediately
 following the options.
-.It Fl h
-The
-.Fl h
-option causes the file information and file type (see
-.Xr stat  2  ) ,
-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.
-.It 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.
 .It Fl x
 The
 .Fl x
@@ -355,8 +362,8 @@ that are newer than ``ttt''.
 .Xr locate 1 ,
 .Xr stat 2 ,
 .Xr fts 3 ,
-.Xr getpwent 3 ,
 .Xr getgrent 3 ,
+.Xr getpwent 3 ,
 .Xr strmode 3 ,
 .Xr symlink 7
 .Sh STANDARDS
index b3f7080..b9a67fe 100644 (file)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 1991, 1993
+ * Copyright (c) 1991, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)find.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)find.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -114,19 +114,20 @@ FTS *tree;                        /* pointer to top of FTS hierarchy */
  *     take a search plan and an array of search paths and executes the plan
  *     over all FTSENT's returned for the given search paths.
  */
-void
+int
 find_execute(plan, paths)
        PLAN *plan;             /* search plan */
        char **paths;           /* array of pathnames to traverse */
 {
        register FTSENT *entry;
        PLAN *p;
+       int rval;
     
-       if (!(tree = fts_open(paths, ftsoptions, (int (*)())NULL)))
+       if ((tree = fts_open(paths, ftsoptions, (int (*)())NULL)) == NULL)
                err(1, "ftsopen");
 
-       while (entry = fts_read(tree)) {
-               switch(entry->fts_info) {
+       for (rval = 0; (entry = fts_read(tree)) != NULL;) {
+               switch (entry->fts_info) {
                case FTS_D:
                        if (isdepth)
                                continue;
@@ -139,22 +140,27 @@ find_execute(plan, paths)
                case FTS_ERR:
                case FTS_NS:
                        (void)fflush(stdout);
+                       errno = entry->fts_errno;
                        warn("%s", entry->fts_path);
+                       rval = 1;
                        continue;
                }
 #define        BADCH   " \t\n\\'\""
                if (isxargs && strpbrk(entry->fts_path, BADCH)) {
                        (void)fflush(stdout);
                        warnx("%s: illegal path", entry->fts_path);
+                       rval = 1;
                        continue;
                }
                 
                /*
-                * call all the functions in the execution plan until one is
+                * Call all the functions in the execution plan until one is
                 * false or all have been executed.  This is where we do all
                 * the work specified by the user on the command line.
                 */
                for (p = plan; p && (p->eval)(p, entry); p = p->next);
        }
-       (void)fts_close(tree);
+       if (errno)
+               err(1, "fts_read");
+       return (rval);
 }
index df2170b..be7751e 100644 (file)
@@ -1,12 +1,21 @@
 /*-
- * Copyright (c) 1990, 1993
+ * Copyright (c) 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
+ * This code is derived from software contributed to Berkeley by
+ * Cimarron D. Taylor of the University of California, Berkeley.
+ *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     8.1 (Berkeley) %G%";
+char copyright[] =
+"@(#) Copyright (c) 1990, 1993, 1994\n\
+       The Regents of the University of California.  All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)main.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -38,16 +47,29 @@ main(argc, argv)
        char *argv[];
 {
        register char **p, **start;
-       int ch;
+       int Hflag, Lflag, Pflag, ch;
 
        (void)time(&now);       /* initialize the time-of-day */
 
        p = start = argv;
-       ftsoptions = FTS_NOSTAT|FTS_PHYSICAL;
-       while ((ch = getopt(argc, argv, "Hdf:hXx")) != EOF)
-               switch(ch) {
+       Hflag = Lflag = Pflag = 0;
+       ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
+       while ((ch = getopt(argc, argv, "HLPXdf:x")) != EOF)
+               switch (ch) {
                case 'H':
-                       ftsoptions |= FTS_COMFOLLOW;
+                       Hflag = 1;
+                       Lflag = Pflag = 0;
+                       break;
+               case 'L':
+                       Lflag = 1;
+                       Hflag = Pflag = 0;
+                       break;
+               case 'P':
+                       Pflag = 1;
+                       Hflag = Lflag = 0;
+                       break;
+               case 'X':
+                       isxargs = 1;
                        break;
                case 'd':
                        isdepth = 1;
@@ -55,13 +77,6 @@ main(argc, argv)
                case 'f':
                        *p++ = optarg;
                        break;
-               case 'h':
-                       ftsoptions &= ~FTS_PHYSICAL;
-                       ftsoptions |= FTS_LOGICAL;
-                       break;
-               case 'X':
-                       isxargs = 1;
-                       break;
                case 'x':
                        ftsoptions |= FTS_XDEV;
                        break;
@@ -73,37 +88,32 @@ main(argc, argv)
        argc -= optind; 
        argv += optind;
 
+       if (Hflag)
+               ftsoptions |= FTS_COMFOLLOW;
+       if (Lflag) {
+               ftsoptions &= ~FTS_PHYSICAL;
+               ftsoptions |= FTS_LOGICAL;
+       }
+
        /* Find first option to delimit the file list. */
-       while (*argv) {
+       for (; *argv != NULL; *p++ = *argv++)
                if (option(*argv))
                        break;
-               *p++ = *argv++;
-       }
 
        if (p == start)
                usage();
        *p = NULL;
 
        if ((dotfd = open(".", O_RDONLY, 0)) < 0)
-               err(1, ".:");
+               err(1, ".");
 
-       find_execute(find_formplan(argv), start);
-       exit(0);
+       exit(find_execute(find_formplan(argv), start));
 }
 
 static void
 usage()
 {
        (void)fprintf(stderr,
-           "usage: find [-HdhXx] [-f file] [file ...] expression\n");
+"usage: find [-H | -L | -P] [-Xdx] [-f file] [file ...] [expression]\n");
        exit(1);
 }
-
-
-
-
-
-
-
-
-