Annotation of researchv10no/cmd/odist/opkg/header.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *     various subroutines to deal with archive headers
                      3:  */
                      4: 
                      5: #include "asd.h"
                      6: #include <ctype.h>
                      7: #include <stdio.h>
                      8: #include <string.h>
                      9: 
                     10: struct hdr hdr;
                     11: 
                     12: /*
                     13:  *     convert p to a long value.  maximum input length is len,
                     14:  *     input is to be interpreted in base b.  No negative values.
                     15:  */
                     16: long
                     17: cvlong (char *p, size_t len, int base)
                     18: {
                     19:        register int i;
                     20:        register long r;
                     21: 
                     22:        r = 0;
                     23:        i = len;
                     24: 
                     25:        do {
                     26:                register int c = *p++;
                     27:                if (isdigit (c))
                     28:                        r = r * base + c - '0';
                     29:        } while (--i > 0);
                     30: 
                     31:        return r;
                     32: }
                     33: 
                     34: long
                     35: read_header (char *name, FILE *file)
                     36: {
                     37:        register int n;
                     38:        register int i;
                     39:        register char *p, *q;
                     40: 
                     41:        n = fread ((char *) &ar_hdr, sizeof (ar_hdr), 1, file);
                     42:        if (n != 1) {
                     43:                fprintf (stderr, "can't read %s\n", name);
                     44:                exit (1);
                     45:        }
                     46: 
                     47:        if (strncmp (ar_hdr.ar_fmag, ARFMAG, sizeof (ar_hdr.ar_fmag)) != 0) {
                     48:                fprintf (stderr, "input phase error on %s\n", name);
                     49:                exit (1);
                     50:        }
                     51: 
                     52:        /* check the component name, allowing for trailing blanks */
                     53:        p = name;
                     54:        q = ar_hdr.ar_name;
                     55:        for (i = 0; i < sizeof (ar_hdr.ar_name); i++) {
                     56:                if (*q++ != (*p? *p++: ' ')) {
                     57:                        fprintf (stderr, "expected %s, got %.*s\n",
                     58:                            name, sizeof (ar_hdr.ar_name), ar_hdr.ar_name);
                     59:                }
                     60:        }
                     61: 
                     62:        /* crack the archive header and put the information in "hdr" */
                     63:        hdr.size = cvlong (ar_hdr.ar_size, sizeof (ar_hdr.ar_size), 10);
                     64:        hdr.mode = cvlong (ar_hdr.ar_mode, sizeof (ar_hdr.ar_mode), 8);
                     65:        hdr.date = cvlong (ar_hdr.ar_date, sizeof (ar_hdr.ar_date), 10);
                     66: 
                     67:        return hdr.size;
                     68: }
                     69: 
                     70: /* advance to the start of the next archive header */
                     71: void
                     72: next_header(FILE *f)
                     73: {
                     74:        if (hdr.size & 1)
                     75:                getc(f);
                     76: }
                     77: 
                     78: /* skip leading white space, return a field */
                     79: char *
                     80: getfield (FILE *f)
                     81: {
                     82:        register char c;
                     83: 
                     84:        /* skip leading white space */
                     85:        do c = getc (f);
                     86:        while (isspace (c) && c != '\n');
                     87: 
                     88:        /* if we hit a newline, something's wrong */
                     89:        if (c == '\n') {
                     90:                fprintf (stderr, "unexpected newline\n");
                     91:                exit (1);
                     92:        }
                     93: 
                     94:        /* return the nonblank, read a "pathname" and return it */
                     95:        ungetc (c, f);
                     96:        return getpath (f);
                     97: }
                     98: 
                     99: /* insist on an end of line right here */
                    100: void
                    101: geteol (FILE *f)
                    102: {
                    103:        register int c;
                    104: 
                    105:        c = getc (f);
                    106:        if (c != '\n') {
                    107:                fprintf (stderr, "expected newline, got %c\n", c);
                    108:                exit (1);
                    109:        }
                    110: }

unix.superglobalmegacorp.com

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