Commit | Line | Data |
---|---|---|
c43c747e KB |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
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 | |
af52bb8a | 12 | static char sccsid[] = "@(#)delete.c 5.4 (Berkeley) %G%"; |
c43c747e KB |
13 | #endif /* not lint */ |
14 | ||
15 | #include <sys/param.h> | |
16 | #include <sys/stat.h> | |
17 | #include <fcntl.h> | |
18 | #include <unistd.h> | |
19 | #include <dirent.h> | |
20 | #include <stdio.h> | |
21 | #include <ar.h> | |
22 | #include "archive.h" | |
23 | #include "pathnames.h" | |
24 | ||
25 | extern CHDR chdr; /* converted header */ | |
26 | extern char *archive; /* archive name */ | |
27 | extern char *tname; /* temporary file "name" */ | |
28 | ||
29 | /*- | |
30 | * delete -- | |
31 | * Deletes named members from the archive. | |
32 | */ | |
33 | delete(argv) | |
34 | register char **argv; | |
35 | { | |
36 | CF cf; | |
37 | off_t size; | |
38 | int afd, eval, 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 KB |
45 | SETCF(afd, archive, tfd, tname, RPAD|WPAD); |
46 | while (get_header(afd)) { | |
af52bb8a | 47 | if ((file = *argv) && files(argv)) { |
c43c747e | 48 | if (options & AR_V) |
af52bb8a | 49 | (void)printf("d - %s\n", file); |
9fb190f7 | 50 | skipobj(afd); |
c43c747e KB |
51 | continue; |
52 | } | |
9fb190f7 | 53 | put_object(&cf, (struct stat *)NULL); |
c43c747e | 54 | } |
44c5e2d6 | 55 | eval = 0; |
c43c747e KB |
56 | ORPHANS; |
57 | ||
58 | size = lseek(tfd, (off_t)0, SEEK_CUR); | |
59 | (void)lseek(tfd, (off_t)0, SEEK_SET); | |
60 | (void)lseek(afd, (off_t)SARMAG, SEEK_SET); | |
9fb190f7 | 61 | SETCF(tfd, tname, afd, archive, NOPAD); |
c43c747e KB |
62 | copyfile(&cf, size); |
63 | (void)close(tfd); | |
64 | (void)ftruncate(afd, size + SARMAG); | |
65 | close_archive(afd); | |
66 | return(eval); | |
67 | } |