summaryrefslogtreecommitdiffstats
path: root/bin/chmod/chmod.c
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2001-05-28 15:31:11 +0000
committerru <ru@FreeBSD.org>2001-05-28 15:31:11 +0000
commit5e17a4447b8fb1510b507aa04823e1721b5b8882 (patch)
treed914068a168ed199c47d97e1deb23d5a5c9af9dc /bin/chmod/chmod.c
parenta58618001f65f45573031d65214ac7e6dcf4fd94 (diff)
downloadFreeBSD-src-5e17a4447b8fb1510b507aa04823e1721b5b8882.zip
FreeBSD-src-5e17a4447b8fb1510b507aa04823e1721b5b8882.tar.gz
Change noop option -h to do the real work. Now mode of symbolic link
is changed if -h option is given. Requested by: bde Obtained from: NetBSD (code part)
Diffstat (limited to 'bin/chmod/chmod.c')
-rw-r--r--bin/chmod/chmod.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/bin/chmod/chmod.c b/bin/chmod/chmod.c
index 7a843c7..97c9c02 100644
--- a/bin/chmod/chmod.c
+++ b/bin/chmod/chmod.c
@@ -74,11 +74,12 @@ main(argc, argv)
int vflag;
char *ep, *mode;
int newmode;
+ int (*change_mode) __P((const char *, mode_t));
set = NULL;
omode = 0;
Hflag = Lflag = Pflag = Rflag = fflag = hflag = vflag = 0;
- while ((ch = getopt(argc, argv, "HLPRXfgorstuvwx")) != -1)
+ while ((ch = getopt(argc, argv, "HLPRXfghorstuvwx")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -102,9 +103,10 @@ main(argc, argv)
/*
* In System V (and probably POSIX.2) the -h option
* causes chmod to change the mode of the symbolic
- * link. 4.4BSD's symbolic links don't have modes,
- * so it's an undocumented noop. Do syntax checking,
- * though.
+ * link. 4.4BSD's symbolic links didn't have modes,
+ * so it was an undocumented noop. In FreeBSD 3.0,
+ * lchmod(2) is introduced and this option does real
+ * work.
*/
hflag = 1;
break;
@@ -148,6 +150,11 @@ done: argv += optind;
} else
fts_options = FTS_LOGICAL;
+ if (hflag)
+ change_mode = lchmod;
+ else
+ change_mode = chmod;
+
mode = *argv;
if (*mode >= '0' && *mode <= '7') {
errno = 0;
@@ -190,14 +197,17 @@ done: argv += optind;
* don't point to anything and ones that we found
* doing a physical walk.
*/
- continue;
+ if (!hflag)
+ continue;
+ /* else */
+ /* FALLTHROUGH */
default:
break;
}
newmode = oct ? omode : getmode(set, p->fts_statp->st_mode);
if ((newmode & ALLPERMS) == (p->fts_statp->st_mode & ALLPERMS))
continue;
- if (chmod(p->fts_accpath, newmode) && !fflag) {
+ if ((*change_mode)(p->fts_accpath, newmode) && !fflag) {
warn("%s", p->fts_path);
rval = 1;
} else {
@@ -215,6 +225,6 @@ void
usage()
{
(void)fprintf(stderr,
- "usage: chmod [-fv] [-R [-H | -L | -P]] mode file ...\n");
+ "usage: chmod [-fhv] [-R [-H | -L | -P]] mode file ...\n");
exit(1);
}
OpenPOWER on IntegriCloud