12c46438cSbostic /*-
2*f365e206Sbostic * Copyright (c) 1990, 1993
3*f365e206Sbostic * The Regents of the University of California. All rights reserved.
42c46438cSbostic *
52c46438cSbostic * This code is derived from software contributed to Berkeley by
62c46438cSbostic * Hugh Smith at The University of Guelph.
72c46438cSbostic *
82c46438cSbostic * %sccs.include.redist.c%
92c46438cSbostic */
102c46438cSbostic
112c46438cSbostic #ifndef lint
12*f365e206Sbostic static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 06/06/93";
132c46438cSbostic #endif /* not lint */
142c46438cSbostic
152c46438cSbostic #include <sys/param.h>
162c46438cSbostic #include <sys/signal.h>
173cf6d427Sbostic #include <errno.h>
183cf6d427Sbostic #include <unistd.h>
192c46438cSbostic #include <stdio.h>
202c46438cSbostic #include <stdlib.h>
212c46438cSbostic #include <string.h>
222c46438cSbostic #include "pathnames.h"
232c46438cSbostic
242c46438cSbostic extern char *archive; /* archive name */
252c46438cSbostic char *tname = "temporary file"; /* temporary file "name" */
262c46438cSbostic
tmp()272c46438cSbostic tmp()
282c46438cSbostic {
292c46438cSbostic sigset_t set, oset;
302c46438cSbostic int fd;
31ce8470e4Sbostic char *envtmp, path[MAXPATHLEN];
322c46438cSbostic
33414f7814Storek if ((envtmp = getenv("TMPDIR")) != NULL)
34414f7814Storek (void)sprintf(path, "%s%s", envtmp, strrchr(_PATH_RANTMP, '/'));
35ce8470e4Sbostic else
362c46438cSbostic bcopy(_PATH_RANTMP, path, sizeof(_PATH_RANTMP));
372c46438cSbostic
38ce8470e4Sbostic sigfillset(&set);
392c46438cSbostic (void)sigprocmask(SIG_BLOCK, &set, &oset);
402c46438cSbostic if ((fd = mkstemp(path)) == -1)
41414f7814Storek error(path);
422c46438cSbostic (void)unlink(path);
43ce8470e4Sbostic (void)sigprocmask(SIG_SETMASK, &oset, NULL);
442c46438cSbostic return(fd);
452c46438cSbostic }
462c46438cSbostic
472c46438cSbostic void *
emalloc(len)482c46438cSbostic emalloc(len)
492c46438cSbostic int len;
502c46438cSbostic {
51ce8470e4Sbostic void *p;
522c46438cSbostic
53ce8470e4Sbostic if ((p = malloc((u_int)len)) == NULL)
542c46438cSbostic error(archive);
552c46438cSbostic return(p);
562c46438cSbostic }
572c46438cSbostic
582c46438cSbostic char *
rname(path)592c46438cSbostic rname(path)
602c46438cSbostic char *path;
612c46438cSbostic {
622c46438cSbostic register char *ind;
632c46438cSbostic
642c46438cSbostic return((ind = rindex(path, '/')) ? ind + 1 : path);
652c46438cSbostic }
662c46438cSbostic
badfmt()672c46438cSbostic badfmt()
682c46438cSbostic {
692c46438cSbostic errno = EFTYPE;
702c46438cSbostic error(archive);
712c46438cSbostic }
722c46438cSbostic
error(name)732c46438cSbostic error(name)
742c46438cSbostic char *name;
752c46438cSbostic {
762c46438cSbostic (void)fprintf(stderr, "ranlib: %s: %s\n", name, strerror(errno));
772c46438cSbostic exit(1);
782c46438cSbostic }
79