date and time created 91/03/07 20:27:47 by bostic
[unix-history] / usr / src / bin / chmod / chmod.c
index 224414c..20fcc53 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)chmod.c    5.16 (Berkeley) %G%";
+static char sccsid[] = "@(#)chmod.c    5.18 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -41,13 +41,12 @@ main(argc, argv)
        while ((ch = getopt(argc, argv, "Rfrwx")) != EOF)
                switch((char)ch) {
                case 'R':
        while ((ch = getopt(argc, argv, "Rfrwx")) != EOF)
                switch((char)ch) {
                case 'R':
-                       rflag++;
+                       rflag = 1;
                        break;
                        break;
-               case 'f':
-                       fflag++;
+               case 'f':               /* no longer documented */
+                       fflag = 1;
                        break;
                        break;
-               /* "-[rwx]" are valid file modes */
-               case 'r':
+               case 'r':               /* "-[rwx]" are valid file modes */
                case 'w':
                case 'x':
                        --optind;
                case 'w':
                case 'x':
                        --optind;
@@ -81,19 +80,37 @@ done:       argv += optind;
                        (void)fprintf(stderr, "chmod: %s.\n", strerror(errno));
                        exit(1);
                }
                        (void)fprintf(stderr, "chmod: %s.\n", strerror(errno));
                        exit(1);
                }
-               while (p = fts_read(fts)) {
-                       if (p->fts_info == FTS_D)
-                               continue;
-                       if (p->fts_info == FTS_ERR) {
-                               if (!fflag)
+               while (p = fts_read(fts))
+                       switch(p->fts_info) {
+                       case FTS_DNR:
+                               (void)fprintf(stderr,
+                                   "chmod: %s: unable to read.\n",
+                                   p->fts_path);
+                               break;
+                       case FTS_DNX:
+                               (void)fprintf(stderr,
+                                   "chmod: %s: unable to search.\n",
+                                   p->fts_path);
+                               break;
+                       case FTS_D:
+                       case FTS_DC:
+                               break;
+                       case FTS_ERR:
+                               (void)fprintf(stderr, "chmod: %s: %s.\n",
+                                   p->fts_path, strerror(errno));
+                               exit(1);
+                       case FTS_NS:
+                               (void)fprintf(stderr,
+                                   "chmod: %s: unable to stat.\n",
+                                   p->fts_path);
+                               break;
+                       default:
+                               if (chmod(p->fts_accpath, oct ? omode :
+                                   getmode(set, p->fts_statb.st_mode)) &&
+                                   !fflag)
                                        error(p->fts_path);
                                        error(p->fts_path);
-                               continue;
+                               break;
                        }
                        }
-                       if (chmod(p->fts_accpath, oct ?
-                           omode : getmode(set, p->fts_statb.st_mode)) &&
-                           !fflag)
-                               error(p->fts_path);
-               }
                exit(retval);
        }
        if (oct) {
                exit(retval);
        }
        if (oct) {
@@ -117,6 +134,6 @@ error(name)
 
 usage()
 {
 
 usage()
 {
-       (void)fprintf(stderr, "chmod: chmod [-fR] mode file ...\n");
+       (void)fprintf(stderr, "chmod: chmod [-R] mode file ...\n");
        exit(1);
 }
        exit(1);
 }