Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/chmod add --reference=rfile
details: https://anonhg.NetBSD.org/src/rev/e135e11e80fb
branches: trunk
changeset: 782237:e135e11e80fb
user: christos <christos%NetBSD.org@localhost>
date: Mon Oct 22 17:47:06 2012 +0000
description:
add --reference=rfile
diffstat:
bin/chmod/chmod.1 | 19 ++++++++++++++++---
bin/chmod/chmod.c | 54 ++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 56 insertions(+), 17 deletions(-)
diffs (167 lines):
diff -r 4a16c6aac31a -r e135e11e80fb bin/chmod/chmod.1
--- a/bin/chmod/chmod.1 Mon Oct 22 16:43:05 2012 +0000
+++ b/bin/chmod/chmod.1 Mon Oct 22 17:47:06 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: chmod.1,v 1.23 2010/01/22 05:41:36 snj Exp $
+.\" $NetBSD: chmod.1,v 1.24 2012/10/22 17:47:06 christos Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" @(#)chmod.1 8.4 (Berkeley) 3/31/94
.\"
-.Dd January 22, 2010
+.Dd October 22, 2012
.Dt CHMOD 1
.Os
.Sh NAME
@@ -47,13 +47,26 @@
.Op Fl fh
.Ar mode
.Ar
+.Nm
+.Oo
+.Fl R
+.Op Fl H | Fl L | Fl P
+.Oc
+.Op Fl fh
+.Fl Fl reference=rfile
+.Ar
.Sh DESCRIPTION
The
.Nm
utility modifies the file mode bits of the listed files
as specified by the
.Ar mode
-operand.
+operand, or
+copied from a reference
+.Ar rfile ,
+as specified with the
+.Fl Fl reference
+argument.
.Pp
The options are as follows:
.Bl -tag -width Ds
diff -r 4a16c6aac31a -r e135e11e80fb bin/chmod/chmod.c
--- a/bin/chmod/chmod.c Mon Oct 22 16:43:05 2012 +0000
+++ b/bin/chmod/chmod.c Mon Oct 22 17:47:06 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: chmod.c,v 1.36 2011/08/29 14:51:17 joerg Exp $ */
+/* $NetBSD: chmod.c,v 1.37 2012/10/22 17:47:06 christos Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)chmod.c 8.8 (Berkeley) 4/1/94";
#else
-__RCSID("$NetBSD: chmod.c,v 1.36 2011/08/29 14:51:17 joerg Exp $");
+__RCSID("$NetBSD: chmod.c,v 1.37 2012/10/22 17:47:06 christos Exp $");
#endif
#endif /* not lint */
@@ -57,25 +57,39 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <getopt.h>
__dead static void usage(void);
+struct option chmod_longopts[] = {
+ { "reference", required_argument, 0,
+ 1 },
+ { NULL, 0, 0,
+ 0 },
+};
+
int
main(int argc, char *argv[])
{
FTS *ftsp;
FTSENT *p;
- mode_t *set;
+ void *set;
+ mode_t mval;
int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval;
- char *mode;
+ char *mode, *reference;
int (*change_mode)(const char *, mode_t);
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
Hflag = Lflag = Rflag = fflag = hflag = 0;
- while ((ch = getopt(argc, argv, "HLPRXfghorstuwx")) != -1)
+ reference = NULL;
+ while ((ch = getopt_long(argc, argv, "HLPRXfghorstuwx",
+ chmod_longopts, NULL)) != -1)
switch (ch) {
+ case 1:
+ reference = optarg;
+ break;
case 'H':
Hflag = 1;
Lflag = 0;
@@ -124,7 +138,7 @@
done: argv += optind;
argc -= optind;
- if (argc < 2)
+ if (argc < 2 && (argc < 1 && reference == NULL))
usage();
fts_options = FTS_PHYSICAL;
@@ -147,13 +161,23 @@
else
change_mode = chmod;
- mode = *argv;
- if ((set = setmode(mode)) == NULL) {
- err(EXIT_FAILURE, "Cannot set file mode `%s'", mode);
- /* NOTREACHED */
+ if (reference == NULL) {
+ mode = *argv++;
+ if ((set = setmode(mode)) == NULL) {
+ err(EXIT_FAILURE, "Cannot set file mode `%s'", mode);
+ /* NOTREACHED */
+ }
+ mval = 0;
+ } else {
+ struct stat st;
+
+ if (stat(reference, &st) == -1)
+ err(EXIT_FAILURE, "Cannot stat `%s'", reference);
+ mval = st.st_mode;
+ set = NULL;
}
- if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL) {
+ if ((ftsp = fts_open(argv, fts_options, 0)) == NULL) {
err(EXIT_FAILURE, "fts_open");
/* NOTREACHED */
}
@@ -189,7 +213,8 @@
break;
}
if ((*change_mode)(p->fts_accpath,
- getmode(set, p->fts_statp->st_mode)) && !fflag) {
+ set ? getmode(set, p->fts_statp->st_mode) : mval)
+ && !fflag) {
warn("%s", p->fts_path);
rval = 1;
}
@@ -206,8 +231,9 @@
usage(void)
{
(void)fprintf(stderr,
- "usage: %s [-R [-H | -L | -P]] [-fh] mode file ...\n",
- getprogname());
+ "Usage: %s [-R [-H | -L | -P]] [-fh] mode file ...\n"
+ "\t%s [-R [-H | -L | -P]] [-fh] --reference=rfile file ...\n",
+ getprogname(), getprogname());
exit(1);
/* NOTREACHED */
}
Home |
Main Index |
Thread Index |
Old Index