prettyness police
[unix-history] / usr / src / usr.bin / ar / append.c
CommitLineData
3971cf43 1/*-
4e6c9859
KB
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
3971cf43
KB
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
706c0358 12static char sccsid[] = "@(#)append.c 8.2 (Berkeley) %G%";
3971cf43
KB
13#endif /* not lint */
14
15#include <sys/param.h>
16#include <sys/stat.h>
706c0358
JSP
17
18#include <err.h>
3971cf43
KB
19#include <fcntl.h>
20#include <unistd.h>
21#include <dirent.h>
22#include <stdio.h>
755759c7 23#include <string.h>
706c0358 24
3971cf43 25#include "archive.h"
755759c7 26#include "extern.h"
3971cf43 27
3971cf43
KB
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 */
706c0358 33int
3971cf43
KB
34append(argv)
35 char **argv;
36{
706c0358
JSP
37 int afd, fd, eval;
38 char *file;
3971cf43 39 CF cf;
706c0358 40 struct stat sb;
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 49 if ((fd = open(file, O_RDONLY)) < 0) {
706c0358 50 warn("%s", file);
1161a8a6 51 eval = 1;
3971cf43
KB
52 continue;
53 }
54 if (options & AR_V)
af52bb8a 55 (void)printf("q - %s\n", file);
3971cf43
KB
56 cf.rfd = fd;
57 cf.rname = file;
ce478bb7 58 put_arobj(&cf, &sb);
3971cf43
KB
59 (void)close(fd);
60 }
61 close_archive(afd);
706c0358 62 return (eval);
3971cf43 63}