Annotation of researchv9/jerq/sgs/strip/process.c, revision 1.1

1.1     ! root        1: /* UNIX HEADER */
        !             2: #include       <stdio.h>
        !             3: #include       <ar.h>
        !             4: 
        !             5: /* COMMON SGS HEADERS */
        !             6: #include       "filehdr.h"
        !             7: #include       "ldfcn.h"
        !             8: 
        !             9: /* SGS SPECIFIC HEADER */
        !            10: 
        !            11: #include       "paths.h"
        !            12: #include       "sgs.h"
        !            13: /* STRIP HEADER */
        !            14: #include       "defs.h"
        !            15: 
        !            16: /* EXTERNAL VARIABLES DEFINED */
        !            17: FILE   *strp1;
        !            18: FILE   *strp2;
        !            19: FILE   *stripout;
        !            20: FILHDR filehead;
        !            21: #if AR16WR
        !            22: FILE   *tempfil, *readtmp;
        !            23: #endif
        !            24: 
        !            25: 
        !            26:        /*  process(filename)
        !            27:         *
        !            28:         *  directs the stripping of the named object file
        !            29:         *  checks the object file header to determine that it can be stripped
        !            30:         *  opens a temporary file (tmpnam1) and then builds the stripped file in it
        !            31:         *  copies the temporary stripped file back to its original place (filename)
        !            32:         *
        !            33:         *      the flags in the file header are set to reflect the new state
        !            34:         *      of the file:
        !            35:         *      if all flags are OFF there will be no symbols or line numbers
        !            36:         *      if lflag is ON then there will be no line numbers
        !            37:         *      if sflag is ON then there will be no local symbols
        !            38:         *      if rflag or xflag is ON then there will be no local symbols 
        !            39:         *                      or line numbers
        !            40:         *      if bflag is ON then there will be no local symbols except
        !            41:         *                      .bb, .eb, .bf, .ef
        !            42:         *      if fflag if ON then there will be no local symbols or line numbers
        !            43:         *                      and no relocation except from a section of type COPY
        !            44:         *
        !            45:         *  defines:
        !            46:         *        - strp1 = fopen(tmpnam1, "w")  for building temporary
        !            47:         *                 = fopen(tmpnam1, "r") for copying temporary to original
        !            48:         *        - strp2 = fopen(tmpnam2, "w") for building temporary
        !            49:         *        - stripout = fopen(filename "w") for copying temporary to original
        !            50:         *
        !            51:         *  calls:
        !            52:         *        - checkflags(filename, &filehead) to check object file flags
        !            53:         *        - buildtmp(filename, &filehead) to build the temporary file
        !            54:         *        - copytmp(filename, &filehead) to copy the temporary to the original
        !            55:         *        - error(filename, message, level) when an error occurs; level
        !            56:         *                indicates the severity of the error and the current strip state
        !            57:         *
        !            58:         *  returns SUCCESS or FAILURE
        !            59:         */
        !            60: 
        !            61: 
        !            62: int
        !            63: process(filename)
        !            64: 
        !            65: char   *filename;
        !            66: 
        !            67: {
        !            68:        /* UNIX FUNCTIONS CALLED */
        !            69:        extern  FILE    *fopen( );
        !            70:        extern          fclose( ),
        !            71:                        exit( );
        !            72:        extern  int     fseek( );
        !            73:        extern  long    ftell( );
        !            74: 
        !            75:        /* COMMON OBJECT FILE ACCESS ROUTINES CALLED */
        !            76:        extern  int     ldaclose( );
        !            77: 
        !            78:        /* STRIP FUNCTIONS CALLED */
        !            79:        extern  int     checkflags( ),
        !            80:                        buildtmp( ),
        !            81:                        copyarh( ),
        !            82:                        copytmp( );
        !            83:        extern          error( );
        !            84: 
        !            85:        /* EXTERNAL VARIABLES USED */
        !            86:        extern  LDFILE  *ldptr;
        !            87:        extern  char    tmpnam1[ ],
        !            88:                        tmpnam2[ ],
        !            89:                        tmpnam3[ ],
        !            90:                        tmpnam4[ ];
        !            91:        extern  FILE    *strp1,
        !            92:                        *strp2,
        !            93:                        *stripout;
        !            94: #if AR16WR
        !            95:        extern  FILE    *tempfil,
        !            96:                        *readtmp,
        !            97: #endif
        !            98:        extern  FILHDR  filehead;
        !            99:        extern  int     rflag,
        !           100:                        sflag;
        !           101:        extern  int     fflag;
        !           102:        extern  int     lflag;
        !           103:        extern  ARCHDR  arhead;
        !           104:        extern  int     aflag;
        !           105:        extern  long    xmore;
        !           106:        extern  int     mag;
        !           107: #if FLEXNAMES
        !           108:        extern  long    string_size;
        !           109: #endif
        !           110: 
        !           111: 
        !           112:        if (ldfhread(ldptr, &filehead) != SUCCESS)
        !           113:        {
        !           114:                error(filename, "cannot read file header", 1);
        !           115:                return(FAILURE);
        !           116:        }
        !           117:        else
        !           118:        {
        !           119:                if ( ! ISMAGIC(filehead.f_magic) )
        !           120:                {
        !           121:                        error(filename, "not the correct magic number", 1);
        !           122:                        return(FAILURE);
        !           123:                }
        !           124:        }
        !           125: 
        !           126: 
        !           127:        if (checkflags(filename, &filehead) != SUCCESS)
        !           128:                return(FAILURE);
        !           129: 
        !           130:        if ((strp1 = fopen(tmpnam1, "w")) == NULL)
        !           131:        {
        !           132:                error(filename, "cannot open temporary file", 1);
        !           133:                exit(FATAL);
        !           134:        }
        !           135:        if ((strp2 = fopen(tmpnam2, "w")) == NULL)
        !           136:        {
        !           137:                error(filename, "cannot open temporary file", 1);
        !           138:                exit(FATAL);
        !           139:        }
        !           140: 
        !           141: #if AR16WR
        !           142:        if ( rflag || sflag )
        !           143:        {
        !           144:                if ((tempfil = fopen(tmpnam3, "w")) == NULL)
        !           145:                {
        !           146:                        error(filename, "cannot open temporary file", 1);
        !           147:                        exit(FATAL);
        !           148:                }
        !           149:                if ((readtmp = fopen(tmpnam3, "r")) == NULL)
        !           150:                {
        !           151:                        error(filename, "cannot open temporary file", 1);
        !           152:                        exit(FATAL);
        !           153:                }
        !           154:        }
        !           155: #endif
        !           156: 
        !           157:        if (buildtmp(filename, &filehead) == SUCCESS)
        !           158:        {
        !           159:                xmore = ldclose(ldptr);
        !           160:                fclose(strp1);
        !           161:                fclose(strp2);
        !           162: 
        !           163: #if AR16WR
        !           164:                if ( rflag || sflag )
        !           165:                {
        !           166:                        fclose(tempfil);
        !           167:                        fclose(readtmp);
        !           168:                }
        !           169: #else
        !           170:                freetempent( );
        !           171: #endif
        !           172: 
        !           173:                if (aflag)
        !           174:                {
        !           175:                        aflag = 0;
        !           176:                        if ((stripout = fopen(tmpnam4, "w")) == NULL)
        !           177:                        {
        !           178:                                error(filename, "cannot write cannot strip", 0);
        !           179:                                return(FAILURE);
        !           180:                        }
        !           181:                }
        !           182:                else if (TYPE(ldptr) != ARTYPE)
        !           183:                        if ((stripout = fopen( filename, "w" )) == NULL)
        !           184:                        {
        !           185:                                error(filename, "cannot write, cannot strip",5);
        !           186:                                return( FAILURE );
        !           187:                        }
        !           188: 
        !           189: 
        !           190:                if ((strp1 = fopen(tmpnam1, "r")) == NULL)
        !           191:                {
        !           192:                        error(filename, "cannot open temporary file", 5);
        !           193:                        exit(FATAL);
        !           194:                }
        !           195:                if ((strp2 = fopen(tmpnam2, "r")) == NULL)
        !           196:                {
        !           197:                        error(filename, "cannot open temporary file", 5);
        !           198:                        exit(FATAL);
        !           199:                }
        !           200: 
        !           201:                if (TYPE(ldptr) == ARTYPE)
        !           202:                {
        !           203:                        fseek(strp1,0L,2);
        !           204:                        fseek(strp2,0L,2);
        !           205:                        arhead.ar_size = ftell(strp1) + ftell(strp2) + sizeof(FILHDR);
        !           206: #if FLEXNAMES
        !           207:                        if (string_size > 0L)
        !           208:                                arhead.ar_size += string_size;
        !           209: #endif
        !           210:                        arhead.ar_size += (arhead.ar_size & 1);
        !           211:                        fseek(strp1,0L,0);
        !           212:                        fseek(strp2,0L,0);
        !           213:                        if (copyarh(filename, &arhead) != SUCCESS)
        !           214:                        {
        !           215:                                fprintf(stderr, "can't copy archive header back");
        !           216:                        }
        !           217:                }
        !           218: 
        !           219:                /* set the new file header flags appropriately */
        !           220:                if (!lflag)
        !           221:                        filehead.f_flags |= F_LSYMS;
        !           222:                if (!sflag)
        !           223:                        filehead.f_flags |= F_LNNO;
        !           224: #if !UNIX
        !           225:                if (fflag)
        !           226:                        filehead.f_flags |= F_RELFLG;
        !           227: #endif
        !           228: 
        !           229:                if (copytmp(filename, &filehead) == SUCCESS)
        !           230:                {
        !           231:                        if (xmore == SUCCESS )
        !           232:                                fclose(stripout);
        !           233:                        fclose(strp1);
        !           234:                        fclose(strp2);
        !           235:                }
        !           236:        }
        !           237: 
        !           238:        return(SUCCESS);
        !           239: }
        !           240: 
        !           241: 
        !           242: int
        !           243: copyarh(filename, arhead)
        !           244: 
        !           245:  char          *filename;
        !           246:  ARCHDR                *arhead;
        !           247: 
        !           248: 
        !           249: {
        !           250: 
        !           251: /*     UNIX FUNCTIONS CALLED */
        !           252: 
        !           253:        extern  int     fwrite( );
        !           254:        extern          sputl( );
        !           255: 
        !           256: /*     STRIP FUNCTIONS CALLED */
        !           257: 
        !           258:        extern  resetsig( ),
        !           259:                error( );
        !           260: 
        !           261: /*     EXTERNAL VARIABLES USED */
        !           262: 
        !           263:        extern  LDFILE *ldptr;
        !           264: 
        !           265:        extern  FILE   *stripout;
        !           266: 
        !           267: #ifdef PORT5AR
        !           268: /*     LOCAL VARIABLES USED */
        !           269: 
        !           270:        struct arf_hdr          arfbuf;
        !           271: 
        !           272:        strncpy(arfbuf.arf_name,arhead->ar_name,sizeof(arfbuf.arf_name));
        !           273:        sputl(arhead->ar_date,arfbuf.arf_date);
        !           274:        sputl((long)arhead->ar_uid,arfbuf.arf_uid);
        !           275:        sputl((long)arhead->ar_gid,arfbuf.arf_gid);
        !           276:        sputl(arhead->ar_mode,arfbuf.arf_mode);
        !           277:        sputl(arhead->ar_size,arfbuf.arf_size);
        !           278:        if (fwrite( &arfbuf, sizeof( struct arf_hdr ), 1, stripout ) != 1 )
        !           279: #else
        !           280: #ifdef PORTAR
        !           281:        struct  ar_hdr  arbuf;
        !           282:        char            *p;
        !           283: 
        !           284:        sprintf( arbuf.ar_name, "%-16s", arhead->ar_name );
        !           285:        p = arbuf.ar_name + sizeof( arbuf.ar_name ) - 1;
        !           286:        while ( *--p == ' ' );
        !           287:        *++p = '/';
        !           288: 
        !           289:        sprintf( arbuf.ar_date, "%-12ld", arhead->ar_date );
        !           290:        sprintf( arbuf.ar_uid, "%-6u", arhead->ar_uid );
        !           291:        sprintf( arbuf.ar_gid, "%-6u", arhead->ar_gid );
        !           292:        sprintf( arbuf.ar_mode, "%-8o", arhead->ar_mode );
        !           293:        sprintf( arbuf.ar_size, "%-10ld", arhead->ar_size );
        !           294:        strncpy( arbuf.ar_fmag, ARFMAG, sizeof( arbuf.ar_fmag ) );
        !           295:        if (fwrite( &arbuf, sizeof( struct ar_hdr ), 1, stripout ) != 1)
        !           296: #else
        !           297:        if (fwrite(&arhead, sizeof(ARCHDR), 1, stripout) != 1)
        !           298: #endif
        !           299: #endif
        !           300:        {
        !           301:                error(filename, "cannot recreate archive header", 5);
        !           302:                resetsig( );
        !           303:                return(FAILURE);
        !           304:        }
        !           305:        else
        !           306:        {
        !           307:                return(SUCCESS);
        !           308:        }
        !           309: }
        !           310: /*
        !           311:  *     @(#)process.c   1.9 11/17/83;
        !           312:  */

unix.superglobalmegacorp.com

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