---
Proposed patch for option 1 described in
https://lists.suckless.org/dev/1912/33729.html
chmod.1 | 16 ++++------------
chmod.c | 11 +++--------
2 files changed, 7 insertions(+), 20 deletions(-)
diff --git a/chmod.1 b/chmod.1
index 4805ce0..b102b64 100644
--- a/chmod.1
+++ b/chmod.1
@@ -6,10 +6,7 @@
.Nd change file modes
.Sh SYNOPSIS
.Nm
-.Oo
-.Fl R
-.Op Fl H | L | P
-.Oc
+.Op Fl R
.Ar mode
.Ar file ...
.Sh DESCRIPTION
@@ -56,18 +53,13 @@ add | remove | set
.It r|w|x|s|t
read | write | execute | setuid and setgid | sticky
.El
+.Pp
+Symbolic links are followed if they are passed as operands, and ignored
+if they are encountered during directory traversal.
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl R
Change modes recursively.
-.It Fl H
-Dereference
-.Ar file
-if it is a symbolic link.
-.It Fl L
-Dereference all symbolic links.
-.It Fl P
-Preserve symbolic links. This is the default.
.El
.Sh SEE ALSO
.Xr chgrp 1 ,
diff --git a/chmod.c b/chmod.c
index 2a0085d..6004a74 100644
--- a/chmod.c
+++ b/chmod.c
@@ -14,7 +14,7 @@ chmodr(const char *path, struct stat *st, void *data, struct
recursor *r)
mode_t m;
m = parsemode(modestr, st->st_mode & ~S_IFMT, mask);
- if (chmod(path, m) < 0) {
+ if (!S_ISLNK(st->st_mode) && chmod(path, m) < 0) {
weprintf("chmod %s:", path);
ret = 1;
} else if (S_ISDIR(st->st_mode)) {
@@ -25,14 +25,14 @@ chmodr(const char *path, struct stat *st, void *data,
struct recursor *r)
static void
usage(void)
{
- eprintf("usage: %s [-R [-H | -L | -P]] mode file ...\n", argv0);
+ eprintf("usage: %s [-R] mode file ...\n", argv0);
}
int
main(int argc, char *argv[])
{
struct recursor r = { .fn = chmodr, .hist = NULL, .depth = 0, .maxdepth
= 1,
- .follow = 'P', .flags = DIRFIRST };
+ .follow = 'H', .flags = DIRFIRST };
size_t i;
argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
@@ -45,11 +45,6 @@ main(int argc, char *argv[])
case 'R':
r.maxdepth = 0;
break;
- case 'H':
- case 'L':
- case 'P':
- r.follow = (*argv)[i];
- break;
case 'r': case 'w': case 'x': case 's': case 't':
/* -[rwxst] are valid modes, so we're done */
if (i == 1)
--
2.24.1