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*46698Sbostic static char sccsid[] = "@(#)misc.c 5.2 (Berkeley) 02/26/91"; 1346013Sbostic #endif /* not lint */ 1446013Sbostic 1546013Sbostic #include <sys/param.h> 1646013Sbostic #include <sys/signal.h> 17*46698Sbostic #include <errno.h> 18*46698Sbostic #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; 3146013Sbostic char path[MAXPATHLEN]; 3246013Sbostic 3346013Sbostic bcopy(_PATH_RANTMP, path, sizeof(_PATH_RANTMP)); 3446013Sbostic 3546013Sbostic sigemptyset(&set); 3646013Sbostic sigaddset(&set, SIGHUP); 3746013Sbostic sigaddset(&set, SIGINT); 3846013Sbostic sigaddset(&set, SIGQUIT); 3946013Sbostic sigaddset(&set, SIGTERM); 4046013Sbostic (void)sigprocmask(SIG_BLOCK, &set, &oset); 4146013Sbostic if ((fd = mkstemp(path)) == -1) 4246013Sbostic error(tname); 4346013Sbostic (void)unlink(path); 4446013Sbostic (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); 4546013Sbostic return(fd); 4646013Sbostic } 4746013Sbostic 4846013Sbostic void * 4946013Sbostic emalloc(len) 5046013Sbostic int len; 5146013Sbostic { 5246013Sbostic char *p; 5346013Sbostic 5446013Sbostic if (!(p = malloc((u_int)len))) 5546013Sbostic error(archive); 5646013Sbostic return(p); 5746013Sbostic } 5846013Sbostic 5946013Sbostic char * 6046013Sbostic rname(path) 6146013Sbostic char *path; 6246013Sbostic { 6346013Sbostic register char *ind; 6446013Sbostic 6546013Sbostic return((ind = rindex(path, '/')) ? ind + 1 : path); 6646013Sbostic } 6746013Sbostic 6846013Sbostic badfmt() 6946013Sbostic { 7046013Sbostic errno = EFTYPE; 7146013Sbostic error(archive); 7246013Sbostic } 7346013Sbostic 7446013Sbostic error(name) 7546013Sbostic char *name; 7646013Sbostic { 7746013Sbostic (void)fprintf(stderr, "ranlib: %s: %s\n", name, strerror(errno)); 7846013Sbostic exit(1); 7946013Sbostic } 80