Annotation of researchv10no/sys/boot/bb/bbs.c, revision 1.1

1.1     ! root        1: #include <a.out.h>
        !             2: 
        !             3: #define        STDIN   0
        !             4: #define        STDOUT  1
        !             5: #define        STDERR  2
        !             6: 
        !             7: #define        PGSIZE  1024
        !             8: #define        BSIZE   4096
        !             9: 
        !            10: main()
        !            11: {
        !            12:        struct exec a;
        !            13: 
        !            14:        if (read(STDIN, (char *)&a, sizeof(a)) != sizeof(a)) {
        !            15:                fprint(STDERR, "no header\n");
        !            16:                exit(1);
        !            17:        }
        !            18:        if (a.a_magic != 0407 && a.a_magic != 0410) {
        !            19:                fprint(STDERR, "bad magic number\n");
        !            20:                exit(1);
        !            21:        }
        !            22:        copy(a.a_text);
        !            23:        if (a.a_magic == 0410)
        !            24:                pad(PGSIZE - (a.a_text & (PGSIZE-1)));
        !            25:        copy(a.a_data);
        !            26:        pad(a.a_bss);
        !            27:        exit(0);
        !            28: }
        !            29: 
        !            30: copy(n)
        !            31: register int n;
        !            32: {
        !            33:        char buf[BSIZE];
        !            34:        register int rn, r;
        !            35: 
        !            36:        while (n > 0) {
        !            37:                r = (n > BSIZE) ? BSIZE : n;
        !            38:                rn = read(STDIN, buf, r);
        !            39:                if (rn <= 0) {
        !            40:                        fprint(STDERR, "short\n");
        !            41:                        exit(1);
        !            42:                }
        !            43:                if (write(STDOUT, buf, rn) != rn) {
        !            44:                        fprint(STDERR, "write error\n");
        !            45:                        exit(1);
        !            46:                }
        !            47:                n -= rn;
        !            48:        }
        !            49: }
        !            50: 
        !            51: pad(n)
        !            52: register int n;
        !            53: {
        !            54:        char buf[BSIZE];
        !            55:        register int i;
        !            56: 
        !            57:        for (i = 0; i < BSIZE; i++)
        !            58:                buf[i] = 0;
        !            59:        while (n > 0) {
        !            60:                i = (n > BSIZE) ? BSIZE : n;
        !            61:                if (write(STDOUT, buf, i) != i) {
        !            62:                        fprint(STDERR, "write error\n");
        !            63:                        exit(1);
        !            64:                }
        !            65:                n -= i;
        !            66:        }
        !            67: }

unix.superglobalmegacorp.com

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