| 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 |
| 12 | static char sccsid[] = "@(#)append.c 5.1 (Berkeley) %G%"; |
| 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> |
| 22 | #include "archive.h" |
| 23 | |
| 24 | extern char *archive; /* archive name */ |
| 25 | |
| 26 | /* |
| 27 | * append -- |
| 28 | * Append files to the archive - modifies original archive or creates |
| 29 | * a new archive if named archive does not exist. |
| 30 | */ |
| 31 | append(argv) |
| 32 | char **argv; |
| 33 | { |
| 34 | register int fd, afd; |
| 35 | register char *file; |
| 36 | struct stat sb; |
| 37 | CF cf; |
| 38 | int rval; |
| 39 | char *rname(); |
| 40 | |
| 41 | afd = open_archive(O_CREAT|O_RDWR); |
| 42 | if (lseek(afd, (off_t)0, SEEK_END) == (off_t)-1) |
| 43 | error(archive); |
| 44 | |
| 45 | SETCF(0, 0, afd, archive, WPAD); |
| 46 | while (file = *argv++) { |
| 47 | if ((fd = open(file, O_RDONLY)) < 0) { |
| 48 | (void)fprintf(stderr, |
| 49 | "ar: %s: %s.\n", file, strerror(errno)); |
| 50 | rval = 1; |
| 51 | continue; |
| 52 | } |
| 53 | if (options & AR_V) |
| 54 | (void)printf("q - %s\n", rname(file)); |
| 55 | cf.rfd = fd; |
| 56 | cf.rname = file; |
| 57 | put_header(&cf, &sb); |
| 58 | copyfile(&cf, sb.st_size); |
| 59 | (void)close(fd); |
| 60 | } |
| 61 | close_archive(afd); |
| 62 | return(rval); |
| 63 | } |