Annotation of 43BSDReno/pgrm/strip/strip.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1988 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: char copyright[] =
        !            22: "@(#) Copyright (c) 1988 Regents of the University of California.\n\
        !            23:  All rights reserved.\n";
        !            24: #endif /* not lint */
        !            25: 
        !            26: #ifndef lint
        !            27: static char sccsid[] = "@(#)strip.c    5.5 (Berkeley) 6/1/90";
        !            28: #endif /* not lint */
        !            29: 
        !            30: #include <sys/types.h>
        !            31: #include <sys/file.h>
        !            32: #include <a.out.h>
        !            33: #include <stdio.h>
        !            34: 
        !            35: typedef struct exec EXEC;
        !            36: 
        !            37: /* ARGSUSED */
        !            38: main(argc, argv)
        !            39:        int argc;
        !            40:        char **argv;
        !            41: {
        !            42:        register off_t fsize;
        !            43:        register int fd, n, pagesize;
        !            44:        EXEC head;
        !            45:        off_t lseek();
        !            46: 
        !            47:        pagesize = getpagesize();
        !            48:        while (*++argv) {
        !            49:                if ((fd = open(*argv, O_RDWR)) < 0 ||
        !            50:                    (n = read(fd, (char *)&head, sizeof(EXEC))) == -1)
        !            51:                        error(*argv);
        !            52:                if (n != sizeof(EXEC) || N_BADMAG(head)) {
        !            53:                        (void)fprintf(stderr,
        !            54:                            "strip: %s not in a.out format.\n", *argv);
        !            55:                        exit(1);
        !            56:                }
        !            57:                if (!head.a_syms && !head.a_trsize && !head.a_drsize)
        !            58:                        continue;
        !            59:                fsize = head.a_text + head.a_data;
        !            60:                if (head.a_magic == ZMAGIC)
        !            61:                        fsize += pagesize - sizeof(EXEC);
        !            62:                head.a_syms = head.a_trsize = head.a_drsize = 0;
        !            63:                if (ftruncate(fd, fsize + sizeof(EXEC)) ||
        !            64:                    lseek(fd, 0L, L_SET) == -1 ||
        !            65:                    write(fd, (char *)&head, sizeof(EXEC)) != sizeof(EXEC))
        !            66:                        error(*argv);
        !            67:                (void)close(fd);
        !            68:        }
        !            69:        exit(0);
        !            70: }
        !            71: 
        !            72: error(fname)
        !            73:        char *fname;
        !            74: {
        !            75:        extern int errno;
        !            76:        char *strerror();
        !            77: 
        !            78:        (void)fprintf(stderr, "strip: %s: %s.\n", fname, strerror(errno));
        !            79:        exit(1);
        !            80: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.