Date: Sun, 22 Dec 2002 00:35:34 +0900 From: "Akinori MUSHA" <knu@iDaemons.org> To: audit@FreeBSD.org Subject: cp -l Message-ID: <86lm2jjsft.wl@archon.local.idaemons.org>
next in thread | raw e-mail | index | archive | help
Hi,
What about cp -l a la GNU cp?
--
/
/__ __ Akinori.org / MUSHA.org
/ ) ) ) ) / FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp
"I believe in what I see, I believe in what I hear,
I believe that what I'm feeling changes how the world appears."
Index: cp.1
===================================================================
RCS file: /home/ncvs/src/bin/cp/cp.1,v
retrieving revision 1.25
diff -u -r1.25 cp.1
--- cp.1 16 Aug 2002 03:13:59 -0000 1.25
+++ cp.1 16 Nov 2002 22:37:38 -0000
@@ -48,7 +48,7 @@
.Op Fl H | Fl L | Fl P
.Oc
.Op Fl f | i | n
-.Op Fl pv
+.Op Fl lpv
.Ar source_file target_file
.Nm
.Oo
@@ -56,7 +56,7 @@
.Op Fl H | Fl L | Fl P
.Oc
.Op Fl f | i | n
-.Op Fl pv
+.Op Fl lpv
.Ar source_file ... target_directory
.Sh DESCRIPTION
In the first synopsis form, the
@@ -141,6 +141,8 @@
or
.Fl n
options.)
+.It Fl l
+Link files instead of copying.
.It Fl n
Do not overwrite an existing file.
(The
@@ -238,7 +240,8 @@
or fifo's.
.Pp
The
-.Fl v
+.Fl v ,
+.Fl l
and
.Fl n
options are non-standard and their use in scripts is not recommended.
Index: cp.c
===================================================================
RCS file: /home/ncvs/src/bin/cp/cp.c,v
retrieving revision 1.43
diff -u -r1.43 cp.c
--- cp.c 18 Oct 2002 14:44:59 -0000 1.43
+++ cp.c 16 Nov 2002 22:20:46 -0000
@@ -86,7 +86,7 @@
PATH_T to = { to.p_path, emptystring, "" };
-int fflag, iflag, nflag, pflag, vflag;
+int fflag, iflag, lflag, nflag, pflag, vflag;
static int Rflag, rflag;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@@ -103,7 +103,7 @@
char *target;
Hflag = Lflag = Pflag = 0;
- while ((ch = getopt(argc, argv, "HLPRfinprv")) != -1)
+ while ((ch = getopt(argc, argv, "HLPRfilnprv")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -127,6 +127,9 @@
case 'i':
iflag = 1;
fflag = nflag = 0;
+ break;
+ case 'l':
+ lflag = 1;
break;
case 'n':
nflag = 1;
Index: extern.h
===================================================================
RCS file: /home/ncvs/src/bin/cp/extern.h,v
retrieving revision 1.16
diff -u -r1.16 extern.h
--- extern.h 18 Oct 2002 14:44:59 -0000 1.16
+++ extern.h 16 Nov 2002 22:20:39 -0000
@@ -41,7 +41,7 @@
} PATH_T;
extern PATH_T to;
-extern int fflag, iflag, nflag, pflag, vflag;
+extern int fflag, iflag, lflag, nflag, pflag, vflag;
__BEGIN_DECLS
int copy_fifo(struct stat *, int);
Index: utils.c
===================================================================
RCS file: /home/ncvs/src/bin/cp/utils.c,v
retrieving revision 1.39
diff -u -r1.39 utils.c
--- utils.c 18 Oct 2002 14:45:00 -0000 1.39
+++ utils.c 17 Nov 2002 05:32:26 -0000
@@ -70,7 +70,9 @@
char *p;
#endif
- if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
+ if (lflag)
+ from_fd = -1;
+ else if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
warn("%s", entp->fts_path);
return (1);
}
@@ -104,24 +106,35 @@
}
}
- if (fflag) {
+ if (fflag || lflag) {
/* remove existing destination file name,
* create a new file */
(void)unlink(to.p_path);
- to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
- fs->st_mode & ~(S_ISUID | S_ISGID));
+ if (lflag)
+ to_fd = link(entp->fts_path, to.p_path);
+ else
+ to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
+ fs->st_mode & ~(S_ISUID | S_ISGID));
} else
/* overwrite existing destination file name */
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
- } else
- to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
- fs->st_mode & ~(S_ISUID | S_ISGID));
+ } else {
+ if (lflag)
+ to_fd = link(entp->fts_path, to.p_path);
+ else
+ to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
+ fs->st_mode & ~(S_ISUID | S_ISGID));
+ }
if (to_fd == -1) {
warn("%s", to.p_path);
- (void)close(from_fd);
+ if (from_fd != -1)
+ (void)close(from_fd);
return (1);
}
+
+ if (lflag)
+ return 0;
rval = 0;
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86lm2jjsft.wl>
