1 /*-
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. 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
12 static char sccsid[] = "@(#)append.c 8.3 (Berkeley) 04/02/94";
13 #endif /* not lint */
14
15 #include <sys/param.h>
16 #include <sys/stat.h>
17
18 #include <err.h>
19 #include <fcntl.h>
20 #include <unistd.h>
21 #include <dirent.h>
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "archive.h"
26 #include "extern.h"
27
28 /*
29 * append --
30 * Append files to the archive - modifies original archive or creates
31 * a new archive if named archive does not exist.
32 */
33 int
append(argv)34 append(argv)
35 char **argv;
36 {
37 int afd, fd, eval;
38 char *file;
39 CF cf;
40 struct stat sb;
41
42 afd = open_archive(O_CREAT|O_RDWR);
43 if (lseek(afd, (off_t)0, SEEK_END) == (off_t)-1)
44 error(archive);
45
46 /* Read from disk, write to an archive; pad on write. */
47 SETCF(0, 0, afd, archive, WPAD);
48 for (eval = 0; file = *argv++;) {
49 if ((fd = open(file, O_RDONLY)) < 0) {
50 warn("%s", file);
51 eval = 1;
52 continue;
53 }
54 if (options & AR_V)
55 (void)printf("q - %s\n", file);
56 cf.rfd = fd;
57 cf.rname = file;
58 put_arobj(&cf, &sb);
59 (void)close(fd);
60 }
61 close_archive(afd);
62 return (eval);
63 }
64