146000Sbostic /*- 2*61906Sbostic * Copyright (c) 1990, 1993 3*61906Sbostic * The Regents of the University of California. All rights reserved. 446000Sbostic * 546000Sbostic * This code is derived from software contributed to Berkeley by 646000Sbostic * Hugh Smith at The University of Guelph. 746000Sbostic * 846000Sbostic * %sccs.include.redist.c% 946000Sbostic */ 1046000Sbostic 1146000Sbostic #ifndef lint 12*61906Sbostic static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 06/06/93"; 1346000Sbostic #endif /* not lint */ 1446000Sbostic 1546000Sbostic #include <sys/param.h> 1646000Sbostic #include <sys/errno.h> 1747202Sbostic #include <signal.h> 1846000Sbostic #include <dirent.h> 1947202Sbostic #include <unistd.h> 2046000Sbostic #include <stdio.h> 2147230Sbostic #include <stdlib.h> 2247230Sbostic #include <string.h> 2347202Sbostic #include "archive.h" 2447230Sbostic #include "extern.h" 2546000Sbostic #include "pathnames.h" 2646000Sbostic 2746000Sbostic extern CHDR chdr; /* converted header */ 2846000Sbostic extern char *archive; /* archive name */ 2946000Sbostic char *tname = "temporary file"; /* temporary file "name" */ 3046000Sbostic 3146000Sbostic tmp() 3246000Sbostic { 3346000Sbostic extern char *envtmp; 3446000Sbostic sigset_t set, oset; 3546000Sbostic static int first; 3646000Sbostic int fd; 3746000Sbostic char path[MAXPATHLEN]; 3846000Sbostic 3946000Sbostic if (!first && !envtmp) { 4046000Sbostic envtmp = getenv("TMPDIR"); 4146000Sbostic first = 1; 4246000Sbostic } 4346000Sbostic 4446000Sbostic if (envtmp) 4546000Sbostic (void)sprintf(path, "%s/%s", envtmp, _NAME_ARTMP); 4646000Sbostic else 4746000Sbostic bcopy(_PATH_ARTMP, path, sizeof(_PATH_ARTMP)); 4846000Sbostic 4949893Sbostic sigfillset(&set); 5046000Sbostic (void)sigprocmask(SIG_BLOCK, &set, &oset); 5146000Sbostic if ((fd = mkstemp(path)) == -1) 5246000Sbostic error(tname); 5346000Sbostic (void)unlink(path); 5449893Sbostic (void)sigprocmask(SIG_SETMASK, &oset, NULL); 5546000Sbostic return(fd); 5646000Sbostic } 5746000Sbostic 5846000Sbostic /* 5946000Sbostic * files -- 6046000Sbostic * See if the current file matches any file in the argument list; if it 6146000Sbostic * does, remove it from the argument list. 6246000Sbostic */ 6347230Sbostic char * 6446000Sbostic files(argv) 6546000Sbostic char **argv; 6646000Sbostic { 6746000Sbostic register char **list; 6847230Sbostic char *p; 6946000Sbostic 7046000Sbostic for (list = argv; *list; ++list) 7146000Sbostic if (compare(*list)) { 7247230Sbostic p = *list; 7346000Sbostic for (; list[0] = list[1]; ++list); 7447230Sbostic return(p); 7546000Sbostic } 7647230Sbostic return(NULL); 7746000Sbostic } 7846000Sbostic 7947230Sbostic void 8047230Sbostic orphans(argv) 8147230Sbostic char **argv; 8247230Sbostic { 8347230Sbostic for (; *argv; ++argv) 8447230Sbostic (void)fprintf(stderr, 8547230Sbostic "ar: %s: not found in archive.\n", *argv); 8647230Sbostic } 8747230Sbostic 8846000Sbostic char * 8946000Sbostic rname(path) 9046000Sbostic char *path; 9146000Sbostic { 9246000Sbostic register char *ind; 9346000Sbostic 9446000Sbostic return((ind = rindex(path, '/')) ? ind + 1 : path); 9546000Sbostic } 9646000Sbostic 9746000Sbostic compare(dest) 9846000Sbostic char *dest; 9946000Sbostic { 10047602Sbostic if (options & AR_TR) 10147213Sbostic return(!strncmp(chdr.name, rname(dest), OLDARMAXNAME)); 10246000Sbostic return(!strcmp(chdr.name, rname(dest))); 10346000Sbostic } 10446000Sbostic 10547230Sbostic void 10646000Sbostic badfmt() 10746000Sbostic { 10846000Sbostic errno = EFTYPE; 10946000Sbostic error(archive); 11046000Sbostic } 11146000Sbostic 11247230Sbostic void 11346000Sbostic error(name) 11446000Sbostic char *name; 11546000Sbostic { 11646000Sbostic (void)fprintf(stderr, "ar: %s: %s\n", name, strerror(errno)); 11746000Sbostic exit(1); 11846000Sbostic } 119