Annotation of src/usr.bin/ar/append.c, Revision 1.1.1.1
1.1 deraadt 1: /* $NetBSD: append.c,v 1.5 1995/03/26 03:27:37 glass Exp $ */
2:
3: /*-
4: * Copyright (c) 1990, 1993, 1994
5: * The Regents of the University of California. All rights reserved.
6: *
7: * This code is derived from software contributed to Berkeley by
8: * Hugh Smith at The University of Guelph.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: */
38:
39: #ifndef lint
40: #if 0
41: static char sccsid[] = "@(#)append.c 8.3 (Berkeley) 4/2/94";
42: #else
43: static char rcsid[] = "$NetBSD: append.c,v 1.5 1995/03/26 03:27:37 glass Exp $";
44: #endif
45: #endif /* not lint */
46:
47: #include <sys/param.h>
48: #include <sys/stat.h>
49:
50: #include <err.h>
51: #include <fcntl.h>
52: #include <unistd.h>
53: #include <dirent.h>
54: #include <stdio.h>
55: #include <string.h>
56:
57: #include "archive.h"
58: #include "extern.h"
59:
60: /*
61: * append --
62: * Append files to the archive - modifies original archive or creates
63: * a new archive if named archive does not exist.
64: */
65: int
66: append(argv)
67: char **argv;
68: {
69: int afd, fd, eval;
70: char *file;
71: CF cf;
72: struct stat sb;
73:
74: afd = open_archive(O_CREAT|O_RDWR);
75: if (lseek(afd, (off_t)0, SEEK_END) == (off_t)-1)
76: error(archive);
77:
78: /* Read from disk, write to an archive; pad on write. */
79: SETCF(0, 0, afd, archive, WPAD);
80: for (eval = 0; file = *argv++;) {
81: if ((fd = open(file, O_RDONLY)) < 0) {
82: warn("%s", file);
83: eval = 1;
84: continue;
85: }
86: if (options & AR_V)
87: (void)printf("q - %s\n", file);
88: cf.rfd = fd;
89: cf.rname = file;
90: put_arobj(&cf, &sb);
91: (void)close(fd);
92: }
93: close_archive(afd);
94: return (eval);
95: }