[Midnightbsd-cvs] src: bin/cp: Syncronize some changes with FreeBSD.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Jun 29 22:20:01 EDT 2008
Log Message:
-----------
Syncronize some changes with FreeBSD.
Make -a map to -RpP
prevent statistics from overflowing, avoid division by zero, etc.
hold copied counter in off_t
Update man page with some of these changes.
Report any bugs to me with this change.
Modified Files:
--------------
src/bin/cp:
cp.1 (r1.3 -> r1.4)
cp.c (r1.4 -> r1.5)
utils.c (r1.3 -> r1.4)
-------------- next part --------------
Index: cp.1
===================================================================
RCS file: /home/cvs/src/bin/cp/cp.1,v
retrieving revision 1.3
retrieving revision 1.4
diff -L bin/cp/cp.1 -L bin/cp/cp.1 -u -r1.3 -r1.4
--- bin/cp/cp.1
+++ bin/cp/cp.1
@@ -33,7 +33,7 @@
.\" $FreeBSD: src/bin/cp/cp.1,v 1.33 2005/02/25 00:40:46 trhodes Exp $
.\" $MidnightBSD$
.\"
-.Dd February 23, 2005
+.Dd June 29, 2008
.Dt CP 1
.Os
.Sh NAME
@@ -149,6 +149,8 @@
or
.Fl n
options.)
+.It Fl l
+Create hard links to regular files in a hierarchy instead of copying.
.It Fl n
Do not overwrite an existing file.
(The
Index: cp.c
===================================================================
RCS file: /home/cvs/src/bin/cp/cp.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -L bin/cp/cp.c -L bin/cp/cp.c -u -r1.4 -r1.5
--- bin/cp/cp.c
+++ bin/cp/cp.c
@@ -104,7 +104,7 @@
char *target;
Hflag = Lflag = Pflag = 0;
- while ((ch = getopt(argc, argv, "HLPRfinprvla")) != -1)
+ while ((ch = getopt(argc, argv, "HLPRfafilnprv")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -137,7 +137,8 @@
pflag = 1;
break;
case 'r':
- rflag = 1;
+ rflag = Lflag = 1;
+ Hflag = Pflag = 0;
break;
case 'v':
vflag = 1;
@@ -162,16 +163,10 @@
usage();
fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
- if (rflag) {
- if (Rflag)
- errx(1,
- "the -R and -r options may not be specified together.");
- if (Hflag || Lflag || Pflag)
- errx(1,
- "the -H, -L, and -P options may not be specified with the -r option.");
- fts_options &= ~FTS_PHYSICAL;
- fts_options |= FTS_LOGICAL;
- }
+ if (Rflag && rflag)
+ errx(1, "the -R and -r options may not be specified together.");
+ if (rflag)
+ Rflag = 1;
if (Rflag) {
if (Hflag)
fts_options |= FTS_COMFOLLOW;
@@ -223,10 +218,8 @@
/*
* Case (1). Target is not a directory.
*/
- if (argc > 1) {
- usage();
- exit(1);
- }
+ if (argc > 1)
+ errx(1, "%s is not a directory", to.p_path);
/*
* Need to detect the case:
* cp -R dir foo
@@ -235,12 +228,12 @@
* the initial mkdir().
*/
if (r == -1) {
- if (rflag || (Rflag && (Lflag || Hflag)))
+ if (Rflag && (Lflag || Hflag))
stat(*argv, &tmp_stat);
else
lstat(*argv, &tmp_stat);
- if (S_ISDIR(tmp_stat.st_mode) && (Rflag || rflag))
+ if (S_ISDIR(tmp_stat.st_mode) && Rflag)
type = DIR_TO_DNE;
else
type = FILE_TO_FILE;
@@ -428,7 +421,7 @@
}
break;
case S_IFDIR:
- if (!Rflag && !rflag) {
+ if (!Rflag) {
warnx("%s is a directory (not copied).",
curr->fts_path);
(void)fts_set(ftsp, curr, FTS_SKIP);
Index: utils.c
===================================================================
RCS file: /home/cvs/src/bin/cp/utils.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L bin/cp/utils.c -L bin/cp/utils.c -u -r1.3 -r1.4
--- bin/cp/utils.c
+++ bin/cp/utils.c
@@ -56,7 +56,8 @@
#include <unistd.h>
#include "extern.h"
-#define cp_pct(x,y) (int)(100.0 * (double)(x) / (double)(y))
+
+#define cp_pct(x,y) ((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
int
copy_file(const FTSENT *entp, int dne)
@@ -66,7 +67,7 @@
int ch, checkch, from_fd = 0, rcount, rval, to_fd = 0;
ssize_t wcount;
size_t wresid;
- size_t wtotal;
+ off_t wtotal;
char *bufp;
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
char *p;
@@ -151,6 +152,8 @@
for (bufp = p, wresid = fs->st_size; ;
bufp += wcount, wresid -= (size_t)wcount) {
wcount = write(to_fd, bufp, wresid);
+ if (wcount <= 0)
+ break;
wtotal += wcount;
if (info) {
info = 0;
@@ -160,7 +163,7 @@
cp_pct(wtotal, fs->st_size));
}
- if (wcount >= (ssize_t)wresid || wcount <= 0)
+ if (wcount >= (ssize_t)wresid)
break;
}
if (wcount != (ssize_t)wresid) {
@@ -181,6 +184,8 @@
for (bufp = buf, wresid = rcount; ;
bufp += wcount, wresid -= wcount) {
wcount = write(to_fd, bufp, wresid);
+ if (wcount <= 0)
+ break;
wtotal += wcount;
if (info) {
info = 0;
@@ -190,7 +195,7 @@
cp_pct(wtotal, fs->st_size));
}
- if (wcount >= (ssize_t)wresid || wcount <= 0)
+ if (wcount >= (ssize_t)wresid)
break;
}
if (wcount != (ssize_t)wresid) {
@@ -428,8 +433,8 @@
{
(void)fprintf(stderr, "%s\n%s\n",
-"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-aplv] source_file target_file",
-" cp [-R [-H | -L | -P]] [-f | -i | -n] [-aplv] source_file ... "
+"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file target_file",
+" cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file ... "
"target_directory");
exit(EX_USAGE);
}
More information about the Midnightbsd-cvs
mailing list