1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Hugh Smith at The University of Guelph. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)misc.c 5.1 (Berkeley) 01/18/91"; 13 #endif /* not lint */ 14 15 #include <sys/param.h> 16 #include <sys/signal.h> 17 #include <sys/errno.h> 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <string.h> 21 #include "pathnames.h" 22 23 extern char *archive; /* archive name */ 24 char *tname = "temporary file"; /* temporary file "name" */ 25 26 tmp() 27 { 28 sigset_t set, oset; 29 int fd; 30 char path[MAXPATHLEN]; 31 32 bcopy(_PATH_RANTMP, path, sizeof(_PATH_RANTMP)); 33 34 sigemptyset(&set); 35 sigaddset(&set, SIGHUP); 36 sigaddset(&set, SIGINT); 37 sigaddset(&set, SIGQUIT); 38 sigaddset(&set, SIGTERM); 39 (void)sigprocmask(SIG_BLOCK, &set, &oset); 40 if ((fd = mkstemp(path)) == -1) 41 error(tname); 42 (void)unlink(path); 43 (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); 44 return(fd); 45 } 46 47 void * 48 emalloc(len) 49 int len; 50 { 51 char *p; 52 53 if (!(p = malloc((u_int)len))) 54 error(archive); 55 return(p); 56 } 57 58 char * 59 rname(path) 60 char *path; 61 { 62 register char *ind; 63 64 return((ind = rindex(path, '/')) ? ind + 1 : path); 65 } 66 67 badfmt() 68 { 69 errno = EFTYPE; 70 error(archive); 71 } 72 73 error(name) 74 char *name; 75 { 76 (void)fprintf(stderr, "ranlib: %s: %s\n", name, strerror(errno)); 77 exit(1); 78 } 79