Annotation of src/usr.bin/ranlib/misc.c, Revision 1.5
1.5 ! espie 1: /* $OpenBSD: misc.c,v 1.4 1999/08/27 08:43:22 fgsch Exp $ */
1.2 deraadt 2:
1.1 deraadt 3: /*-
4: * Copyright (c) 1990 The Regents of the University of California.
5: * All rights reserved.
6: *
7: * This code is derived from software contributed to Berkeley by
8: * Hugh Smith at The University of Guelph.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: */
38:
39: #ifndef lint
40: /*static char sccsid[] = "from: @(#)misc.c 5.2 (Berkeley) 2/26/91";*/
1.5 ! espie 41: static char rcsid[] = "$OpenBSD: misc.c,v 1.4 1999/08/27 08:43:22 fgsch Exp $";
1.1 deraadt 42: #endif /* not lint */
43:
44: #include <sys/param.h>
45: #include <signal.h>
46: #include <errno.h>
47: #include <unistd.h>
48: #include <stdio.h>
49: #include <stdlib.h>
50: #include <string.h>
51: #include "pathnames.h"
1.5 ! espie 52: #include "extern.h"
1.1 deraadt 53:
1.5 ! espie 54: char *tname = "temporary file";
1.1 deraadt 55:
1.5 ! espie 56: int
1.1 deraadt 57: tmp()
58: {
59: static char *envtmp;
60: sigset_t set, oset;
61: static int first;
62: int fd;
63: char path[MAXPATHLEN];
64:
65: if (!first) {
66: envtmp = getenv("TMPDIR");
67: first = 1;
68: }
69:
70: if (envtmp)
1.4 fgsch 71: (void)snprintf(path, sizeof(path), "%s/%s", envtmp,
72: _NAME_RANTMP);
1.1 deraadt 73: else
1.4 fgsch 74: strlcpy(path, _PATH_RANTMP, sizeof(path));
1.1 deraadt 75:
76: sigemptyset(&set);
77: sigaddset(&set, SIGHUP);
78: sigaddset(&set, SIGINT);
79: sigaddset(&set, SIGQUIT);
80: sigaddset(&set, SIGTERM);
81: (void)sigprocmask(SIG_BLOCK, &set, &oset);
82: if ((fd = mkstemp(path)) == -1)
83: error(tname);
1.5 ! espie 84: (void)unlink(path);
1.1 deraadt 85: (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL);
86: return(fd);
87: }
88:
89: void *
90: emalloc(len)
1.5 ! espie 91: size_t len;
1.1 deraadt 92: {
1.5 ! espie 93: void *p;
1.1 deraadt 94:
1.5 ! espie 95: if (!(p = malloc(len)))
1.1 deraadt 96: error(archive);
97: return(p);
98: }
99:
1.5 ! espie 100: const char *
1.1 deraadt 101: rname(path)
1.5 ! espie 102: const char *path;
1.1 deraadt 103: {
1.5 ! espie 104: register const char *ind;
1.1 deraadt 105:
1.3 millert 106: return((ind = strrchr(path, '/')) ? ind + 1 : path);
1.1 deraadt 107: }
108:
1.5 ! espie 109: void
1.1 deraadt 110: badfmt()
111: {
112: errno = EFTYPE;
113: error(archive);
114: }
115:
1.5 ! espie 116: void
1.1 deraadt 117: error(name)
1.5 ! espie 118: const char *name;
1.1 deraadt 119: {
1.5 ! espie 120:
! 121: err(1, "%s", name);
1.1 deraadt 122: }