4.4BSD snapshot (revision 8.1)
[unix-history] / usr / src / usr.bin / ar / append.c
CommitLineData
3971cf43
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
1161a8a6 12static char sccsid[] = "@(#)append.c 5.6 (Berkeley) %G%";
3971cf43
KB
13#endif /* not lint */
14
15#include <sys/param.h>
16#include <sys/stat.h>
17#include <sys/errno.h>
18#include <fcntl.h>
19#include <unistd.h>
20#include <dirent.h>
21#include <stdio.h>
755759c7 22#include <string.h>
3971cf43 23#include "archive.h"
755759c7 24#include "extern.h"
3971cf43
KB
25
26extern char *archive; /* archive name */
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 */
33append(argv)
34 char **argv;
35{
36 register int fd, afd;
37 register char *file;
38 struct stat sb;
39 CF cf;
1161a8a6 40 int eval;
3971cf43
KB
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
ff7a74c0 46 /* Read from disk, write to an archive; pad on write. */
3971cf43 47 SETCF(0, 0, afd, archive, WPAD);
1161a8a6 48 for (eval = 0; file = *argv++;) {
3971cf43
KB
49 if ((fd = open(file, O_RDONLY)) < 0) {
50 (void)fprintf(stderr,
51 "ar: %s: %s.\n", file, strerror(errno));
1161a8a6 52 eval = 1;
3971cf43
KB
53 continue;
54 }
55 if (options & AR_V)
af52bb8a 56 (void)printf("q - %s\n", file);
3971cf43
KB
57 cf.rfd = fd;
58 cf.rname = file;
ce478bb7 59 put_arobj(&cf, &sb);
3971cf43
KB
60 (void)close(fd);
61 }
62 close_archive(afd);
1161a8a6 63 return(eval);
3971cf43 64}