BSD 4_2 release
[unix-history] / usr / src / bin / chgrp.c
index ea53806..954079f 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)chgrp.c     4.4 83/01/20";
+static char *sccsid = "@(#)chgrp.c     4.6 83/05/10";
 #endif
 
 /*
 #endif
 
 /*
@@ -18,6 +18,7 @@ struct        passwd *getpwuid(), *pwd;
 struct stat stbuf;
 int    gid, uid;
 int    status;
 struct stat stbuf;
 int    gid, uid;
 int    status;
+int    fflag;
 /* VARARGS */
 int    fprintf();
 
 /* VARARGS */
 int    fprintf();
 
@@ -28,8 +29,12 @@ main(argc, argv)
        register c, i;
 
        argc--, argv++;
        register c, i;
 
        argc--, argv++;
+       if (argc > 0 && strcmp(argv[0], "-f") == 0) {
+               fflag++;
+               argv++, argc--;
+       }
        if (argc < 2) {
        if (argc < 2) {
-               printf("usage: chgrp gid file ...\n");
+               printf("usage: chgrp [-f] gid file ...\n");
                exit(2);
        }
        uid = getuid();
                exit(2);
        }
        uid = getuid();
@@ -57,6 +62,8 @@ main(argc, argv)
                for (i=0; gr->gr_mem[i]; i++)
                        if (!(strcmp(pwd->pw_name, gr->gr_mem[i])))
                                goto ok;
                for (i=0; gr->gr_mem[i]; i++)
                        if (!(strcmp(pwd->pw_name, gr->gr_mem[i])))
                                goto ok;
+               if (fflag)
+                       exit(0);
                fprintf(stderr, "You are not a member of the %s group.\n",
                    argv[0]);
                exit(2);
                fprintf(stderr, "You are not a member of the %s group.\n",
                    argv[0]);
                exit(2);
@@ -68,12 +75,14 @@ ok:
                        continue;
                }
                if (uid && uid != stbuf.st_uid) {
                        continue;
                }
                if (uid && uid != stbuf.st_uid) {
+                       if (fflag)
+                               continue;
                        fprintf(stderr, "You are not the owner of %s\n",
                            argv[c]);
                        status = 1;
                        continue;
                }
                        fprintf(stderr, "You are not the owner of %s\n",
                            argv[c]);
                        status = 1;
                        continue;
                }
-               if (chown(argv[c], stbuf.st_uid, gid))
+               if (chown(argv[c], stbuf.st_uid, gid) && !fflag)
                        perror(argv[c]);
        }
        exit(status);
                        perror(argv[c]);
        }
        exit(status);