diff options
author | wosch <wosch@FreeBSD.org> | 1996-03-08 06:58:08 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1996-03-08 06:58:08 +0000 |
commit | b149de385358aae454e84aaa2ae0182793af8c2b (patch) | |
tree | 0181aa2ba8a9c3b8c895b9eb57d4f15b2bfb8a56 /bin/cp/utils.c | |
parent | 4ce0328b770359966fa9f49ac04f6ee8f1c9d235 (diff) | |
download | FreeBSD-src-b149de385358aae454e84aaa2ae0182793af8c2b.zip FreeBSD-src-b149de385358aae454e84aaa2ae0182793af8c2b.tar.gz |
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
Diffstat (limited to 'bin/cp/utils.c')
-rw-r--r-- | bin/cp/utils.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c index e77140e..62e208b 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -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); } |