[hackers] [sbase] chmod: Add -HLP flags and update manpage || sin

From: <git_AT_suckless.org>
Date: Tue, 24 Mar 2015 23:53:52 +0100 (CET)

commit 9da1deaab920e2b2635079729aa816822f324eab
Author: sin <sin_AT_2f30.org>
Date: Mon Feb 16 16:47:07 2015 +0000

    chmod: Add -HLP flags and update manpage

diff --git a/chmod.1 b/chmod.1
index 5833af3..08ad958 100644
--- a/chmod.1
+++ b/chmod.1
_AT_@ -6,9 +6,12 @@
 .Nd change file mode
 .Sh SYNOPSIS
 .Nm
-.Op Fl R
+.Oo
+.Fl R
+.Op Fl H | L | P
+.Oc
 .Ar mode
-.Op Ar file ...
+.Ar file ...
 .Sh DESCRIPTION
 .Nm
 changes the file mode of the given
_AT_@ -54,9 +57,17 @@ read | write | execute | setuid and setgid | sticky
 .Sh OPTIONS
 .Bl -tag -width Ds
 .It Fl R
-Change modes recursively
+Change modes recursively.
+.It Fl H
+Only dereference symbolic links that are passed as command line arguments when
+recursively traversing directories.
+.It Fl L
+Always dereference symbolic links while recursively traversing directories.
+.It Fl P
+Don't dereference symbolic links (default).
 .El
 .Sh SEE ALSO
+.Xr chgrp 1 ,
 .Xr umask 1
 .Sh STANDARDS
 The
_AT_@ -66,5 +77,5 @@ utility is compliant with the
 specification.
 .Pp
 The
-.Op Fl R
-flag is an extension to that specification.
+.Op Fl HLP
+flags are an extension to that specification.
diff --git a/chmod.c b/chmod.c
index 1ddc87c..ac94a53 100644
--- a/chmod.c
+++ b/chmod.c
_AT_@ -3,7 +3,8 @@
 
 #include "util.h"
 
-static int rflag = 0;
+static int Rflag = 0;
+static int fflag = 'P';
 static char *modestr = "";
 static mode_t mask = 0;
 static int ret = 0;
_AT_@ -25,14 +26,14 @@ chmodr(const char *path, int fflag)
                 weprintf("chmod %s:", path);
                 ret = 1;
         }
- if (rflag)
+ if (Rflag)
                 recurse(path, chmodr, fflag);
 }
 
 static void
 usage(void)
 {
- eprintf("usage: %s [-R] mode [file ...]\n", argv0);
+ eprintf("usage: %s [-R [-H | -L | -P]] mode file ...\n", argv0);
 }
 
 int
_AT_@ -44,7 +45,12 @@ main(int argc, char *argv[])
         for (i = 1; i < argc && argv[i][0] == '-'; i++) {
                 switch (argv[i][1]) {
                 case 'R':
- rflag = 1;
+ Rflag = 1;
+ break;
+ case 'H':
+ case 'L':
+ case 'P':
+ fflag = argv[i][1];
                         break;
                 case 'r': case 'w': case 'x': case 's': case 't':
                         /*
_AT_@ -65,7 +71,7 @@ done:
                 usage();
 
         for (++i; i < argc; i++)
- chmodr(argv[i], 'P');
+ chmodr(argv[i], fflag);
 
         return ret;
 }
Received on Tue Mar 24 2015 - 23:53:52 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 25 2015 - 00:10:19 CET