summaryrefslogtreecommitdiffstats
path: root/bin/cp/utils.c
diff options
context:
space:
mode:
authorwosch <wosch@FreeBSD.org>1996-02-18 18:48:26 +0000
committerwosch <wosch@FreeBSD.org>1996-02-18 18:48:26 +0000
commitef875dfa9a1d918f8cf335f5de089dc8f80c2c3d (patch)
tree569e3fbc5a0cf8ea503fd2a89bf725746085b2b9 /bin/cp/utils.c
parentca465af3df8c4e6f751237d66fc017487093bb12 (diff)
downloadFreeBSD-src-ef875dfa9a1d918f8cf335f5de089dc8f80c2c3d.zip
FreeBSD-src-ef875dfa9a1d918f8cf335f5de089dc8f80c2c3d.tar.gz
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
Diffstat (limited to 'bin/cp/utils.c')
-rw-r--r--bin/cp/utils.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index ca2d2c5..ca7017c 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.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
@@ -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);
}
OpenPOWER on IntegriCloud