Commit | Line | Data |
---|---|---|
3c7e1c10 | 1 | /*- |
80baa34f KB |
2 | * Copyright (c) 1990, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
3c7e1c10 KB |
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 | |
80baa34f | 12 | static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) %G%"; |
3c7e1c10 KB |
13 | #endif /* not lint */ |
14 | ||
15 | #include <sys/param.h> | |
16 | #include <sys/signal.h> | |
d6db39e0 KB |
17 | #include <errno.h> |
18 | #include <unistd.h> | |
3c7e1c10 KB |
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 | ||
27 | tmp() | |
28 | { | |
29 | sigset_t set, oset; | |
30 | int fd; | |
ebcea7ca | 31 | char *envtmp, path[MAXPATHLEN]; |
3c7e1c10 | 32 | |
6e597a60 CT |
33 | if ((envtmp = getenv("TMPDIR")) != NULL) |
34 | (void)sprintf(path, "%s%s", envtmp, strrchr(_PATH_RANTMP, '/')); | |
ebcea7ca KB |
35 | else |
36 | bcopy(_PATH_RANTMP, path, sizeof(_PATH_RANTMP)); | |
37 | ||
38 | sigfillset(&set); | |
3c7e1c10 KB |
39 | (void)sigprocmask(SIG_BLOCK, &set, &oset); |
40 | if ((fd = mkstemp(path)) == -1) | |
6e597a60 | 41 | error(path); |
3c7e1c10 | 42 | (void)unlink(path); |
ebcea7ca | 43 | (void)sigprocmask(SIG_SETMASK, &oset, NULL); |
3c7e1c10 KB |
44 | return(fd); |
45 | } | |
46 | ||
47 | void * | |
48 | emalloc(len) | |
49 | int len; | |
50 | { | |
ebcea7ca | 51 | void *p; |
3c7e1c10 | 52 | |
ebcea7ca | 53 | if ((p = malloc((u_int)len)) == NULL) |
3c7e1c10 KB |
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 | } |