1 /*- 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. 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 8.1 (Berkeley) 06/06/93"; 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 <string.h> 23 #include "archive.h" 24 #include "extern.h" 25 26 extern 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 */ 33 append(argv) 34 char **argv; 35 { 36 register int fd, afd; 37 register char *file; 38 struct stat sb; 39 CF cf; 40 int eval; 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 46 /* Read from disk, write to an archive; pad on write. */ 47 SETCF(0, 0, afd, archive, WPAD); 48 for (eval = 0; file = *argv++;) { 49 if ((fd = open(file, O_RDONLY)) < 0) { 50 (void)fprintf(stderr, 51 "ar: %s: %s.\n", file, strerror(errno)); 52 eval = 1; 53 continue; 54 } 55 if (options & AR_V) 56 (void)printf("q - %s\n", file); 57 cf.rfd = fd; 58 cf.rname = file; 59 put_arobj(&cf, &sb); 60 (void)close(fd); 61 } 62 close_archive(afd); 63 return(eval); 64 } 65