145990Sbostic /*-
2*66645Spendry * Copyright (c) 1990, 1993, 1994
361905Sbostic * The Regents of the University of California. All rights reserved.
445990Sbostic *
545990Sbostic * This code is derived from software contributed to Berkeley by
645990Sbostic * Hugh Smith at The University of Guelph.
745990Sbostic *
845990Sbostic * %sccs.include.redist.c%
945990Sbostic */
1045990Sbostic
1145990Sbostic #ifndef lint
12*66645Spendry static char sccsid[] = "@(#)append.c 8.3 (Berkeley) 04/02/94";
1345990Sbostic #endif /* not lint */
1445990Sbostic
1545990Sbostic #include <sys/param.h>
1645990Sbostic #include <sys/stat.h>
1766567Spendry
1866567Spendry #include <err.h>
1945990Sbostic #include <fcntl.h>
2045990Sbostic #include <unistd.h>
2145990Sbostic #include <dirent.h>
2245990Sbostic #include <stdio.h>
2347224Sbostic #include <string.h>
2466567Spendry
2545990Sbostic #include "archive.h"
2647224Sbostic #include "extern.h"
2745990Sbostic
2845990Sbostic /*
2945990Sbostic * append --
3045990Sbostic * Append files to the archive - modifies original archive or creates
3145990Sbostic * a new archive if named archive does not exist.
3245990Sbostic */
3366567Spendry int
append(argv)3445990Sbostic append(argv)
3545990Sbostic char **argv;
3645990Sbostic {
3766567Spendry int afd, fd, eval;
3866567Spendry char *file;
3966567Spendry CF cf;
4045990Sbostic struct stat sb;
4145990Sbostic
4245990Sbostic afd = open_archive(O_CREAT|O_RDWR);
4345990Sbostic if (lseek(afd, (off_t)0, SEEK_END) == (off_t)-1)
4445990Sbostic error(archive);
4545990Sbostic
4647196Sbostic /* Read from disk, write to an archive; pad on write. */
4745990Sbostic SETCF(0, 0, afd, archive, WPAD);
4847256Sbostic for (eval = 0; file = *argv++;) {
4945990Sbostic if ((fd = open(file, O_RDONLY)) < 0) {
5066567Spendry warn("%s", file);
5147256Sbostic eval = 1;
5245990Sbostic continue;
5345990Sbostic }
5445990Sbostic if (options & AR_V)
5547214Sbostic (void)printf("q - %s\n", file);
5645990Sbostic cf.rfd = fd;
5745990Sbostic cf.rname = file;
5847240Sbostic put_arobj(&cf, &sb);
5945990Sbostic (void)close(fd);
6045990Sbostic }
6145990Sbostic close_archive(afd);
6266567Spendry return (eval);
6345990Sbostic }
64