# 2.11BSD#431 - /usr/src/bin/ar/misc.c

##### Functions

    badfmt            X
    compare           X
    error             X
    files             X
    orphans           X
    rname             X
    tmp               X

##### Variables

    tname             X

       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

- in /usr/src/bin/ar/archive.c line 99-102(2), 140-145(2), 159, 168-173(2), 296, 302
- in /usr/src/bin/ar/extern.h line 36

compare defined in line 121; used 4 times

- in line 95
- in /usr/src/bin/ar/extern.h line 39
- in /usr/src/bin/ar/move.c line 97
- in /usr/src/bin/ar/replace.c line 127

error defined in line 136; used 18 times

- in line 76, 133
- in /usr/src/bin/ar/append.c line 70
- in /usr/src/bin/ar/archive.c line 77-81(2), 89, 100-104(2), 139, 172, 246-249(2), 292-297(2), 303-307(2), 322
- in /usr/src/bin/ar/extern.h line 37

files defined in line 87; used 7 times

- in /usr/src/bin/ar/contents.c line 73
- in /usr/src/bin/ar/delete.c line 74
- in /usr/src/bin/ar/extern.h line 41
- in /usr/src/bin/ar/extract.c line 82
- in /usr/src/bin/ar/move.c line 90
- in /usr/src/bin/ar/print.c line 70
- in /usr/src/bin/ar/replace.c line 103

orphans defined in line 103; used 6 times

- in /usr/src/bin/ar/contents.c line 109
- in /usr/src/bin/ar/delete.c line 93
- in /usr/src/bin/ar/extern.h line 38
- in /usr/src/bin/ar/extract.c line 123
- in /usr/src/bin/ar/move.c line 138
- in /usr/src/bin/ar/print.c line 85

rname defined in line 112; used 9 times

- in line 125-126(2)
- in /usr/src/bin/ar/ar.c line 178
- in /usr/src/bin/ar/archive.c line 210(2), 297, 303
- in /usr/src/bin/ar/extern.h line 42
- in /usr/src/bin/ar/replace.c line 75

tmp defined in line 55; used 8 times

- in /usr/src/bin/ar/delete.c line 69
- in /usr/src/bin/ar/extern.h line 40
- in /usr/src/bin/ar/move.c line 75-77(3)
- in /usr/src/bin/ar/replace.c line 87-92(3)

#### Defined variables

sccsid defined in line 38; never used
tname defined in line 53; used 10 times

- in line 76
- in /usr/src/bin/ar/delete.c line 72, 86
- in /usr/src/bin/ar/move.c line 88, 119
- in /usr/src/bin/ar/replace.c line 120, 132, 138, 163, 170

Last modified: 1999-10-26 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1359 |