146000Sbostic /*- 2*66645Spendry * Copyright (c) 1990, 1993, 1994 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*66645Spendry static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 04/02/94"; 1346000Sbostic #endif /* not lint */ 1446000Sbostic 1546000Sbostic #include <sys/param.h> 1666567Spendry 1766567Spendry #include <dirent.h> 1866567Spendry #include <err.h> 1966567Spendry #include <errno.h> 2047202Sbostic #include <signal.h> 2146000Sbostic #include <stdio.h> 2247230Sbostic #include <stdlib.h> 2347230Sbostic #include <string.h> 2466567Spendry #include <unistd.h> 2566567Spendry 2647202Sbostic #include "archive.h" 2747230Sbostic #include "extern.h" 2846000Sbostic #include "pathnames.h" 2946000Sbostic 3046000Sbostic char *tname = "temporary file"; /* temporary file "name" */ 3146000Sbostic 3266567Spendry 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 4966567Spendry 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); 5766567Spendry 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 { 6966567Spendry char **list, *p; 7046000Sbostic 7146000Sbostic for (list = argv; *list; ++list) 7246000Sbostic if (compare(*list)) { 7347230Sbostic p = *list; 7466567Spendry for (; list[0] = list[1]; ++list) 7566567Spendry continue; 7666567Spendry return (p); 7746000Sbostic } 7866567Spendry return (NULL); 7946000Sbostic } 8046000Sbostic 8147230Sbostic void 8247230Sbostic orphans(argv) 8347230Sbostic char **argv; 8447230Sbostic { 8566567Spendry 8647230Sbostic for (; *argv; ++argv) 8766567Spendry warnx("%s: not found in archive", *argv); 8847230Sbostic } 8947230Sbostic 9046000Sbostic char * 9146000Sbostic rname(path) 9246000Sbostic char *path; 9346000Sbostic { 9466567Spendry char *ind; 9546000Sbostic 9666567Spendry return ((ind = strrchr(path, '/')) ? ind + 1 : path); 9746000Sbostic } 9846000Sbostic 9966567Spendry int 10046000Sbostic compare(dest) 10146000Sbostic char *dest; 10246000Sbostic { 10366567Spendry 10447602Sbostic if (options & AR_TR) 10566567Spendry return (!strncmp(chdr.name, rname(dest), OLDARMAXNAME)); 10666567Spendry return (!strcmp(chdr.name, rname(dest))); 10746000Sbostic } 10846000Sbostic 10947230Sbostic void 11046000Sbostic badfmt() 11146000Sbostic { 11266567Spendry 11366567Spendry errx(1, "%s: %s", archive, strerror(EFTYPE)); 11446000Sbostic } 11546000Sbostic 11647230Sbostic void 11746000Sbostic error(name) 11846000Sbostic char *name; 11946000Sbostic { 12066567Spendry 12166567Spendry errx(1, "%s", name); 12246000Sbostic } 123