Annotation of researchv10no/cmd/worm/io.c, revision 1.1

1.1     ! root        1: #include       <libc.h>
        !             2: #include       "worm.h"
        !             3: 
        !             4: Read(s, buf, n)
        !             5:        register Superblock *s;
        !             6:        char *buf;
        !             7:        long n;
        !             8: {
        !             9:        register k;
        !            10:        int len;
        !            11: 
        !            12:        n *= s->blocksize;
        !            13:        if(n != (int)n){
        !            14:                fprint(2, "bad arg to Read n=%ld\n", n);
        !            15:                abort();
        !            16:        }
        !            17:        len = BIGBLOCK;
        !            18:        while(n){
        !            19:                if(n < len) len = n;
        !            20:                if((k = read(s->fd, buf, len)) != len){
        !            21:                        if(k && (errno != ENXIO)){
        !            22:                                perror("Read");
        !            23:                                exit(1);
        !            24:                        }
        !            25:                        return(1);
        !            26:                }
        !            27:                n -= len;
        !            28:                buf += len;
        !            29:        }
        !            30:        return(0);
        !            31: }
        !            32: 
        !            33: Write(s, buf, n)
        !            34:        register Superblock *s;
        !            35:        char *buf;
        !            36:        long n;
        !            37: {
        !            38:        register k;
        !            39:        int len;
        !            40:        char msg[256];
        !            41: 
        !            42:        n *= s->blocksize;
        !            43:        if(n != (int)n){
        !            44:                fprint(2, "bad arg to Write n=%d\n", n);
        !            45:                abort();
        !            46:        }
        !            47:        len = BIGBLOCK;
        !            48:        while(n){
        !            49:                if(n < len) len = n;
        !            50:                if((k = write(s->fd, buf, len)) != len){
        !            51:                        sprint(msg, "Write %d blks (%dB)", n/s->blocksize, n);
        !            52:                        perror(msg);
        !            53:                        return(1);
        !            54:                }
        !            55:                n -= len;
        !            56:                buf += len;
        !            57:        }
        !            58:        return(0);
        !            59: }
        !            60: 
        !            61: Seek(s, blk)
        !            62:        register Superblock *s;
        !            63:        long blk;
        !            64: {
        !            65:        bigseek(s->fd, blk, s->blocksize, 0);
        !            66: }
        !            67: 
        !            68: bigseek(fd, a, b, ptr)
        !            69: {
        !            70: #define        SEEK64  /**/
        !            71: #ifdef SEEK64
        !            72: #include       <sys/param.h>
        !            73:        llong_t off;
        !            74:        extern llong_t Llmul(), ltoL();
        !            75: 
        !            76:        off = Llmul(ltoL(a), b);
        !            77:        llseek(fd, off, ptr);
        !            78: #else
        !            79:        lseek(fd, a*(long)b, ptr);
        !            80: #endif
        !            81: }

unix.superglobalmegacorp.com

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