146013Sbostic /*- 246013Sbostic * Copyright (c) 1990 The Regents of the University of California. 346013Sbostic * All rights reserved. 446013Sbostic * 546013Sbostic * This code is derived from software contributed to Berkeley by 646013Sbostic * Hugh Smith at The University of Guelph. 746013Sbostic * 846013Sbostic * %sccs.include.redist.c% 946013Sbostic */ 1046013Sbostic 1146013Sbostic #ifndef lint 12*52348Sbostic static char sccsid[] = "@(#)misc.c 5.3 (Berkeley) 02/04/92"; 1346013Sbostic #endif /* not lint */ 1446013Sbostic 1546013Sbostic #include <sys/param.h> 1646013Sbostic #include <sys/signal.h> 1746698Sbostic #include <errno.h> 1846698Sbostic #include <unistd.h> 1946013Sbostic #include <stdio.h> 2046013Sbostic #include <stdlib.h> 2146013Sbostic #include <string.h> 2246013Sbostic #include "pathnames.h" 2346013Sbostic 2446013Sbostic extern char *archive; /* archive name */ 2546013Sbostic char *tname = "temporary file"; /* temporary file "name" */ 2646013Sbostic 2746013Sbostic tmp() 2846013Sbostic { 2946013Sbostic sigset_t set, oset; 3046013Sbostic int fd; 31*52348Sbostic char *envtmp, path[MAXPATHLEN]; 3246013Sbostic 33*52348Sbostic if (envtmp = getenv("TMPDIR")) 34*52348Sbostic (void)sprintf(path, "%s/%s", envtmp, _PATH_RANTMP); 35*52348Sbostic else 36*52348Sbostic bcopy(_PATH_RANTMP, path, sizeof(_PATH_RANTMP)); 37*52348Sbostic 38*52348Sbostic sigfillset(&set); 3946013Sbostic (void)sigprocmask(SIG_BLOCK, &set, &oset); 4046013Sbostic if ((fd = mkstemp(path)) == -1) 4146013Sbostic error(tname); 4246013Sbostic (void)unlink(path); 43*52348Sbostic (void)sigprocmask(SIG_SETMASK, &oset, NULL); 4446013Sbostic return(fd); 4546013Sbostic } 4646013Sbostic 4746013Sbostic void * 4846013Sbostic emalloc(len) 4946013Sbostic int len; 5046013Sbostic { 51*52348Sbostic void *p; 5246013Sbostic 53*52348Sbostic if ((p = malloc((u_int)len)) == NULL) 5446013Sbostic error(archive); 5546013Sbostic return(p); 5646013Sbostic } 5746013Sbostic 5846013Sbostic char * 5946013Sbostic rname(path) 6046013Sbostic char *path; 6146013Sbostic { 6246013Sbostic register char *ind; 6346013Sbostic 6446013Sbostic return((ind = rindex(path, '/')) ? ind + 1 : path); 6546013Sbostic } 6646013Sbostic 6746013Sbostic badfmt() 6846013Sbostic { 6946013Sbostic errno = EFTYPE; 7046013Sbostic error(archive); 7146013Sbostic } 7246013Sbostic 7346013Sbostic error(name) 7446013Sbostic char *name; 7546013Sbostic { 7646013Sbostic (void)fprintf(stderr, "ranlib: %s: %s\n", name, strerror(errno)); 7746013Sbostic exit(1); 7846013Sbostic } 79