146000Sbostic /*- 261906Sbostic * Copyright (c) 1990, 1993 361906Sbostic * 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*66567Spendry static char sccsid[] = "@(#)misc.c 8.2 (Berkeley) 04/01/94"; 1346000Sbostic #endif /* not lint */ 1446000Sbostic 1546000Sbostic #include <sys/param.h> 16*66567Spendry 17*66567Spendry #include <dirent.h> 18*66567Spendry #include <err.h> 19*66567Spendry #include <errno.h> 2047202Sbostic #include <signal.h> 2146000Sbostic #include <stdio.h> 2247230Sbostic #include <stdlib.h> 2347230Sbostic #include <string.h> 24*66567Spendry #include <unistd.h> 25*66567Spendry 2647202Sbostic #include "archive.h" 2747230Sbostic #include "extern.h" 2846000Sbostic #include "pathnames.h" 2946000Sbostic 3046000Sbostic char *tname = "temporary file"; /* temporary file "name" */ 3146000Sbostic 32*66567Spendry int 3346000Sbostic tmp() 3446000Sbostic { 3546000Sbostic extern char *envtmp; 3646000Sbostic sigset_t set, oset; 3746000Sbostic static int first; 3846000Sbostic int fd; 3946000Sbostic char path[MAXPATHLEN]; 4046000Sbostic 4146000Sbostic if (!first && !envtmp) { 4246000Sbostic envtmp = getenv("TMPDIR"); 4346000Sbostic first = 1; 4446000Sbostic } 4546000Sbostic 4646000Sbostic if (envtmp) 4746000Sbostic (void)sprintf(path, "%s/%s", envtmp, _NAME_ARTMP); 4846000Sbostic else 49*66567Spendry strcpy(path, _PATH_ARTMP); 5046000Sbostic 5149893Sbostic sigfillset(&set); 5246000Sbostic (void)sigprocmask(SIG_BLOCK, &set, &oset); 5346000Sbostic if ((fd = mkstemp(path)) == -1) 5446000Sbostic error(tname); 5546000Sbostic (void)unlink(path); 5649893Sbostic (void)sigprocmask(SIG_SETMASK, &oset, NULL); 57*66567Spendry return (fd); 5846000Sbostic } 5946000Sbostic 6046000Sbostic /* 6146000Sbostic * files -- 6246000Sbostic * See if the current file matches any file in the argument list; if it 6346000Sbostic * does, remove it from the argument list. 6446000Sbostic */ 6547230Sbostic char * 6646000Sbostic files(argv) 6746000Sbostic char **argv; 6846000Sbostic { 69*66567Spendry char **list, *p; 7046000Sbostic 7146000Sbostic for (list = argv; *list; ++list) 7246000Sbostic if (compare(*list)) { 7347230Sbostic p = *list; 74*66567Spendry for (; list[0] = list[1]; ++list) 75*66567Spendry continue; 76*66567Spendry return (p); 7746000Sbostic } 78*66567Spendry return (NULL); 7946000Sbostic } 8046000Sbostic 8147230Sbostic void 8247230Sbostic orphans(argv) 8347230Sbostic char **argv; 8447230Sbostic { 85*66567Spendry 8647230Sbostic for (; *argv; ++argv) 87*66567Spendry warnx("%s: not found in archive", *argv); 8847230Sbostic } 8947230Sbostic 9046000Sbostic char * 9146000Sbostic rname(path) 9246000Sbostic char *path; 9346000Sbostic { 94*66567Spendry char *ind; 9546000Sbostic 96*66567Spendry return ((ind = strrchr(path, '/')) ? ind + 1 : path); 9746000Sbostic } 9846000Sbostic 99*66567Spendry int 10046000Sbostic compare(dest) 10146000Sbostic char *dest; 10246000Sbostic { 103*66567Spendry 10447602Sbostic if (options & AR_TR) 105*66567Spendry return (!strncmp(chdr.name, rname(dest), OLDARMAXNAME)); 106*66567Spendry return (!strcmp(chdr.name, rname(dest))); 10746000Sbostic } 10846000Sbostic 10947230Sbostic void 11046000Sbostic badfmt() 11146000Sbostic { 112*66567Spendry 113*66567Spendry errx(1, "%s: %s", archive, strerror(EFTYPE)); 11446000Sbostic } 11546000Sbostic 11647230Sbostic void 11746000Sbostic error(name) 11846000Sbostic char *name; 11946000Sbostic { 120*66567Spendry 121*66567Spendry errx(1, "%s", name); 12246000Sbostic } 123