Commit | Line | Data |
---|---|---|
c43c747e | 1 | /*- |
4e6c9859 KB |
2 | * Copyright (c) 1990, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
c43c747e KB |
4 | * |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Hugh Smith at The University of Guelph. | |
7 | * | |
8 | * %sccs.include.redist.c% | |
9 | */ | |
10 | ||
11 | #ifndef lint | |
706c0358 | 12 | static char sccsid[] = "@(#)delete.c 8.2 (Berkeley) %G%"; |
c43c747e KB |
13 | #endif /* not lint */ |
14 | ||
15 | #include <sys/param.h> | |
16 | #include <sys/stat.h> | |
706c0358 JSP |
17 | |
18 | #include <ar.h> | |
c43c747e | 19 | #include <dirent.h> |
706c0358 | 20 | #include <fcntl.h> |
c43c747e | 21 | #include <stdio.h> |
706c0358 JSP |
22 | #include <unistd.h> |
23 | ||
c43c747e | 24 | #include "archive.h" |
1337a6b8 | 25 | #include "extern.h" |
c43c747e KB |
26 | #include "pathnames.h" |
27 | ||
c43c747e KB |
28 | /*- |
29 | * delete -- | |
30 | * Deletes named members from the archive. | |
31 | */ | |
706c0358 | 32 | int |
c43c747e | 33 | delete(argv) |
706c0358 | 34 | char **argv; |
c43c747e KB |
35 | { |
36 | CF cf; | |
37 | off_t size; | |
1337a6b8 | 38 | int afd, tfd; |
af52bb8a | 39 | char *file; |
c43c747e KB |
40 | |
41 | afd = open_archive(O_RDWR); | |
42 | tfd = tmp(); | |
43 | ||
9fb190f7 | 44 | /* Read and write to an archive; pad on both. */ |
c43c747e | 45 | SETCF(afd, archive, tfd, tname, RPAD|WPAD); |
ce478bb7 | 46 | while (get_arobj(afd)) { |
1337a6b8 | 47 | if (*argv && (file = files(argv))) { |
c43c747e | 48 | if (options & AR_V) |
af52bb8a | 49 | (void)printf("d - %s\n", file); |
ce478bb7 | 50 | skip_arobj(afd); |
c43c747e KB |
51 | continue; |
52 | } | |
ce478bb7 | 53 | put_arobj(&cf, (struct stat *)NULL); |
c43c747e | 54 | } |
c43c747e KB |
55 | |
56 | size = lseek(tfd, (off_t)0, SEEK_CUR); | |
57 | (void)lseek(tfd, (off_t)0, SEEK_SET); | |
58 | (void)lseek(afd, (off_t)SARMAG, SEEK_SET); | |
9fb190f7 | 59 | SETCF(tfd, tname, afd, archive, NOPAD); |
ce478bb7 | 60 | copy_ar(&cf, size); |
c43c747e KB |
61 | (void)close(tfd); |
62 | (void)ftruncate(afd, size + SARMAG); | |
63 | close_archive(afd); | |
1337a6b8 KB |
64 | |
65 | if (*argv) { | |
66 | orphans(argv); | |
706c0358 | 67 | return (1); |
1337a6b8 | 68 | } |
706c0358 | 69 | return (0); |
c43c747e | 70 | } |