Commit | Line | Data |
---|---|---|
834794c6 KB |
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) %G%"; | |
13 | #endif /* not lint */ | |
14 | ||
15 | #include <sys/param.h> | |
16 | #include <sys/signal.h> | |
17 | #include <sys/errno.h> | |
18 | #include <dirent.h> | |
19 | #include <stdio.h> | |
20 | #include "pathnames.h" | |
21 | #include "archive.h" | |
22 | ||
23 | extern CHDR chdr; /* converted header */ | |
24 | extern char *archive; /* archive name */ | |
25 | char *tname = "temporary file"; /* temporary file "name" */ | |
26 | ||
27 | tmp() | |
28 | { | |
29 | extern char *envtmp; | |
30 | sigset_t set, oset; | |
31 | static int first; | |
32 | int fd; | |
33 | char path[MAXPATHLEN]; | |
34 | ||
35 | if (!first && !envtmp) { | |
36 | envtmp = getenv("TMPDIR"); | |
37 | first = 1; | |
38 | } | |
39 | ||
40 | if (envtmp) | |
41 | (void)sprintf(path, "%s/%s", envtmp, _NAME_ARTMP); | |
42 | else | |
43 | bcopy(_PATH_ARTMP, path, sizeof(_PATH_ARTMP)); | |
44 | ||
45 | sigemptyset(&set); | |
46 | sigaddset(&set, SIGHUP); | |
47 | sigaddset(&set, SIGINT); | |
48 | sigaddset(&set, SIGQUIT); | |
49 | sigaddset(&set, SIGTERM); | |
50 | (void)sigprocmask(SIG_BLOCK, &set, &oset); | |
51 | if ((fd = mkstemp(path)) == -1) | |
52 | error(tname); | |
53 | (void)unlink(path); | |
54 | (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); | |
55 | return(fd); | |
56 | } | |
57 | ||
58 | /* | |
59 | * files -- | |
60 | * See if the current file matches any file in the argument list; if it | |
61 | * does, remove it from the argument list. | |
62 | */ | |
63 | files(argv) | |
64 | char **argv; | |
65 | { | |
66 | register char **list; | |
67 | ||
68 | for (list = argv; *list; ++list) | |
69 | if (compare(*list)) { | |
70 | for (; list[0] = list[1]; ++list); | |
71 | return(1); | |
72 | } | |
73 | return(0); | |
74 | } | |
75 | ||
76 | char * | |
77 | rname(path) | |
78 | char *path; | |
79 | { | |
80 | register char *ind; | |
81 | ||
82 | return((ind = rindex(path, '/')) ? ind + 1 : path); | |
83 | } | |
84 | ||
85 | compare(dest) | |
86 | char *dest; | |
87 | { | |
88 | char *rname(); | |
89 | ||
90 | return(!strcmp(chdr.name, rname(dest))); | |
91 | } | |
92 | ||
93 | badfmt() | |
94 | { | |
95 | errno = EFTYPE; | |
96 | error(archive); | |
97 | } | |
98 | ||
99 | error(name) | |
100 | char *name; | |
101 | { | |
102 | (void)fprintf(stderr, "ar: %s: %s\n", name, strerror(errno)); | |
103 | exit(1); | |
104 | } |