Option -f implemented (remove + create)
option -f and -i are exclusive respond `Y' is equal to `y' fix usage string remove isatty(3) check Reviewed by: pst
This commit is contained in:
parent
cc494d0cce
commit
6add522f93
23
bin/cp/cp.1
23
bin/cp/cp.1
@ -33,7 +33,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)cp.1 8.3 (Berkeley) 4/18/94
|
||||
.\" $Id: cp.1,v 1.2 1994/09/24 02:53:40 davidg Exp $
|
||||
.\" $Id: cp.1,v 1.3 1996/02/18 18:48:24 wosch Exp $
|
||||
.\"
|
||||
.Dd April 18, 1994
|
||||
.Dt CP 1
|
||||
@ -47,14 +47,16 @@
|
||||
.Fl R
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Oc
|
||||
.Op Fl fip
|
||||
.Op Fl f | i
|
||||
.Op Fl p
|
||||
.Ar source_file target_file
|
||||
.Nm cp
|
||||
.Oo
|
||||
.Fl R
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Oc
|
||||
.Op Fl fip
|
||||
.Op Fl f | i
|
||||
.Op Fl p
|
||||
.Ar source_file ... target_directory
|
||||
.Sh DESCRIPTION
|
||||
In the first synopsis form, the
|
||||
@ -105,18 +107,25 @@ For each existing destination pathname, remove it and
|
||||
create a new file, without prompting for confirmation
|
||||
regardless of its permissions.
|
||||
(The
|
||||
.Fl i
|
||||
option is ignored if the
|
||||
.Fl f
|
||||
option is specified.)
|
||||
option overrides any previous
|
||||
.Fl i
|
||||
options.)
|
||||
.It Fl i
|
||||
Causes
|
||||
.Nm cp
|
||||
to write a prompt to the standard error output before copying a file
|
||||
that would overwrite an existing file.
|
||||
If the response from the standard input begins with the character
|
||||
.Sq Li y ,
|
||||
.Sq Li y
|
||||
or
|
||||
.Sq Li Y ,
|
||||
the file copy is attempted.
|
||||
(The
|
||||
.Fl i
|
||||
option overrides any previous
|
||||
.Fl f
|
||||
options.)
|
||||
.It Fl p
|
||||
Causes
|
||||
.Nm cp
|
||||
|
@ -33,7 +33,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: cp.c,v 1.8 1996/02/19 00:43:42 wosch Exp $
|
||||
* $Id: cp.c,v 1.9 1996/02/19 05:56:33 pst Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
@ -86,7 +86,7 @@ static char sccsid[] = "@(#)cp.c 8.2 (Berkeley) 4/1/94";
|
||||
PATH_T to = { to.p_path, "" };
|
||||
|
||||
uid_t myuid;
|
||||
int Rflag, iflag, pflag, rflag;
|
||||
int Rflag, iflag, pflag, rflag, fflag;
|
||||
int myumask;
|
||||
|
||||
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
||||
@ -123,10 +123,12 @@ main(argc, argv)
|
||||
Rflag = 1;
|
||||
break;
|
||||
case 'f':
|
||||
fflag = 1;
|
||||
iflag = 0;
|
||||
break;
|
||||
case 'i':
|
||||
iflag = isatty(fileno(stdin));
|
||||
iflag = 1;
|
||||
fflag = 0;
|
||||
break;
|
||||
case 'p':
|
||||
pflag = 1;
|
||||
|
@ -31,7 +31,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.2 (Berkeley) 4/1/94
|
||||
* $Id: extern.h,v 1.2 1994/09/24 02:53:41 davidg Exp $
|
||||
* $Id: extern.h,v 1.3 1996/02/18 18:48:26 wosch Exp $
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
@ -42,7 +42,7 @@ typedef struct {
|
||||
|
||||
extern PATH_T to;
|
||||
extern uid_t myuid;
|
||||
extern int iflag, pflag, myumask;
|
||||
extern int iflag, pflag, fflag, myumask;
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: utils.c,v 1.7 1996/02/19 00:43:44 wosch Exp $
|
||||
* $Id: utils.c,v 1.6 1996/02/18 18:48:26 wosch Exp wosch $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
@ -86,12 +86,21 @@ copy_file(entp, dne)
|
||||
checkch = ch = getchar();
|
||||
while (ch != '\n' && ch != EOF)
|
||||
ch = getchar();
|
||||
if (checkch != 'y') {
|
||||
if (checkch != 'y' && checkch != 'Y') {
|
||||
(void)close(from_fd);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
|
||||
|
||||
if (fflag) {
|
||||
/* 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));
|
||||
} 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));
|
||||
@ -281,7 +290,7 @@ void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "%s\n%s\n",
|
||||
"usage: cp [-R [-H | -L | -P]] [-fip] src target",
|
||||
" cp [-R [-H | -L | -P]] [-fip] src1 ... srcN directory");
|
||||
"usage: cp [-R [-H | -L | -P]] [-f | -i] [-p] src target",
|
||||
" cp [-R [-H | -L | -P]] [-f | -i] [-p] src1 ... srcN directory");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user