1 /*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. 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 8.1 (Berkeley) 06/06/93";
13 #endif /* not lint */
14
15 #include <sys/param.h>
16 #include <sys/signal.h>
17 #include <errno.h>
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include "pathnames.h"
23
24 extern char *archive; /* archive name */
25 char *tname = "temporary file"; /* temporary file "name" */
26
tmp()27 tmp()
28 {
29 sigset_t set, oset;
30 int fd;
31 char *envtmp, path[MAXPATHLEN];
32
33 if ((envtmp = getenv("TMPDIR")) != NULL)
34 (void)sprintf(path, "%s%s", envtmp, strrchr(_PATH_RANTMP, '/'));
35 else
36 bcopy(_PATH_RANTMP, path, sizeof(_PATH_RANTMP));
37
38 sigfillset(&set);
39 (void)sigprocmask(SIG_BLOCK, &set, &oset);
40 if ((fd = mkstemp(path)) == -1)
41 error(path);
42 (void)unlink(path);
43 (void)sigprocmask(SIG_SETMASK, &oset, NULL);
44 return(fd);
45 }
46
47 void *
emalloc(len)48 emalloc(len)
49 int len;
50 {
51 void *p;
52
53 if ((p = malloc((u_int)len)) == NULL)
54 error(archive);
55 return(p);
56 }
57
58 char *
rname(path)59 rname(path)
60 char *path;
61 {
62 register char *ind;
63
64 return((ind = rindex(path, '/')) ? ind + 1 : path);
65 }
66
badfmt()67 badfmt()
68 {
69 errno = EFTYPE;
70 error(archive);
71 }
72
error(name)73 error(name)
74 char *name;
75 {
76 (void)fprintf(stderr, "ranlib: %s: %s\n", name, strerror(errno));
77 exit(1);
78 }
79