[BACK]Return to misc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ar

Annotation of src/usr.bin/ar/misc.c, Revision 1.1

1.1     ! deraadt     1: /*     $NetBSD: misc.c,v 1.6 1995/03/26 03:27:55 glass Exp $   */
        !             2:
        !             3: /*-
        !             4:  * Copyright (c) 1990, 1993, 1994
        !             5:  *     The Regents of the University of California.  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: #if 0
        !            41: static char sccsid[] = "@(#)misc.c     8.3 (Berkeley) 4/2/94";
        !            42: #else
        !            43: static char rcsid[] = "$NetBSD: misc.c,v 1.6 1995/03/26 03:27:55 glass Exp $";
        !            44: #endif
        !            45: #endif /* not lint */
        !            46:
        !            47: #include <sys/param.h>
        !            48:
        !            49: #include <dirent.h>
        !            50: #include <err.h>
        !            51: #include <errno.h>
        !            52: #include <signal.h>
        !            53: #include <stdio.h>
        !            54: #include <stdlib.h>
        !            55: #include <string.h>
        !            56: #include <unistd.h>
        !            57:
        !            58: #include "archive.h"
        !            59: #include "extern.h"
        !            60: #include "pathnames.h"
        !            61:
        !            62: char *tname = "temporary file";                /* temporary file "name" */
        !            63:
        !            64: int
        !            65: tmp()
        !            66: {
        !            67:        extern char *envtmp;
        !            68:        sigset_t set, oset;
        !            69:        static int first;
        !            70:        int fd;
        !            71:        char path[MAXPATHLEN];
        !            72:
        !            73:        if (!first && !envtmp) {
        !            74:                envtmp = getenv("TMPDIR");
        !            75:                first = 1;
        !            76:        }
        !            77:
        !            78:        if (envtmp)
        !            79:                (void)sprintf(path, "%s/%s", envtmp, _NAME_ARTMP);
        !            80:        else
        !            81:                strcpy(path, _PATH_ARTMP);
        !            82:
        !            83:        sigfillset(&set);
        !            84:        (void)sigprocmask(SIG_BLOCK, &set, &oset);
        !            85:        if ((fd = mkstemp(path)) == -1)
        !            86:                error(tname);
        !            87:         (void)unlink(path);
        !            88:        (void)sigprocmask(SIG_SETMASK, &oset, NULL);
        !            89:        return (fd);
        !            90: }
        !            91:
        !            92: /*
        !            93:  * files --
        !            94:  *     See if the current file matches any file in the argument list; if it
        !            95:  *     does, remove it from the argument list.
        !            96:  */
        !            97: char *
        !            98: files(argv)
        !            99:        char **argv;
        !           100: {
        !           101:        char **list, *p;
        !           102:
        !           103:        for (list = argv; *list; ++list)
        !           104:                if (compare(*list)) {
        !           105:                        p = *list;
        !           106:                        for (; list[0] = list[1]; ++list)
        !           107:                                continue;
        !           108:                        return (p);
        !           109:                }
        !           110:        return (NULL);
        !           111: }
        !           112:
        !           113: void
        !           114: orphans(argv)
        !           115:        char **argv;
        !           116: {
        !           117:
        !           118:        for (; *argv; ++argv)
        !           119:                warnx("%s: not found in archive", *argv);
        !           120: }
        !           121:
        !           122: char *
        !           123: rname(path)
        !           124:        char *path;
        !           125: {
        !           126:        char *ind;
        !           127:
        !           128:        return ((ind = strrchr(path, '/')) ? ind + 1 : path);
        !           129: }
        !           130:
        !           131: int
        !           132: compare(dest)
        !           133:        char *dest;
        !           134: {
        !           135:
        !           136:        if (options & AR_TR)
        !           137:                return (!strncmp(chdr.name, rname(dest), OLDARMAXNAME));
        !           138:        return (!strcmp(chdr.name, rname(dest)));
        !           139: }
        !           140:
        !           141: void
        !           142: badfmt()
        !           143: {
        !           144:
        !           145:        errno = EFTYPE;
        !           146:        err(1, "%s", archive);
        !           147: }
        !           148:
        !           149: void
        !           150: error(name)
        !           151:        char *name;
        !           152: {
        !           153:
        !           154:        err(1, "%s", name);
        !           155: }