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 | |
ce478bb7 | 12 | static char sccsid[] = "@(#)delete.c 5.6 (Berkeley) %G%"; |
c43c747e KB |
13 | #endif /* not lint */ |
14 | ||
15 | #include <sys/param.h> | |
16 | #include <sys/stat.h> | |
17 | #include <fcntl.h> | |
c43c747e | 18 | #include <dirent.h> |
1337a6b8 | 19 | #include <unistd.h> |
c43c747e KB |
20 | #include <stdio.h> |
21 | #include <ar.h> | |
22 | #include "archive.h" | |
1337a6b8 | 23 | #include "extern.h" |
c43c747e KB |
24 | #include "pathnames.h" |
25 | ||
26 | extern CHDR chdr; /* converted header */ | |
27 | extern char *archive; /* archive name */ | |
28 | extern char *tname; /* temporary file "name" */ | |
29 | ||
30 | /*- | |
31 | * delete -- | |
32 | * Deletes named members from the archive. | |
33 | */ | |
34 | delete(argv) | |
35 | register char **argv; | |
36 | { | |
37 | CF cf; | |
38 | off_t size; | |
1337a6b8 | 39 | int afd, tfd; |
af52bb8a | 40 | char *file; |
c43c747e KB |
41 | |
42 | afd = open_archive(O_RDWR); | |
43 | tfd = tmp(); | |
44 | ||
9fb190f7 | 45 | /* Read and write to an archive; pad on both. */ |
c43c747e | 46 | SETCF(afd, archive, tfd, tname, RPAD|WPAD); |
ce478bb7 | 47 | while (get_arobj(afd)) { |
1337a6b8 | 48 | if (*argv && (file = files(argv))) { |
c43c747e | 49 | if (options & AR_V) |
af52bb8a | 50 | (void)printf("d - %s\n", file); |
ce478bb7 | 51 | skip_arobj(afd); |
c43c747e KB |
52 | continue; |
53 | } | |
ce478bb7 | 54 | put_arobj(&cf, (struct stat *)NULL); |
c43c747e | 55 | } |
c43c747e KB |
56 | |
57 | size = lseek(tfd, (off_t)0, SEEK_CUR); | |
58 | (void)lseek(tfd, (off_t)0, SEEK_SET); | |
59 | (void)lseek(afd, (off_t)SARMAG, SEEK_SET); | |
9fb190f7 | 60 | SETCF(tfd, tname, afd, archive, NOPAD); |
ce478bb7 | 61 | copy_ar(&cf, size); |
c43c747e KB |
62 | (void)close(tfd); |
63 | (void)ftruncate(afd, size + SARMAG); | |
64 | close_archive(afd); | |
1337a6b8 KB |
65 | |
66 | if (*argv) { | |
67 | orphans(argv); | |
68 | return(1); | |
69 | } | |
70 | return(0); | |
c43c747e | 71 | } |