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:  * Redistribution and use in source and binary forms, with or without
   9:  * modification, are permitted provided that the following conditions
  10:  * are met:
  11:  * 1. Redistributions of source code must retain the above copyright
  12:  *    notice, this list of conditions and the following disclaimer.
  13:  * 2. Redistributions in binary form must reproduce the above copyright
  14:  *    notice, this list of conditions and the following disclaimer in the
  15:  *    documentation and/or other materials provided with the distribution.
  16:  * 3. All advertising materials mentioning features or use of this software
  17:  *    must display the following acknowledgement:
  18:  *	This product includes software developed by the University of
  19:  *	California, Berkeley and its contributors.
  20:  * 4. Neither the name of the University nor the names of its contributors
  21:  *    may be used to endorse or promote products derived from this software
  22:  *    without specific prior written permission.
  23:  *
  24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34:  * SUCH DAMAGE.
  35:  */
  36: 
  37: #if defined(DOSCCS) && !defined(lint)
  38: static char sccsid[] = "@(#)misc.c	5.7.1 (2.11BSD) 1999/10/25";
  39: #endif
  40: 
  41: #include <sys/param.h>
  42: #include <sys/errno.h>
  43: #include <signal.h>
  44: #include <sys/dir.h>
  45: #include <stdio.h>
  46: #include <string.h>
  47: #include "archive.h"
  48: #include "extern.h"
  49: #include "pathnames.h"
  50: 
  51: extern CHDR chdr;           /* converted header */
  52: extern char *archive;           /* archive name */
  53: char *tname = "temporary file";     /* temporary file "name" */
  54: 
  55: tmp()
  56: {
  57:     extern char *envtmp;
  58:     sigset_t set, oset;
  59:     static int first;
  60:     int fd;
  61:     char path[MAXPATHLEN];
  62: 
  63:     if (!first && !envtmp) {
  64:         envtmp = (char *)getenv("TMPDIR");
  65:         first = 1;
  66:     }
  67: 
  68:     if (envtmp)
  69:         (void)sprintf(path, "%s/%s", envtmp, _NAME_ARTMP);
  70:     else
  71:         bcopy(_PATH_ARTMP, path, sizeof(_PATH_ARTMP));
  72: 
  73:     sigfillset(&set);
  74:     (void)sigprocmask(SIG_BLOCK, &set,  &oset);
  75:     if ((fd = mkstemp(path)) == -1)
  76:         error(tname);
  77:         (void)unlink(path);
  78:     (void)sigprocmask(SIG_SETMASK, &oset, NULL);
  79:     return(fd);
  80: }
  81: 
  82: /*
  83:  * files --
  84:  *	See if the current file matches any file in the argument list; if it
  85:  * 	does, remove it from the argument list.
  86:  */
  87: char *
  88: files(argv)
  89:     char **argv;
  90: {
  91:     register char **list;
  92:     char *p;
  93: 
  94:     for (list = argv; *list; ++list)
  95:         if (compare(*list)) {
  96:             p = *list;
  97:             for (; list[0] = list[1]; ++list);
  98:             return(p);
  99:         }
 100:     return(NULL);
 101: }
 102: 
 103: void
 104: orphans(argv)
 105:     char **argv;
 106: {
 107:     for (; *argv; ++argv)
 108:         (void)fprintf(stderr,
 109:             "ar: %s: not found in archive.\n", *argv);
 110: }
 111: 
 112: char *
 113: rname(path)
 114:     char *path;
 115: {
 116:     register char *ind;
 117: 
 118:     return((ind = rindex(path, '/')) ? ind + 1 : path);
 119: }
 120: 
 121: compare(dest)
 122:     char *dest;
 123: {
 124:     if (options & AR_TR)
 125:         return(!strncmp(chdr.name, rname(dest), OLDARMAXNAME));
 126:     return(!strcmp(chdr.name, rname(dest)));
 127: }
 128: 
 129: void
 130: badfmt()
 131: {
 132:     errno = EINVAL;
 133:     error(archive);
 134: }
 135: 
 136: void
 137: error(name)
 138:     char *name;
 139: {
 140:     (void)fprintf(stderr, "ar: %s: %s\n", name, strerror(errno));
 141:     exit(1);
 142: }

Defined functions

badfmt defined in line 129; used 10 times
compare defined in line 121; used 4 times
error defined in line 136; used 18 times
rname defined in line 112; used 9 times
tmp defined in line 55; used 8 times

Defined variables

sccsid defined in line 38; never used
tname defined in line 53; used 10 times
Last modified: 1999-10-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3366
Valid CSS Valid XHTML 1.0 Strict