diff options
author | denny <denny@cvs.openbsd.org> | 1997-08-19 07:22:10 +0000 |
---|---|---|
committer | denny <denny@cvs.openbsd.org> | 1997-08-19 07:22:10 +0000 |
commit | 5636ae65e281a9203f2d79f2a6d510922eaf9d67 (patch) | |
tree | 312208254a98ec981aa2ca761e7f6c259319a12e /usr.bin | |
parent | 3ac409032d84b75bb4f005012d89cd8043059d3e (diff) |
Add -C to not overwrite existing files when extracting (part of POSIX 1003.2)
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ar/ar.c | 11 | ||||
-rw-r--r-- | usr.bin/ar/archive.h | 3 | ||||
-rw-r--r-- | usr.bin/ar/extract.c | 25 |
3 files changed, 27 insertions, 12 deletions
diff --git a/usr.bin/ar/ar.c b/usr.bin/ar/ar.c index a6da84ff8de..32ca26cf82e 100644 --- a/usr.bin/ar/ar.c +++ b/usr.bin/ar/ar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ar.c,v 1.3 1997/01/15 23:42:11 millert Exp $ */ +/* $OpenBSD: ar.c,v 1.4 1997/08/19 07:22:08 denny Exp $ */ /* $NetBSD: ar.c,v 1.5 1995/03/26 03:27:44 glass Exp $ */ /*- @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ar.c 8.3 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: ar.c,v 1.3 1997/01/15 23:42:11 millert Exp $"; +static char rcsid[] = "$OpenBSD: ar.c,v 1.4 1997/08/19 07:22:08 denny Exp $"; #endif #endif /* not lint */ @@ -101,7 +101,7 @@ main(argc, argv) argv[1] = p; } - while ((c = getopt(argc, argv, "abcdilmopqrTtuvx")) != -1) { + while ((c = getopt(argc, argv, "abcCdilmopqrTtuvx")) != -1) { switch(c) { case 'a': options |= AR_A; @@ -113,6 +113,9 @@ main(argc, argv) case 'c': options |= AR_C; break; + case 'C': + options |= AR_CC; + break; case 'd': options |= AR_D; fcall = delete; @@ -201,7 +204,7 @@ main(argc, argv) if (options & AR_T && options & ~(AR_T|AR_TR|AR_V)) badoptions("-t"); /* -x only valid with -ouTv. */ - if (options & AR_X && options & ~(AR_O|AR_U|AR_TR|AR_V|AR_X)) + if (options & AR_X && options & ~(AR_O|AR_U|AR_TR|AR_V|AR_X|AR_CC)) badoptions("-x"); if (!(archive = *argv++)) { diff --git a/usr.bin/ar/archive.h b/usr.bin/ar/archive.h index 1ba81c2fab3..cdaaeb26bc7 100644 --- a/usr.bin/ar/archive.h +++ b/usr.bin/ar/archive.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archive.h,v 1.2 1996/06/26 05:31:18 deraadt Exp $ */ +/* $OpenBSD: archive.h,v 1.3 1997/08/19 07:22:08 denny Exp $ */ /* $NetBSD: archive.h,v 1.6 1995/03/25 06:39:43 glass Exp $ */ /*- @@ -54,6 +54,7 @@ #define AR_U 0x0800 #define AR_V 0x1000 #define AR_X 0x2000 +#define AR_CC 0x4000 extern u_int options; /* Set up file copy. */ diff --git a/usr.bin/ar/extract.c b/usr.bin/ar/extract.c index 9943633f831..598e0984652 100644 --- a/usr.bin/ar/extract.c +++ b/usr.bin/ar/extract.c @@ -1,4 +1,4 @@ -/* $OpenBSD: extract.c,v 1.3 1997/05/31 08:17:33 deraadt Exp $ */ +/* $OpenBSD: extract.c,v 1.4 1997/08/19 07:22:09 denny Exp $ */ /* $NetBSD: extract.c,v 1.5 1995/03/26 03:27:53 glass Exp $ */ /*- @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)extract.c 8.3 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: extract.c,v 1.3 1997/05/31 08:17:33 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: extract.c,v 1.4 1997/08/19 07:22:09 denny Exp $"; #endif #endif /* not lint */ @@ -96,11 +96,22 @@ extract(argv) sb.st_mtime > chdr.date) continue; - if ((tfd = open(file, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR)) < 0) { - warn("%s", file); - skip_arobj(afd); - eval = 1; - continue; + if (options & AR_CC) { + /* -C means do not overwrite existing files */ + if ((tfd = open(file, O_WRONLY|O_CREAT|O_EXCL, + S_IWUSR)) < 0) { + skip_arobj(afd); + eval = 1; + continue; + } + } else { + if ((tfd = open(file, O_WRONLY|O_CREAT|O_TRUNC, + S_IWUSR)) < 0) { + warn("%s", file); + skip_arobj(afd); + eval = 1; + continue; + } } if (options & AR_V) |