Option -f implemented (remove + create)
option -f and -i are exclusive all flag variables initialized with zero respond `Y' is equal to `y' update usage string
This commit is contained in:
parent
1efb053dc4
commit
d6ea04ccf4
23
bin/cp/cp.1
23
bin/cp/cp.1
@ -33,7 +33,7 @@
|
|||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" @(#)cp.1 8.3 (Berkeley) 4/18/94
|
.\" @(#)cp.1 8.3 (Berkeley) 4/18/94
|
||||||
.\" $Id$
|
.\" $Id: cp.1,v 1.2 1994/09/24 02:53:40 davidg Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd April 18, 1994
|
.Dd April 18, 1994
|
||||||
.Dt CP 1
|
.Dt CP 1
|
||||||
@ -47,14 +47,16 @@
|
|||||||
.Fl R
|
.Fl R
|
||||||
.Op Fl H | Fl L | Fl P
|
.Op Fl H | Fl L | Fl P
|
||||||
.Oc
|
.Oc
|
||||||
.Op Fl fip
|
.Op Fl f | i
|
||||||
|
.Op Fl p
|
||||||
.Ar source_file target_file
|
.Ar source_file target_file
|
||||||
.Nm cp
|
.Nm cp
|
||||||
.Oo
|
.Oo
|
||||||
.Fl R
|
.Fl R
|
||||||
.Op Fl H | Fl L | Fl P
|
.Op Fl H | Fl L | Fl P
|
||||||
.Oc
|
.Oc
|
||||||
.Op Fl fip
|
.Op Fl f | i
|
||||||
|
.Op Fl p
|
||||||
.Ar source_file ... target_directory
|
.Ar source_file ... target_directory
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
In the first synopsis form, the
|
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
|
create a new file, without prompting for confirmation
|
||||||
regardless of its permissions.
|
regardless of its permissions.
|
||||||
(The
|
(The
|
||||||
.Fl i
|
|
||||||
option is ignored if the
|
|
||||||
.Fl f
|
.Fl f
|
||||||
option is specified.)
|
option overrides any previous
|
||||||
|
.Fl i
|
||||||
|
options.)
|
||||||
.It Fl i
|
.It Fl i
|
||||||
Causes
|
Causes
|
||||||
.Nm cp
|
.Nm cp
|
||||||
to write a prompt to the standard error output before copying a file
|
to write a prompt to the standard error output before copying a file
|
||||||
that would overwrite an existing file.
|
that would overwrite an existing file.
|
||||||
If the response from the standard input begins with the character
|
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 file copy is attempted.
|
||||||
|
(The
|
||||||
|
.Fl i
|
||||||
|
option overrides any previous
|
||||||
|
.Fl f
|
||||||
|
options.)
|
||||||
.It Fl p
|
.It Fl p
|
||||||
Causes
|
Causes
|
||||||
.Nm cp
|
.Nm cp
|
||||||
|
11
bin/cp/cp.c
11
bin/cp/cp.c
@ -33,7 +33,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: cp.c,v 1.5 1995/04/02 00:49:16 bde Exp $
|
* $Id: cp.c,v 1.6 1995/05/30 00:06:21 rgrimes Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
@ -86,7 +86,7 @@ static char sccsid[] = "@(#)cp.c 8.2 (Berkeley) 4/1/94";
|
|||||||
PATH_T to = { to.p_path, "" };
|
PATH_T to = { to.p_path, "" };
|
||||||
|
|
||||||
uid_t myuid;
|
uid_t myuid;
|
||||||
int Rflag, iflag, pflag, rflag;
|
int Rflag, iflag, pflag, rflag, fflag;
|
||||||
int myumask;
|
int myumask;
|
||||||
|
|
||||||
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
||||||
@ -105,7 +105,8 @@ main(argc, argv)
|
|||||||
char *target;
|
char *target;
|
||||||
|
|
||||||
Hflag = Lflag = Pflag = Rflag = 0;
|
Hflag = Lflag = Pflag = Rflag = 0;
|
||||||
while ((ch = getopt(argc, argv, "HLPRfipr")) != EOF)
|
fflag = iflag = rflag = pflag = 0;
|
||||||
|
while ((ch = getopt(argc, argv, "HLPRfipr?")) != EOF)
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'H':
|
case 'H':
|
||||||
Hflag = 1;
|
Hflag = 1;
|
||||||
@ -124,9 +125,11 @@ main(argc, argv)
|
|||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
iflag = 0;
|
iflag = 0;
|
||||||
|
fflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
iflag = isatty(fileno(stdin));
|
iflag = isatty(STDIN_FILENO);
|
||||||
|
fflag = 0;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
pflag = 1;
|
pflag = 1;
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#)extern.h 8.2 (Berkeley) 4/1/94
|
* @(#)extern.h 8.2 (Berkeley) 4/1/94
|
||||||
* $Id$
|
* $Id: extern.h,v 1.2 1994/09/24 02:53:41 davidg Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -42,7 +42,7 @@ typedef struct {
|
|||||||
|
|
||||||
extern PATH_T to;
|
extern PATH_T to;
|
||||||
extern uid_t myuid;
|
extern uid_t myuid;
|
||||||
extern int iflag, pflag, myumask;
|
extern int iflag, pflag, fflag, myumask;
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: utils.c,v 1.4 1995/06/14 05:41:27 bde Exp $
|
* $Id: utils.c,v 1.5 1995/10/03 12:55:01 bde Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
@ -86,12 +86,21 @@ copy_file(entp, dne)
|
|||||||
checkch = ch = getchar();
|
checkch = ch = getchar();
|
||||||
while (ch != '\n' && ch != EOF)
|
while (ch != '\n' && ch != EOF)
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
if (checkch != 'y') {
|
if (checkch != 'y' && checkch != 'Y') {
|
||||||
(void)close(from_fd);
|
(void)close(from_fd);
|
||||||
return (0);
|
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
|
} else
|
||||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
|
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
|
||||||
fs->st_mode & ~(S_ISUID | S_ISGID));
|
fs->st_mode & ~(S_ISUID | S_ISGID));
|
||||||
@ -281,7 +290,7 @@ void
|
|||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr, "%s\n%s\n",
|
(void)fprintf(stderr, "%s\n%s\n",
|
||||||
"usage: cp [-R [-H | -L | -P] [-fip] src target",
|
"usage: cp [-R [-H | -L | -P] [-f | -i] [-p] src target",
|
||||||
" cp [-R [-H | -L | -P] [-fip] src1 ... srcN directory");
|
" cp [-R [-H | -L | -P] [-f | -i] [-p] src1 ... srcN directory");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user